7 Replies Latest reply on Jun 22, 2007 8:17 AM by Twitchr

    Should be simple?

    Twitchr
      Hey everyone. This has probably been asked before, but I thought it may be quicker to ask again.
      I'm new to actionscript, but not new to programming. I'm trying something which should be simple, but getting nowhere in Flash. What I'm trying to do is when a button on frame 2 is pressed, check the contents of an input field named "enterTeamTwo" on frame one and depending upon what text is in that field, either gotoAndStop(2) or gotoAndStop(3).

      My instinct was to put the following code in the next button on frame 2, but it does not do what I expect it to do:

      if (enterTeamTwo.text = "Team 2"){
      gotoAndStop(2);
      }else{
      gotoAndStop(3);
      ]

      I've tried many variations of this and sometimes instead of getting the contents it puts the text I'm looking for into that input field.

      Thanks in advance for your help. I'm loving what I'm seeing of Flash, but getting used to actionscript and getting rid of habits from other languages is frustrating...ha ha.

      -Twitch
        • 1. Re: Should be simple?
          kglad Adobe Community Professional & MVP
          use double equal (==) to test for equality. and if that code is in frame two, instead of gotoAndStop(2), use stop().
          • 2. Should be simple?
            Twitchr Level 1
            Really appreciate the quick reply, kglad. Unfortunately, it's still not working. It stays on frame 2 no matter what text is in the "enterTeamTwo" input field.

            Here is all the code for the button:
            on (release) {
            teamOneScore = teamOnePoints - - teamOneScore
            if (enterTeamTwo.text == "Team 2"){
            gotoAndStop(3);
            }else{
            stop()
            }
            }

            The first line of code is simply adding two text fields together. The name of the input field "enterTeamTwo" is in the "Var:" section of the input fields properties. That's where is should be, correct?

            Sorry for taking up your time with such a lame question, but it's driving me batty.

            -Twitch
            • 3. Re: Should be simple?
              BSpero Level 1
              If the text field instance does not exist on the frame you are on, then this could cause a problem as well. You could drop that text into a variable, or move the text field to off stage in frame 2.
              • 4. Re: Should be simple?
                kglad Adobe Community Professional & MVP
                use trace(enterTeamTwo.text) in frame 2 to pinpoint the problem, if bspero's suggestion hasn't resolved this issue.
                • 5. Re: Should be simple?
                  Twitchr Level 1
                  Once again, thanks for the quick response guys.

                  I did- trace(enterTeamTwo.text) and got "undefined" in the Output panel. Does that mean the path is incorrect?

                  -Twitch
                  • 6. Re: Should be simple?
                    kglad Adobe Community Professional & MVP
                    it could be an incorrect path/filename, but it also could mean bspero was correct: your textfield doesn't exist on the frame that contains your code.

                    in frame 1, use trace(enterTeamTwo). if that returns your textfield, your path/instance name is correct. if it returns undefined, your path/instance name is incorrect.
                    • 7. Should be simple?
                      Twitchr Level 1
                      Can't thank you guys enough. Debugging with trace helped out a lot. I took ".text" out of (enterTeamTwo.text == "Team 2") and that did the trick. I knew it was something minor....ha ha.

                      I'm a Flash beginner so it will be hard to return the favor, but I am a Mac technician so if you ever have any issues with your Mac (if you're on one) I'd be glad to help.

                      -Twitch