?
Solved

random jump to labelled set of frames

Posted on 2003-03-26
10
Medium Priority
?
184 Views
Last Modified: 2010-04-03
Hello

Could anyone help with this(simple)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 randomly choose from(labels are travel, portrait, still life, food, lifestyle. The idea is that each labelled frame loads in 2 external .swf files of images.

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 expertise: beginner/intermediate.


0
Comment
Question by:cu72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 6

Expert Comment

by:henryww
ID: 8211937
what do u mean it is nothing too work?

ur code looks ok ... except
randomNumber = Math.ceil(Math.random()*myArray.length);

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

the array is zero base :)

cheers
0
 
LVL 6

Expert Comment

by:henryww
ID: 8211944
i mean it should be

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

the array is zero base :)

cheers
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 8212231
maybe you should try

gotoAndStop (NUMBER(myArray[randomNumber]));
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cu72
ID: 8212279
Thanks henryww that fixes one of the problems - but I have one more snag - and this might be something to do with my Flash inexperience..

This random action takes place in one scene (scene 2). When I try to put a scene before this (scene 1 - this scene contains some animation) the random action doesn't work any more. After going through scene 1 the playhead goes to scene 2 where the random jump frame is - but the playhead then always jumps straight to the last labelled frame in the scene - it seems to ignore most of the random action code.

there is nothing in scene 1 - just the usual 'gotoAndPlay ("Scene 2", 1); code.

Hope this makes sense.

Thanks



0
 
LVL 6

Expert Comment

by:henryww
ID: 8212401
well, u mean u insert a new scene before that random function? ... and it doesn't work ...

try the following and make sure labels are different
rename the scenes so there is no space between scene & 1
ie: scene 1 -> scene1 or any single word no spaces

// put the code in scene1 - frame 1
myArray = new Array("travel" , "portrait", "still life", "food", "lifestyle");
function rndLabel(){
     r = Math.floor(Math.random()*myArray.length);
     gotoAndStop (myArray[r]);
}


// anywhere in sceneX - frame X
rndLabel();

see if this helps

cheers
0
 

Author Comment

by:cu72
ID: 8212576
Hello Henryww

Just to clarify

Scene1 has the animation

Scene2 has the random function and the labelled frames.

Scene2 with the code above works fine until I put in a Scene 1 before it.

I've taken out the spacing in scenes 1 + 2 - no difference.

Sorry - are you suggesting I put your script in scene 1 frame 1 and stick the rndLabel(); anywhere in scene 1?

I'll certainly try it if I have understood correctly.

Thanks again


0
 
LVL 6

Accepted Solution

by:
henryww earned 400 total points
ID: 8213003
yes, try this

// put the code in ***scene1*** - frame 1
myArray = new Array("travel" , "portrait", "still life", "food", "lifestyle");
function rndLabel(){
    r = Math.floor(Math.random()*myArray.length);
    gotoAndStop (myArray[r]);
}


// scene1 last frame
gotoAndPlay("scene2",1);




then ... call the function in scene2
//scene2 - frame2
rndLabel();


see if that helps

:P
0
 
LVL 9

Expert Comment

by:rexmor
ID: 8214557
cu72,
Try this it works for me..

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

hope this help

rex
0
 

Author Comment

by:cu72
ID: 8221180
Hello henryww

Sorry - got tied up with something else - I've just tried what you suggested and it works fine - sorted out the problem. Thank very much for your help. I don't know exactly why putting the code at the beginning and calling the function later on worked - perhaps if you have a moment you could tell me why. Don't worry if you haven't the time and thanks again for the help.

cheers

thanks also rexmor for you suggestion - I'll have a look at this.
0
 
LVL 6

Expert Comment

by:henryww
ID: 8226902
that's ok as long as ur problem is solved.

anyway, the putting the function is scene1 (first scene) works, i am not 100% sure why, guess that's the way scenes and labels are arranged and it goes back to the very beginning and start looking from there to see if there is a matching label ...

cheers
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question