Skip to main content
Known Participant
May 18, 2006
Question

Random Frame From Range

  • May 18, 2006
  • 4 replies
  • 411 views
Hey I need the timeline to jump to a random frame from a range which are labeled. The purpose is to give a random set of "resting" animations for a game character". I am already using a time delay script I just want to know how to get to a random frame from a predefined range!

Thanks

Sam
This topic has been closed for replies.

4 replies

Inspiring
May 18, 2006

myRand = random(9);

myFrameNames = "Animation"; //assuming your Frame Labels are Animation1, Animation2


gotoAndPlay(myFrameNames+myRand);
Known Participant
May 18, 2006
Thanks guys, I'll give that a try!
Inspiring
May 18, 2006
you could list all your frame labels in an array and pull out a random one.

var myArrayName = new Array();
myArrayName[0] = "Animation4
myArrayName[1] = "Animation3";
myArrayName[2] = "Animation2";
myArrayName[3] = "Animation1";

gotoAndPlay(myArrayName);

Not too sure on the random function but you could look it up.
Inspiring
May 18, 2006
gotoAndPlay("FrameLabel");

gotoAndPlay(4); // notice not""
Inspiring
May 18, 2006
Hi!

Try using this function to get a random number in the range [a,b]:
getRandom = function(a,b) {
return Math.round(Math.random()*(b-a))+a;
}

/Jensen/
"mynameissam.co.uk" <webforumsuser@macromedia.com> wrote in message
news:e4hag9$nt8$1@forums.macromedia.com...
> Hey I need the timeline to jump to a random frame from a range which are
> labeled. The purpose is to give a random set of "resting" animations for a
> game
> character". I am already using a time delay script I just want to know how
> to
> get to a random frame from a predefined range!
>
> Thanks
>
> Sam
>


Known Participant
May 18, 2006
Hey, so how would that work with names of frames and the gotoAndPlay function. Would I list the frame names, and if so, how would I make it play the frame?