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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using one button to play two scenes?? 2

Status
Not open for further replies.

surly

Technical User
Oct 26, 2001
54
0
0
GB
How do I make one button play two scenes in sequence?
I can get the first part (go to and play scene x frame 1) but once that has finished, I want to 'go to and play' another scene without clicking the button again.

The first scene to be played will be the same for each of my buttons, but the second scene is different for each one.

For example....
press button A - plays scene 2 then scene 4
press button B - plays scene 2 then scene 8
 
I guess you have stop(); actions at the end of each scene, otherwise Flash would automatically play the next one in line. So one way of achieving your goal would be to set a variable differently when each button is pressed and to check that variable at the end of the second scene, and re-directing the movie to play the appropriate scene.

Button A:

on (release){
_root.scene_togoto = "Scene 4";
_root.gotoAndPlay("Scene 2", 1);
}

Button B:

on (release){
_root.scene_togoto = "Scene 8";
_root.gotoAndPlay("Scene 2", 1);
}

Then on an ending keyframe of Scene 2, you would add something like:

stop();
if(_root.scene_togoto == "Scene 4"){
_root.gotoAndPlay("Scene 4", 1);
}
if(_root.scene_togoto == "Scene 8"){
_root.gotoAndPlay("Scene 8", 1);
}

Now this would only work if your buttons are on the main timeline. If you ever put your buttons in movie clips, or they're inserted in external movies loaded on other levels, targeting scene names, would not worked. You'd have to use frame labels instead. You would label the first frame of each scene with an unique label (no number only labels or at least not starting with numbers), and target that labeled frame rather than the scene name. Thus if the first frame of Scene 4 was labeled with something like start4 and the first frame of Scene 8 with start8, then the above script would be changed to:

stop();
if(_root.scene_togoto == "Scene 4"){
_root.gotoAndPlay("start4");
}
if(_root.scene_togoto == "Scene 8"){
_root.gotoAndPlay("start8");
}

This labeled frame method would work even if the buttons were on the main timeline, so you might as well get used to use it everywhere.
So if the first frame of Scene 2 was labeled with start2, then...

Button A:

on (release){
_root.scene_togoto = "Scene 4";
_root.gotoAndPlay("start2");
}

Button B:

on (release){
_root.scene_togoto = "Scene 8";
_root.gotoAndPlay("start2");
}


Regards,

cubalibre2.gif
 
If you press buttonA and you always have the same sequence, like, scene 4 then scene 8, then on the last frame of scene 4 put a gotoAndPlay() function. Inside the gotoAndPlay() function use a scene name to refer to scene 8, instead of the number. This way if you ever add scenes or delete scenes, your sequence to play is still the same. To reiterate, on buttonA you put:

on (press){
_root.gotoAndPlay("Scene4"); //Scene4 should be a reference name.
}
On the last frame of scene 4, put:
_root.gotoAndPlay("Scene8"); //Scene8 should be a reference name.

However, if one button doesn't always play the same two scenes, you will have to use script such as oldnewbie suggested.
 
Many thanks for your contributions.

As the buttons dont always play the same 2 scenes, I have implemented oldnewbie's method with defined variables, and this has worked brilliantly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top