1 Reply Latest reply on Jan 12, 2013 7:20 PM by kglad

    Choose a random scene

    Delaano

      Hello everyone!

       

      I have problem with a script i created. This is the idea; if i hit the space bar a random scene needs to appear.

      Can anyone help me?

       

      var keyListener:Object = new Object();

      keyListener.onKeyDown = function() {

                if (Key.getCode() == 32) {

                          //do something here for space bar press

                          var scene = random(3);

      if (scene == 0) {

                gotoAndStop("Scene 2", 1);

      }

      if (scene == 1) {

                gotoAndStop("Scene 3", 1);

      }

      if (scene == 2) {

                gotoAndStop("Scene 4", 1);

      }

       

       

                }

      };

       

      Key.addListener(keyListener);

        • 1. Re: Choose a random scene
          kglad Adobe Community Professional & MVP

          you shouldn't use scenes for navigation with as2 and you shouldn't use the goto functions.  use frame labels and the goto methods:

           

           

           

          var keyListener:Object = new Object();

          keyListener.onKeyDown = function() {

                    if (Key.getCode() == 32) {

                              //do something here for space bar press

                              var scene = Math.floor(Math.random()*3);  // Math.random() is preferred

          if (scene == 0) {

                    _root.gotoAndStop("Scene 2 frame 1");  // label this frame and the others below

          }

          if (scene == 1) {

                    gotoAndStop("Scene 3 frame 1");

          }

          if (scene == 2) {

                    gotoAndStop("Scene 4 frame 1");

          }

           

           

                    }

          };

           

          Key.addListener(keyListener);

          1 person found this helpful