MINI SUPPORTERS:

 

 

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

We wrapped up the main part of the tutorial on the previous page. In this, the last page, we tie up some unfinished ends!


Putting it All Together
At this point, you re-created the mouse-trail like effect as well as learned about how each line of code works. In this section, let's go back and re-visit some of the important concepts beyond just the code that I hope this tutorial communicated.

Obviously, learning how to use attachMovie is a big part of this tutorial. Creating re-usable movie clip is both a great way to reduce file size, but it also makes maintenance and future updates much easier when all you have to do is change one movie clip instead of several individual movie clips.

Using attachMovie has its own set of issues that need to be addressed. One major issue is being able to assign unique values to the the newly attached movie clip's properties and variables. There is no easy way to use an onLoad event handler with a dynamically generated movie clip placed on stage via attachMovie, loadMovie, createEmptyMovieClip, etc. So, in this tutorial, I explained how to pass in the values for the properties of your movie clip object as part of the attachMovie function's argument itself. There are other, more indirect ways, of simulating onLoad, and the following code provides one way of using the onEnterFrame event handler and deleting it after it has gone through one iteration:

var newMC:MovieClip = this.attachMovie("blueCircle", "blue"+count, 10000+count);
newMC.onEnterFrame = function() {
this._x = xPos;
this._y = yPos;
this._alpha = 10+Math.random()*40;
this._xscale = this._yscale=scale;
delete this.onEnterFrame;
};

The above method approach has its drawbacks also. For example, it is tricky to both assign your initial properties using onEnterFrame, deleting onEnterFrame, and then creating another onEnterFrame event handler to deal with the animation. Until, hopefully, future versions of Flash address this issue, you can read senocular's FAQ on this as well as take a look at some solutions at the always-useful http://proto.layer51.com/ site.

Finally, keeping each movie clip's properties and variables from interfering requires some planning. If a variable happened to accidentally be declared outside the scope of an individual movie clip, then you will find that this particular variable's data is shared across all movie clips. That might be useful in some cases, but when each movie clip is part of an animation with its own scale and alpha values, a global variable is not preferable.


Phew! With that, I hope this tutorial helped give you a better understanding of using attachMovie and dealing with some of the issues that you can encounter with it. I have provided the source file for my version of the example animation you saw on the first page.

Need Help?

If you have questions, need some assistance on this topic, or just want to chat - please drop by our friendly forums and post your question. There are a lot of knowledgeable and witty people who would be happy to help you out. Plus, we have a large collection of smileys you can use

Share

Did you enjoy reading this and found it useful? If so, please share it with your friends:

If you didn't like it, I always like to hear how I can do better next time. Please feel free to contact me directly at kirupa[at]kirupa.com.

Cheers!

Kirupa Chinnathambi
about | facebook | twitter

 

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: