Flash tutorials
Home 3D (2) Actionscripting (65) Animation (100) Audio (4) Drawing (7) Full flash sites (4) Getting Started (15) Navigation (25) Special Effects (52) Text Effects (38)

Random effect

2.11.2006, 0:18    Total views: 34825

Learn this tutorial and see how to create random effect in flash using the Action Script code. Using this action script tutorial, you will also learn how to convert any object into a Movie Clip Symbol, how to create instance name, how to draw cube and more!

Example:



Step 1

Create a new flash document, press Ctrl+J key (Document Properties), and set Width to 330 and Height to 200px. Frame rate set to 16fps (Frames per Second).



Step 2


Take the Rectangle Tool (R), and draw a "cube" 25x25px. See the picture below.





Step 3

While your "cube" is still selected, press F8 key to convert it into a Movie Clip. See the picture below.



Step 4

Then, open the Properties Panel (Ctrl+F3), and under  type cube.



Step 5

Select the "cube" again, open the Action Script Panel (F9), and paste this script:

onClipEvent(enterFrame){
r=Math.floor(Math.random()*255)
g=Math.floor(Math.random()*255)
b=Math.floor(Math.random()*255)
colourobj=new Color(this)
colourobj.setRGB(r<<16|g<<8|b)
}

Step 6

Cick on frame 1, open again the Action Script Panel (F9), and paste this sctipt:

for(i=1;i<=50;++i){
duplicateMovieClip("cube","movie"+i,i)
}
numobjects=1
for(i=1;i<=10;++i){
for(z=1;z<=5;++z){
this["movie"+numobjects]._x = i*30;
this["movie"+numobjects]._y = z*30;
numobjects+=1
}
}
cube._visible = false;

Test your Movie (Ctrl+Enter).

We're done!

Download source file (.fla)

Have questions about this tutorial?
Visit our friendly Community Forums!
Digg it! Add this tutorial to del.icio.us! Furl it! Add this tutorial to reddit! Spurl it! Add this tutorial to technorati!

Top tutorials

1. Advanced full flash site - Part 1
Total views: 221536

2. Water effect
Total views: 166041

3. Photo slide show
Total views: 153641

4. High-tech city animation
Total views: 151459

5. Special Picture Effect
Total views: 146247

Related links