Coding
i. One thing that we must do before we write the code is give our fire Movieclip an instance name. That's because we're going to need to address it through Actionscript in a moment.
So, select the fire Movieclip and press Ctrl + F3 to open your Properties window, in case it's not already opened. In the bottom-left corner of this window should be a text field. This is where we specify the instance name of symbols. Type fire there. Yes - that's the name of our symbol as well.
![]() |
ii. Next, select the first frame of the main timeline and press F9. In the Actionscript window that will appear, type the following code:
- i = 0;
- Mouse.hide();
- this.onEnterFrame = function() {
- i += 1;
- _root.fire.duplicateMovieClip("fire"+i, i, {_x:_root._xmouse+random(4), _y:_root._ymouse});
- };
Important!
OK, we could pretty much finish our tutorial here. But, there is one very important reason why we shouldn't.
You see, each of the duplicated Movieclips, although not visible, is still there, which means that we will have thousands of Movieclips on the stage in just a few minutes. The problem with that is computers are slowed down considerably when dealing with some many Movieclips at the same time.
So, what can we do?
Yes - we have to get rid of the Movieclips that we don't need anymore. To do that, select the fire Movieclip and press F9. In the Actionscript window that will appear, copy and paste the following code:
- onClipEvent(enterFrame){
- if(random(300) == 0){
- removeMovieClip(this)
- }
- }
OK, now here comes something for those who could do with some explanation.
Explanation
- Mouse.hide();
First off, we get rid of the mouse.
- i = 0;
Then, we need to declare the i variable. We will use this variable to duplicate the Movieclips.
- this.onEnterFrame = function() {
- i += 1;
- _root.fire.duplicateMovieClip("fire"+i, i, {_x:_root._xmouse+random(4), _y:_root._ymouse});
- };
The first line is an event handler which tells Flash to execute what is between its opening and closing curly brackets every frame. Now let's have a look at what happens within the event handler.
- i += 1
a) we increment (increase by 1) the i variable.
- _root.fire.duplicateMovieClip("fire"+i, i, {_x:_root._xmouse+random(4), _y:_root._ymouse});
b) we duplicate the Movieclip whose instance name is fire, and then use the variable i to give the newly-duplicated Movieclip a unique name. So, the duplicated Movieclips' names will be fire1, fire2, fire3, fire4, fire5, and so on.
In the curly backets Also, we can specify other properties of the duplicated Movieclips. For example, in the above code, we specify the x and y coordinate of the Movieclips. As you can see, the y coordinate is the same as the y coodrinate of the mouse, while the x coordinate is the same but a random number is added to it. I did that to receive an effect of randomness that characterises a flame.
And here comes the explanation for the code place on our Movieclip:
- onClipEvent(enterFrame){
- if(random(300) == 0){
- removeMovieClip(this)
- }
- }
So, we've got an event handler again. What is does is tell Flash to execute the code that is between its opening and closing curly brackets everyframe.
And what is the code that is executed every frame all about?
It is in fact an if statement that checks if a random number, picked from 0 to 299, is equivalent to 0. The reason I did that was I wanted to give some time for the Movieclip to play its animation, and disappear only when it's over. To delete the Movieclips I used the removeMovieClip function.
Below you can download the FLA files for your better understanding.
Alright, I think this is it. Thanks for reading!
Cheers!

