dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: how to play scenes randomly

  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    1

    how to play scenes randomly

    Hi, I have a file containing 4 diffrent scenes.
    I want them to play "randomly". How can I do that?
    Is there any action script for that? Please guide me.

    Madhura

  2. #2
    Senior Member olias32's Avatar
    Join Date
    Jan 2003
    Location
    Romania
    Posts
    126
    basically you need to have the following action script at the point in the current timeline where you want the change to take place:

    Code:
    scene_name = new Array["scene 1", "scene 2", "scene 3", "scene 4"];
    
    do {
      a = random(4);
    } while (a == current_scene_number);
    
    gotoAndPlay(scene_name[a], 1);
    replace current_scene_number by the scene number you are in (this is done so we make sure we dont play the same scene we're in)
    e.g.

    if you're in "Scene 3", the code looks like this:

    Code:
    scene_name = new Array["scene 1", "scene 2", "scene 3", "scene 4"];
    
    do {
      a = random(4);
    } while (a == 3);
    
    gotoAndPlay(scene_name[a], 1);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center