Journal Entries
Aug 4, 2006
Fun with Flash: ‘asfunction’ calls within a Class instance.
I was having this problem. I need links within a TextArea component to call a Class method. Are you having this problem too?
You are? Cool. Here’s a solution:
private function createBodyText( mc:MovieClip, depth:Number ):Void {
var __myBodyText = mc.createClassObject( TextArea, "myTextArea", depth );
var myRef:ContentTemplate = this;
mc[ 'myTextArea'].handlerFunction = function( s:String ) {
myRef.executeFunction();
};
__myBodyText.text += ‘<a href=”asfunction:callFunction,wee”>My kingdom for a method.</a>’;
}
public function executeFunction():Void {
trace( “Called!” );
}
When called within a class, ‘asfunction’ scopes to the movieclip parent of the textfield. And since the TextArea component is a textfield with a movieclip as a parent, ‘asfunction’ is calling ‘__myBodyText’ and not my class instance. The actionscript complier will toss an error if we assign the function ‘callFunction’ to ‘__myBodyText’ so we cheat and tell Flash to look for the instance called ‘myTextArea’ within ‘mc’s array of children. Same thing. Different phrasing.
Here are two other ways to handle it: Luis of Lessrain and Nathan Derksen of nathanderksen.com whom I found through random googling. [so dirty] Again, basically the same thing with different phrasing.
Comments are closed.

