5 Replies Latest reply on Oct 29, 2012 5:25 AM by Ned Murphy

    I need IF statment Help Pwease

    Kilik89

      Here is my code:

      on (release) {
          if (nameofvar < 1)
          {
              function nameofTextbox()
              {
                  trace("You already have a nameofvar");
              }
              nameofTextbox();
          }
          else
          {
              nameofvar = nameofvar + 1;
          }
      }
      

       

      Now  I have a Button btw all this code is on the button also there is a Dynamic Textbox above the button I named the Var in properties and added Var nameofvar(); in the frame. 3 questions #1 When I click button nothing happenes No name ofvar added or nothing how change this? #2 how make the textbox invisable until you have 1 nameofvar then if click button again it traces also if leave frame comaback textbox invisable again. #3 If you dont have 1 of nameofvar how make same of differnt textbox say You have found a nameofvar.

        • 1. Re: I need IF statment Help Pwease
          Ned Murphy Adobe Community Professional & MVP

          You should not place code on objects.  Keep all of your code in the timeline.  Give your button an instance name and assign code to it using that name.

           

          You should avoid using the var properties of textfields.  Use a variable that you define in the timeline and assign value to that variable. If you want that value displayed in a textfield, then assign an instance name to the textfield and assign text to it using its text property.

           

          As far as the conditional code you wrote goes, you should not build functions within. The following is all you would need for that button code when placing it in the timeline...

           

          btnName.onRelease = function (){

           

              if (nameofvar < 1)

              {

                      trace(You already have a nameofvar);

              }

              else

              {

                  nameofvar = nameofvar + 1;

              }

          }

          • 2. Re: I need IF statment Help Pwease
            Kilik89 Level 1

            Thank you for the on timeline Explaintion <3 if you dont mind explian differance between keeping it on button and keeping it on timeline

            1 person found this helpful
            • 3. Re: I need IF statment Help Pwease
              Ned Murphy Adobe Community Professional & MVP

              The difference is primarily poor coding practices versus good coding practices.  When you keep all of the code in the timeline, it is much easier to find and to manage - you don't have to click every item to try to find if code is hiding on them.  It also makes it much clearer which objects are being addressed when code is targeting them.

               

              If you ever plan to advance to using the newer versions of Flash and AS3, placing code on objects is not allowed, so getting in the habit now is better.

              1 person found this helpful
              • 4. Re: I need IF statment Help Pwease
                Kilik89 Level 1

                Thank you I now use all code on timeline Thank You so much for your lesson!

                1 person found this helpful
                • 5. Re: I need IF statment Help Pwease
                  Ned Murphy Adobe Community Professional & MVP

                  You're welcome