Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random jump to a labelled frame

Status
Not open for further replies.

cu92

Technical User
Feb 11, 2003
6
GB
Hello

Could anyone help with this problem?

I want the playhead to run into a frame and randomly jump to a labelled frame further on in the timeline. There are 5 labelled frames to choose from(labels are travel, portrait, still life, food, lifestyle.)

I have tried using this on the timeline jump frame:

myArray = new Array("travel" , "portrait", "still life", "food", "lifestyle");
randomNumber = Math.ceil(Math.random()*myArray.length);
gotoAndStop (myArray[randomNumber]);

its kind of working but not too well - makes me think I'm doing somthing wrong.

Any help would be greatly appreciated.

Thanks.

LEVEL of FLASH: beginner/intermediateish
 
What do you mean it is kind of working but not too well? What is it doing wrong...
 
your code will be debuggable but this will work...just extend it for 5

theFrame = Math.round(Math.random()*5);
switch (theFrame) {
case 0:
gotoAndStop("travel");
break;
case 1:
gotoAndStop("food");
break;
case 2:
gotoAndStop("portrait");
break;
default:
gotoAndStop("food");
}




 
Thanks Bill

I think I just sorted out the original problem -

randomNumber = Math.FLOOR(Math.random()*myArray.length);

instead of

randomNumber = Math.CEIL(Math.random()*myArray.length);


- though I'll still look into your way of doing it.

thanks again. (and thanks for the interest TheConeHead)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top