Flashadvisor logo
:: Desktop Shortcut
:: Flash Help
Advices from Experts

 Submit Here! · Link to Us · Newsletter · Tell a Friend ·

      Add Tutorial |

 

Advertise here










 

Google

Search WWW   
FlashAdvisor.com

 Home > Tutorials  > ActionScript

"Starfield Simulation" effect using "duplicateMovieClip"

Author: Saumitra Karandikar | Email


Advertisement


The shots from a machine gun, the fire flares from a space ship tail, the water droplets from a fountain, all represent Movie Clips when created on a Flash timeline. But what if there are thousands of these to be created dynamically? Yes, it is possible to add multiple movies by directly dragging movie clips from the library. But then there position is constant on the timeline and cannot be changed randomly. Additionally, it will also take up a lot of time to build such an animation.
Actionscript comes to rescue us here.
Imagine a scenario where you need to create the classic "Starfield Simulation" or the "Flying Windows" like animation where "windows" or some arbitrary text comes flying from far of and zooms off the screen.
Lets go step by step. Create an animation representing zooming text. Using tweening you can build such an animation in seconds. The animation would actually be on a Movie Clip timeline instead of the root timeline. Let call the Movie Clip "flying_mc". Representing Movie Clips with the instance name ending in "_mc" is always wise. It automatically pops up the dropdown menu with methods available for Movie Clip object thus making life easier and saving lots of lines of typing. Same applies for a button where you can use "_btn". Coming back to our "flying_mc", see the snapshot of the f;lying mc below in fig 1.1



Fig 1.1

Notice the use of graphic symbol before making a tween. This saves us on file size. Also notice the use of the "transform" panel in Flash. The initial size has been scaled down to 30%. The library now contains the Movie Clip with the tweened symbol.
Next, lets imagine that we need to create 50 such animations on the screen coming from at different locations one after the other, every half a second.
Before we delve into the code, name the Movie Clip as "flying_mc" in the "properties" dialog box without which our actionscript fails.(Fig 1.2)



Fig 1.2

Next let us create another layer called the "actions". We will use duplicateMovieClip function of the Movie Clip object to create multiple movieclips on the fly as follows.
As the first step, initialize a counter to 0. Lets call it "mycount"; this will be used to check if the duplicated movies have exceeded our desired count of 50.
In Step2, we write out function to create duplicate Movie as:


_root.flying_mc.duplicateMovieClip("flying_mc"+mycount , _root.getNextHighestDepth());


Lets look closely; Written as above, the method duplicateMovieClip takes 2 parameters viz, new name and new depth. We will keep the depth as variable mycount. We will keep increasing the depth till it becomes 49 and alongside also continue duplicating the movie clip.
The getNextHighestDepth() method indicates the next highest depth in the indicated Movie Clip in this case the "root".

Now, we have successfully duplicated our Movie Clip.

Download Source File

| 1 | 2 | 3 |

Rate This Tutorial :
We hope the information helped you. If you have any questions or comments, please don't hesitate to post them on the Forums section
Submit your Tutorial at Click Here
  

Home | About Us | Contact Us | Feedback | Advertise with us

Best viewed in 800x600 resolution with Internet Explorer.

Site Developed and Hosted by  ethicsolutions.com
All rights reserved with FlashAdvisor

Flash is a registered trademark of Adobe Systems, Inc.

3 users online