9 Replies Latest reply on Jun 29, 2006 12:51 PM by kglad

    passing frame names to a Goto command

    ricklecoat Level 1
      I have a string variable (let's call it 'myFrame:String') and I want to use this variable as the argument for a gotoAndStop command to send the timeline dynamically to a named frame. The gotoAndStop command accepts frame names if they are between quotes "", but therein lies my dilemma.

      If I put gotoAndStop ("myFrame"), the command will look for a frame named myFrame, which is wrong. But is I put gotoAndStop (myFrame), will not the command be expecting a number argument?

      How should this be resolved? Or am I misunderstanding how the command interprets its arguments?
        • 1. Re: passing frame names to a Goto command
          Level 7
          Try it!

          var myFrame:String = "myFrameName";
          this.gotoAndStop(myFrame);

          Will work. The variable type is a string, so all is well...


          --
          -------------------------------
          Remove '_spamkiller_' to mail
          -------------------------------


          • 2. Re: passing frame names to a Goto command
            kglad Adobe Community Professional & MVP
            use the goto methods (not functions) and flash has no problem handling a string variable.
            • 3. Re: passing frame names to a Goto command
              ricklecoat Level 1
              Hmm, I think I must have a problem with my variable expression, because it's not evaluating like I thought it would. Here's the test I set up to check what String I was getting:

              When the user clicks a button, it assigns the button's name to the variable 'buttonChoice' as a string value such as "testbutton_mc". This value is then passed to the 2nd variable, currentButton, which should strip off the '_mc' and add an 'On'; I should end up with a buttonChoice having a value of "testbutton_mc" and currentButton having a value of "testbuttonOn".

              When written out to a pair of dynamic text fields, however, buttonChoice shows correctly but currentButton shows as NaNOn.
              My code is below: can anyone tell me what I'm doing wrong (I assume that it's the expression that I have wrong)?

              Thanks.

              • 4. Re: passing frame names to a Goto command
                kglad Adobe Community Professional & MVP
                there's no string subtraction using the minus sign in actionscript. you must use the string methods to remove characters from a string.
                • 5. Re: passing frame names to a Goto command
                  ricklecoat Level 1
                  Hmm, I think I must have a problem with my variable expression, because it's not evaluating like I thought it would. Here's the test I set up to check what String I was getting:

                  When the user clicks a button, it assigns the button's name to the variable 'buttonChoice' as a string value such as "testbutton_mc". This value is then passed to the 2nd variable, currentButton, which should strip off the '_mc' and add an 'On'; I should end up with a buttonChoice having a value of "testbutton_mc" and currentButton having a value of "testbuttonOn".

                  When written out to a pair of dynamic text fields, however, buttonChoice shows correctly but currentButton shows as NaNOn.
                  My code is below: can anyone tell me what I'm doing wrong (I assume that it's the expression that I have wrong)?

                  Thanks.

                  • 6. Re: passing frame names to a Goto command
                    ricklecoat Level 1
                    Errata:
                    Whoops, in my last post, the intended final values for the variables should be:
                    buttonChoice: "testing_mc"
                    currentButton: "testingOn" (not "testbuttonOn" as previously stated)

                    Thnx
                    • 7. Re: passing frame names to a Goto command
                      kglad Adobe Community Professional & MVP
                      read my previous message.
                      • 8. Re: passing frame names to a Goto command
                        ricklecoat Level 1
                        Ugh sorry about the double post; this forum is incredibly slow for me for some reason and frequently times out on fetching a page or processing a reply. The double post was a product of one of those glitches.

                        Kglad: no minus? well, that would explain it then! Methods, however, are not something I've learned about yet (only been doing this AS stuff for a week) so I guess I'll have to crack the books again (I've got 4 off the things permanently open around my desk!).

                        If you have any tips that might give me a leg-up on Methods, then do share!
                        Thanks for the subtraction tip off, anyway.

                        Rick
                        • 9. Re: passing frame names to a Goto command
                          kglad Adobe Community Professional & MVP
                          check: help/actionscript 2.0 language reference/actionscript classes/strings

                          currentButton=buttonChoice.substring(0,buttonChoice.indexOf("_mc"))+"On";