Toxiclab.org

Random Glow Ball animation

27.2.2010, 15:13
Submited in: Flash | Total Views: 8847

Using this thoroughly explained, detailed flash lesson, I will explain to you how to create advanced random ball animation using the Action Script code. You can use this animation for some presentation or for some web banner. Using this lesson, you will also learn how to convert any object into a movie clip symbol, how to create instance name, how to apply flash filters on it and much more. Let's start!

Example:



Step 1

Create a new flash document. Press Ctrl+J key on the keyboard (Document Properties) and set the width of your document to 400 pixels and the height to 300 pixels. Select white color as background color. Set your Flash movie's frame rate to 35 and click ok.



Step 2


Select again the Oval Tool (O).  In the Colors portion of the Tool panel, block the Stroke color by clicking on the little pencil icon and then on the small square with the red diagonal line. For Fill color choose #247E14 and draw a circle shape about 15x15 px.

Step 3

While the circle shape is still selected, hit F8 key (Convert to Symbol) to convert it into a Movie Clip Symbol.



Step 4

While the new made Movie Clip is still selected, go to the Properties Panel below the stage. On the left side, You will find the Instance name input field there. Call this Movie Clip ball. See the picture below!



Step 5

Select the Selection Tool (V) and click once on the circle to select it. Then, go to the Properties Panel (Ctrl+F3) below the stage. After that, select Filters tab from the left side. Click on the plus icon and select the Blur filter. Make the adjustments as follows:



Step 6

Select again the circle and go to the AS panel (F9). Then, enter the following Action Script code, inside the Actions panel:

onClipEvent (enterFrame) {
 setProperty(this, _x, _x + randomx);
 setProperty(this, _y, _y + randomy);
 if ((_x < _width/2) or (_x > (400-_width/2))) {
  randomx = -randomx;
 }
 if ((_y < _height/2) or (_y > (300-_height/2))) {
  randomy = -randomy;
 }
}

Step 7

Call the current layer ball. Double-click on its default name (Layer 1) to change it. Press Enter once you have typed in the new name!

Step 8

Create a new layer above the layer ball and name it action script.

Step 9

Select the first frame of layer action script and go again to the AS panel (F9). Then, enter the following Action Script code, inside the Actions panel:

setProperty("ball", _visible, false);
for (i=0; i < 50; i++) {
 duplicateMovieClip("ball", "ball" + i, i);
 randomscale = Math.random ()*90 + 10;
 setProperty("ball" + i, _xscale, randomscale);
 setProperty("ball" + i, _yscale, randomscale);
 eval("ball" + i).randomx = (Math.random ()*10) +4;
 eval("ball" + i).randomy = (Math.random ()*10) + 4;
}

We're done!

Test your animation and enjoy!

Download example

Are you a website owner?
Click here to register and submit your tutorials!

Browse by category


Most popular tutorials