6 Replies Latest reply: Oct 15, 2010 1:25 PM by C-Rock RSS

    if statement

    Smitch1581 MeganK

      Hi all,

      I'm trying to run an "if" statement on a TLF text field.

      I have several TLF text field that the user enters a number in.

      The example,

      The TLF Text Field has an instance name of "sq"

      When the user enters 1 in the TLF Text field called sq, I want it to run a function. I 4t this was easy but am struggling!

       

      If (condition){           // i 4t i could right something like (sq == 1) or (sq.text == 1)

      gotoAndStop(2);

      }

       

      i've tried lots of variety buts no joy!

       

      i'm really stuck, 4t i was getting the hang off this but obviously not yet! ;(

        • 1. Re: if statement
          C-Rock Community Member

          I would say the when the user enters the field, in other words the field has focus, I would start a timer.

          That timer would check the field each half second or so for changes and then update what you need it to update. Then when the user leave

          s the field and it loses focus kill the timer and listeners.

           

          Help?

          • 2. Re: if statement
            Smitch1581 MeganK

            Hi

            Thanx for the quick reply.

            I'm trying to get it so when the user enters the Number 1 inside the sq TLF text field it goes to and stops on frame 2.

             

            How can i control the condition statement within the parenthesis so that the sq text field is equal to 1?!

            I hope thats a bit clearer?

             

            thanx for your help so far

            • 3. Re: if statement
              C-Rock Community Member

              You're probably comparing the string as text instead of a number. Remember all textfields contain strings so if you want them to be numbers you

              have to convert them.

               

              sq textfield contains the number 1 then the comparison looks like this

               

              var sq_contents:Number = Number(sq.text);

               

              if(sq_contents == 1){

                   // code here

              }

              • 4. Re: if statement
                Smitch1581 MeganK

                Hi thanx fot taht, think could be getting there.

                 

                Is that what Flash calls casting?

                I entered the code and it works if the text field has already has 1 typed in (i inputed 1 before i tested the movie), however, if the textfield is blank and i enter 1 in the exported swf nothing happens.!

                 

                Am i missing one last thing?

                • 5. Re: if statement
                  Smitch1581 MeganK

                  Thank you, with your help i have just cracked it the code you submitted was

                  perfect, ignor the last post, my end goal was not that when the user enters 1 it goes to frame 2, i wanted the user to fill in the entire fields and then press a button, if they entered the correct number in all fields it would move to frame 2 so i wrapped the if statement in the button function and it worked  treat.

                   

                  Thank you very much again :-)

                  • 6. Re: if statement
                    C-Rock Community Member

                    You're welcome.