FORUMS: list search recent posts

How to rotate between movie clips

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Aja Shamblee
How to rotate between movie clips
on May 23, 2013 at 9:40:10 pm

I have five movie clips that are basically going to be stills of an image. These need to be randomly played for 5 seconds until they slide to the next movie clip.

I know that I need to use an array to call out the movie clips, but I'm very unfamiliar with getting it to randomly pick one and play it for 5 seconds until it goes to the next one. Can anyone help me with this?


Return to posts index

Sam Mattern
Re: How to rotate between movie clips
on Jun 7, 2013 at 11:47:47 am

Well, a simple way to do it is to have a function that is called every 5 seconds that generates a random number between 1 and 5, and then plays that clip. Depending on your Actionscript version, it goes something like:

var myTimer:Timer = new Timer(5000, 1); // 5000 milli-seconds = 5 seconds
myTimer.addEventListener(TimerEvent.TIMER, generateNumber);
myTimer.start();

function generateNumber(event:TimerEvent):void {
loadClip(Math.floor(Math.random() * (5 - 1 + 1)) + 1);
//sends loadClip a 1,2,3,4,5
}


To save time and explanation, I got the generateNumber guts from someone else. You can read the explanation of it here:
http://active.tutsplus.com/tutorials/actionscript/quick-tip-get-a-random-nu...

Now thinking about it, if you are using an array, you can simplify the generateNumber function to select a number from 0-4, which is a lot easier.

-Sam


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]