Display frames in random order.
Download source project here (3 kb)
- Launch Flash Designer and choose Blank
- Set movie dimensions 230 x 100 (or any desired) with Frame > Frame Size
- Change frame delay to “0.05″.
- Choose “Frame” > “ActionScript” and paste the code:
// generate random number (f) but different than the last one (l) // the number will be between 1 and 6 while(f==l) { f = Math.Floor(Math.Random()*6)+1; } // remember the last random number l = f; // jump to a frame if(f==1) gotoAndPlay("Frame 2"); if(f==2) gotoAndPlay("Frame 3"); if(f==3) gotoAndPlay("Frame 4"); if(f==4) gotoAndPlay("Frame 5"); if(f==5) gotoAndPlay("Frame 6"); if(f==6) gotoAndPlay("Frame 7"); - Choose “Frame” > “Insert”, put Qty: 6 and delay 2 seconds
- Put graphics on each frame (from Frame 2 to Frame 7) for example numbers
- Hit F9 for preview.




February 24, 2011 at 5:19 pm
This example has been the best match for what I am trying to accomplish in a banner ad I am working on! I ran into one problem with my test file:
- I am using Flash CS5 with AS2.
- everything in my test file went smoothly except the random order did not work (my frame sequence ran 1,2,3,4,5,6,7, repeating)
- the AS compiler error I received was:
Scene=Scene 1, layer=actions, frame=1, Line 4 There is no method with the name ‘Floor’.
- I also tried recreating the test file using AS3, but encountered more compiler errors =(
- here is the (same as above) code I copied & pasted:
// generate random number (f) but different than the last one (l)
// the number will be between 1 and 6
while(f==l) { f = Math.Floor(Math.Random()*6)+1; }
// remember the last random number
l = f;
// jump to a frame
if(f==1) gotoAndPlay(“Frame 2″);
if(f==2) gotoAndPlay(“Frame 3″);
if(f==3) gotoAndPlay(“Frame 4″);
if(f==4) gotoAndPlay(“Frame 5″);
if(f==5) gotoAndPlay(“Frame 6″);
if(f==6) gotoAndPlay(“Frame 7″);
If there is anything I did wrong or any changes I need to make, please advise. Thanks!!!
February 24, 2011 at 8:42 pm
P.S.
The compiler error went away after changing 2 upper case letters (Math.Floor and Math.Random) to lower case Math.floor and Math.random.
Unfortunately my frame sequence is still the same (rather than random).