IF & FOR Loop Comparison to Make Fireworks in Flash

Categories TutorialsPosted on

You must have seen Fireworks in Flash on many blogs/sites, but today I’m going to tell you how to make Fireworks in Flash using If and then For loop. You will be noticing the difference between these two Loops. We will be using duplicateMovieClip and setProperty commands alongwith defining variables. So it will be very informative for you.






1. First of all we are going to learn If loop, how to use and how it will have the output during runtime. So take a new file in Flash having size 250×250 px with black background and 40 frames per seconds.

2. Run the command Insert >> New Symbol or simple press F8 key. Write any name in the box and choose Movie Clip from Type list and hit Ok:

3. By using Ellipse tool with Radial Fill, make the following shape alongwith some tiny colorful circles around it (remember all objects should be in same layer and same frame:

4. Now in Timeline, click on Frame 30, hit F5 key to make frames, then right click over it and choose Create Classic Tween then hit F6 key to convert it into KeyFrame and then move these objects towards top almost 70 or 80 px.

5. Now select Frame 20 and hit F6 key to make KeyFrame:

6. Select Frame 1, goto Property Panel, under Color Effect select Alpha from Style list box and give it alpha 0. Just do the same for Frame 30.

7. Now come back to Scene 1 and from Library Panel paste this movie clip outside the Stage. Goto Property Panel and write ‘fire’ in instance box to give it a name:

8. Create new Layer and select its first frame and hit F6 twice to make 2 keyframes:

9. Select first frame and hit F9 key and write the following ActionScript:


10. Select second frame and hit F9 key and write the following ActionScript:


Note: If “fire”+a don’t work then write “fire” add a.

11. Select third frame and hit F9 key and write the following ActionScript:

a=a+1; // it will increase the number of copies
if (a>=500){ // if copies will be greater than 500 then a will have value 1
// it will come back to frame 2

12. You will get this result:


13. Now we are going to give proper angle, goto First Frame and define another variable as:


Now goto Second Frame and modify Rotation property as (remain other things as it is):


Now goto Third frame and replace this code:

a=a+1; // it will increase the number of copies
b=b+5; // it will add 5 into the angle
if (a>=500){ // if copies will be greater than 500 then a will have value 1
if (b>=360){ // if angle would be greater than equal to 360 then it will have value 1
gotoAndPlay(2); // it will come back to frame 2

14. You will get the following result now:


15. Now what would happen if we give it Random X and Y position, for this goto Frame 2 and change the following ActionScript and remain the other code as it is:

setProperty(“fire”+a,_x,random(250)); // write number same as the width of the stage i.e. 250
setProperty(“fire”+a,_y,random(250));  // write number same as the height of the stage i.e. 250

Animation would become like this:



16. So far we have Discussed IF loop, now we are going to check the FOR loop result. I’m going to modify this file for FOR loop. Just delete the second layer on which you have given ActionScript and remove Frame 2 and 3 so you will have only Frame 1. (simply press Shift+F5 key to remove the frames). Move the MovieClip to the center of the stage and write the following code on Frame 1:

for (s=5; s<100; s++) {
duplicateMovieClip(“fire”, “fire”+s, s);
setProperty(“fire”+s, _rotation, random(360));
setProperty(“fire”+s, _alpha, random(30)+50);
setProperty(“fire”+s, _xscale, 50+Number(random(50)));
setProperty(“fire”+s, _yscale, 50+Number(random(50)));
tellTarget (“fire”+s) {

Here will be the result of FOR loop:


A professional Web/Graphic Designer, working as Freelancer since 2000. Designing is my passion, blogging is my hobby.


  1. Hey, I’m new to flash and I have a question about this. I’m trying to make this for loop only play the explosion part once. For example, it explodes once, then stops. How do I do that?

    Also, how would I copy this over so there are a bunch that go off at different times?

  2. Would there be a logical reason why my firework attempt is circling around instead of bursting from a central point. Any help would be greatly appreciated.

  3. Wow! very informative tutorial. That is will be very much helpful for concern professional. Thanks for sharing such a creative work

  4. Excellent report and correct to the point. I don’t perceive if that is truly the best arrange to ask but do you individuals possess any ideea where to make use of some home writers? Give thanks to you

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.