August 2006


Aug 9, 2006

Flash components are like bratty children


Ever try to initialize a Loader component via actionscript with 2 or more dynamically created movieclips as parents? Yeah. Didn’t work for you either, huh?

Try the following code as a solution and I’ll try to explain why I think it’s happening below.


private function makeContainer( mc:MovieClip ):Void {

	__myContainer_mc = mc.createEmptyMovieClip( "myContainer" );

	createLoader( mc, 0 );

}

private function createLoader( mc:MovieClip, depth:Number ):Void {

		__myLoader = mc[ 'myContainer' ].createClassObject( Loader, “myLoader”, depth );

}

See what’s happening? Instead of using variables as references to movieclips, to create the Loader we must identify the movieclip by the name is was assigned when it was created. In this case __myContainer_mc.createClassObject() will not give us a functioning Loader. But mc[ 'myContainer' ].createClassObject() will. This strikes me as odd because I always understood that __myContainer_mc = mc[ 'myContainer' ].

Obviously, that is not the case. My guess? The Loader is addicted to negative attention and enjoys watching me anthropomorphize the computer by repeatedly and angrily yelling at it to “Tell me why it has to be such an ass?”

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.