Leave a Reply

Your email address will not be published. Required fields are marked *

8 Comments

  • hi ashton, looks good i was looking some like this. where do we put this script? in the first scene?

  • Hi,

    Yes. Make the first scene a blank screen, and put this code in one of the frames.

    Then have the end of each of your scenes redirect back to the beginning of the first scene.

  • Hi Ashton,

    I added the code to the end of each scene (3 scenes total) where I previously had code to go to the next scene. But this seems to repeat quite frequently. Do you know a way to prevent repeating schne?

  • Hi Jeff,

    Thanks for the question. Yes, to make the scenes not repeat, do not put the current scene in the randomizing code.

    For example, for the first scene, don’t have “GotoAndPlay(“scenename”, 1);” You’ll have to change the code to be for two scenes since you are removing one of them. That way, there is no chance to play the scene you are already in.

    I hope that helps,
    Ashton Sanders

  • Niiiiiiice! Exactly what I was looking for. Using with GotoAndStop to randomly display different call-to-action hero images on a home page. THX 🙂

  • Sure this could be use for what I’m currently working on – starts with cow wandering around a field for ten seconds, and it should then randomly select one of 11 scenes, each one with a cow pat in a different bit of the field – once the cow pat scene had finished, it then goes back to the cow wandering the field – all working fine apart from the randomly selecting which cow pat scene it plays – I’ve named all the frame1s for each scene with scene 1, scene 2 etc because a different tutorial told me too, but I still can’t get it to work… here’s the script that I’ve currently got in the last frame of the cow wandering about the field scene…

    set(scenes, [“scene 2”, “scene 3”, “scene 4”, “scene 5”, “scene 6”, “scene 7”, “scene 8”, “scene 9”, “scene 10”, “scene 11”, “scene 12”]);
    gotoAndPlay(scenes[random(12)]);

    (on the first frame of the cow wandering about the field scene is the random movement script that makes the wander randomly)

    the whole project is for a school fete, where my form want to run a poo-lette stall – people “bet” on which bit of the field the cow will poo in first – figured we can’t get a real cow into school so this will have to do – anyone who can help I’d be very grateful.

  • TYVM! Exactly what I was looking for (like OmegaTech said).
    Needed that to randomly show images on my website banner (school project)

    Thanks very much!

  • U can try this code…
    Condition = for 3 scene (name scene = Scene_1,Scene_2,Scene_3)
    Where to put this code (First layer, first frame)

    sheeta = random(3);
    if (sheeta == 0) {
    gotoAndStop(“Scene_1”, 1);
    }
    if (sheeta == 1) {
    gotoAndStop(“Scene_2”, 1);
    }
    if (sheeta == 2) {
    gotoAndStop(“Scene_3”, 1);
    }

    u can use button for the trigger to execute this action with the code :
    on(release)
    {

    sheeta = random(3);
    if (sheeta == 0) {
    gotoAndStop(“Scene_1”, 1);
    }
    if (sheeta == 1) {
    gotoAndStop(“Scene_2”, 1);
    }
    if (sheeta == 2) {
    gotoAndStop(“Scene_3”, 1);
    }

    }

    good luck