7 Replies Latest reply on May 18, 2008 7:23 AM by clbeech

    Go to scene using numeric stepper

    mooque
      I am trying to make a simple numeric stepper that takes the user to another scene...with or without the use of a button (it doesn't matter)

      I'm pretty sure it's an easy thing to do, but for some reason what I've done doesn't work. I have named the button "goscenebtn" and the numeric stepper "gosceneno".

      The code attached is the code for the button. I'm not sure if I referred to the value of the numeric stepper correctly.
        • 1. Go to scene using numeric stepper
          Ned Murphy Adobe Community Professional & MVP
          If you are accessing a variable to define the scene, don't use quotes (assuming gosceneno is some form of an object and value is a quoted string):

          gotoAndPlay(this._parent.gosceneno.value,1);

          OR

          gotoAndPlay(_parent.gosceneno.value,1);
          • 2. Re: Go to scene using numeric stepper
            mooque Level 1
            When I remove the quotes, CS3 brings up an error "Scene name must be enclosed in quotes". Also, it still does not work for some reason.

            Thanks for that anyway.

            Any more solutions?
            • 3. Re: Go to scene using numeric stepper
              clbeech Level 3
              the return value from the 'numeric' stepper is going to be a number - Neds right no quotes - however the value will simply be a number. unless you've renamed the scene's you'll need to use that number along with a string in order to nav to the correct scene (fyi - using scenes are not great and can cause problems when coding - they are meant more for management when producing animations)

              so the usage should be (provided they are named: Scene 1, Scene 2, etc)

              on(press) {
              _parent.gotoAndPlay('Scene '+_parent.gosceneno.value, 1);
              }
              • 4. Go to scene using numeric stepper
                Ned Murphy Adobe Community Professional & MVP
                Here's an odd one... I was trying to see what the deal was and was getting errors as well, though it did play.

                I looked around online and saw a few instances where the order of the gotoAndPlay() arguments were reversed. So I tried it, and the errors went away... (this is using AS3, since you said you were using CS3)

                var sceneName:String = "Scene 2";

                gotoAndPlay(1, sceneName);

                Now that I look at the Flash help file, somewhere along the line someone decided to switch the order between AS2 and AS3... I gotta wonder about the guys who rewrote the language!

                And I agree that scenes are best avoided. I rarely use them except in certain cases.
                • 5. Re: Go to scene using numeric stepper
                  clbeech Level 3
                  DOH!! lol - yeah you're right Ned - they are reversed there for 2 - wasn't thinking - PHA HA!

                  yeah, scene are bad news when coding for certain - it's much better to use frame labels to nav the timeline. personally i wish that they'd done away with them altogether - it's confusing for early users, because they seem like a good way to organize a timeline structure - and are for straight-line animations, but bad for scripting.

                  additionally mooque - you should work at placing your codes within a frame on the timeline (usually we make a layer called 'actions' and place everything there) as opposed to the object attachment method as you've used above - it's a 'best practice' to do so, because it makes finding all of the operational codes easy as well as connecting paths more accessible. However the syntax is little different - but far better in the long run. in fact attaching code to objects has been eliminated in AS3. so if you were to place the code on the timeline it would look like this:

                  my_btn.onPress = function() {
                  gotoAndPlay(1, 'Scene '+gosceneno.value);
                  }

                  of course you need to give the button an 'instance name' - in the case above this is 'my_btn' - you do so in the properties panel.
                  • 6. Re: Go to scene using numeric stepper
                    mooque Level 1
                    So the problem was that I didn't add "Scene " in front of the value...now I feel quite stupid for doing that.

                    Thanks for all the help guys! The darn thing works now
                    • 7. Re: Go to scene using numeric stepper
                      clbeech Level 3
                      you're welcome - and np mooque, don't feel stupid, it takes time to learn these things, and it's smart to ask questions to learn the answer.

                      yeah - the parameter requires a 'string' so were just taking the numeric value from the stepper and 'concatenating' (adding) it to the string as needed.