MINI SUPPORTERS:

 

 

Animating Dynamic MovieClips - Page 6
       by kirupa  |  30 August 2006

We are almost done with the code explanations. Let's pick up from where we left off from the previous page.


var newMC:MovieClip = this["blue"+count];

I am declaring a new variable called newMC of type MovieClip. Notice that the name of the movie clip is the same as the value passed into the attachMovie function's new name argument. Notice that I am referring to the newly attached movie clip by using the this[...] function which informs Flash that the expression within this's brackets are referring to an actual object.

Note - eval()

Instead of using this[...] to have expressions refer to actual objects, you can also use the older eval function as in eval("blue"+count).

In our code, it seems like the return value for attachMovie is void - or nothing. In reality, the return value is the newly attached movie clip itself. So, you can get away with something like the following:

var newMC:MovieClip = this.attachMovie("blueCircle",....)

For simplicity reasons, I broke the one statement over two lines. In this approach, notice that you don't need to worry about using this[...] either.


newMC.onEnterFrame = function() {
fadeOut(this);
};

In the above lines, I am attaching an onEnterFrame event handler to the newly defined and initialized newMC movie clip. The onEnterFrame event handler loops whatever function is assigned to it at a brisk rate of 25 frames per second - which also happens to be your movie's frame rate! That's not a coincidence, for the rate at which onEnterFrame loops code is the same as the animation's frame rate in ActionScript 1.0/2.0.

Twenty-five times a second, the fadeOut function is called, and the argument passed into it is this, which in this case, refers to the newMC movie clip itself! It's time to take a look at the fadeOut function now.


function fadeOut(inputMC:MovieClip):Void {
inputMC._xscale += 10;
inputMC._yscale += 10;
inputMC._alpha -= 1;
if (inputMC._alpha<0) {
inputMC.removeMovieClip();
delete inputMC.onEnterFrame;
}
}

The fadeOut function is called by the onEnterFrame event from our attachOnMove function. It takes for its argument a variable whose type is movie clip. This passed-in variable, inputMC, will reference the particular circle that is placed on your stage via the atttachMovie function you saw earlier.


There is more code that will be explained on the next page!

Onwards to the next page!

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8

SUPPORTERS:

cloud storage
cloud storage
kirupa.com's fast and reliable hosting provided by Media Temple. Creative web apps. Make your own free flash banners and photo slideshows.
HTML5 CSS3 Mobile Gallery for iPhone, iPad Flash effects. Art without coding.
Flipping Book - page flip flash component. Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery
X-Platform Application Development for Flash Free Flash Components Download - XML Templates, Players and Galleries.

two computer monitors

US Direct

Learn how to advertise on kirupa.com  
 
SHARE:



MINI SUPPORTERS: