Flash Components      Flash Menu      Flash Gallery      Flash Slideshow      FLV Player      Flash Form      MP3 Player      PhotoFlow      Flash CMS      3D Wall      Flash Scroller

Flash / AS

Silverlight

WPF

ASP.net / PHP

Photoshop

Forums

Blog

About

 


FlashComponents
  Galleries
  Slideshows
  Menus
  Design & Effects
  Audio & Video
  User Interface
  Templates

 

 

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

In the previous page, I provided you with a basic idea of how attachMovie works. Now, let's look at how it applies to our code.


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

Like mentioned earlier, the movie clip we wish to attach to the stage is the blueCircle movie clip. Coincidentally, the Linkage ID value of our blueCircle movie clip is also blueCircle.

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

The second argument specifies the new name of our attached movie clip. I'll be calling the new movie clip blue plus the value of count. The names you will see will be similar to blue0, blue1, blue2, etc.

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

The third argument takes a number that specifies the depth of our attached movie clip on the stage. The most common value used here is the getNextHighestDepth() property associated with a movie clip or a target level such as _root.

In this case, I am creating my own custom depth by picking an arbitrarily large number combined with, again, our count value. I will explain the rationale behind this a bit later.

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

The final argument is the most interesting one, because it allows you to set the initial properties of our movie clip. Notice that the properties are enclosed by the { and } curly braces. Also, the property and its value are assigned using a colon instead of an equals sign such as _x:xPos, _y:yPos, etc.

In the code for this example, I set the _x, _y, _alpha, _xscale, and _yscale properties to the variables I declared earlier. You are not limited to using variables for setting the properties. For the _alpha property, I am using an expression that picks a random alpha value between 10 and 50:

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

In the end, our little blue circles taken from the library, placed at a point where our mouse cursor currently is as defined by  the xPos and yPos variables, and the circles feature random scaling and alpha values thanks to Math.random().

The following screenshot gives you a snapshot of how the animation looks with each circle being a little bit more unique than the preceding circle:

[ notice the random sizes/alphas of the circles generated ]

Let's leave attachMovie and continue on with the code explanation on the next page.

Onwards to the next page!

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


kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components

Flash Templates
CSS Templates
Dreamweaver Templates

flash menus, buttons and components
Digicrafts Components The best flash components ever!
Entheos Flash Website Templates Buy and sell FLAs at Ultrashock!
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com Purchase & Download Flash Components
flash components  Learn how to advertise on kirupa.com