10 Replies Latest reply on Jun 3, 2013 2:12 PM by zontaluma

    How to make a click event null

    zontaluma Level 1

      All-

       

      I have a button on the main stage with a hit event inside of it.  This hit area calls frame lables on other symbols (these "other symbols" are also on the main stage, not dynamic) .  How do I make the click event of the hit area null if one of these symbols is/are visible?  I added another button to set the visibility to false but then I also need the click event to reset itself to it's original state

       

      hope this make sense

       

      thx

        • 1. Re: How to make a click event null
          resdesign Adobe Community Professional & MVP

          Maybe you could unbind it then rebind it when needed?

           

          For example Below is the code I have  for three buttons and I wanted then to work only in turns.

           

          sym.$("v1").click(function() {

              func(1, 2);   

          });   

          sym.$("v2").click(function() {

              func(2, 3);   

          });

          sym.$("v3").click(function() {

              func(3, 1);   

          });   

           

           

          function func(i, next) {

              var nextnext = ((next+1)%3 == 0) ? 3 : (next+1)%3;

              sym.play("p"+i);

              sym.$("v1").unbind("click");

              sym.$("v2").unbind("click");

              sym.$("v3").unbind("click");

              sym.$("v"+ next).bind("click", function() { func(next, nextnext); });

          }

          • 2. Re: How to make a click event null
            Zaxist Level 4

            you can use if() !!

             

            its very simple just add a variable in the Stage > compositionReady

             

            Flag = 0;

             

            then write in your button click event :

             

            if ( Flag == 0 ){

             

            your click code should be here

             

            }

             

             

            thats it...

            and where ever you made your symbol visible just add this line there

             

            Flag = 1;

             

            and where ever you made your symbol invisible just add this line there

             

            Flag = 0;

             

            in this way you can easily contorl your event click to work or not

             

            Zaxist

            • 3. Re: How to make a click event null
              zontaluma Level 1

              not sure i follow

               

              my button that's on the main stage has a hit area with the following code

               

               

              sym.getComposition().getStage().getSymbol("MC-SYM-INTRO").play("FADE IN");

              sym.getComposition().getStage().getSymbol("MC-WHITE-BG").play("BG");

               

               

              i'm simply calling other symbols when the hit area's clicked.  the button with the hit area is still visible when the symbol is on the stage.   what i'm trying to understand is how to code the hit area to detect when these symbols are on stage and to deactive the click when they are. 

              • 4. Re: How to make a click event null
                zontaluma Level 1

                i guess im not clear on what code to put in the if (Flag ==0) {} statement

                • 5. Re: How to make a click event null
                  Zaxist Level 4

                  this is very simple & easy !!

                   

                  let me explain you more :

                   

                  for example we want to execute this code by click on a button

                   

                  sym.$("mysymbol").show();

                   

                  but we want to deactive the button click after that, simply we can use variables to do that plus if() statement

                   

                  so we write this line in Stage>compositionReady

                   

                  Flag = 0;    // we define a variable named Flag and we set its value to zero

                   

                  now back on the button click, we change or button code to this :

                   

                  if ( Flag == 0){  // in this line we check flag value to see if its value is Zero doing

                                        // below actions

                  sym.$("mysymbol").show(); // we do our action

                  Flag++; // then we increase our Flag Value to One // Now or Flag Value is equal to 1

                  }

                   

                   

                  So next time we click on the button it wouldnt work because it would execute or statement if our Flag have Zero value already, so our Flag doesnt have it so it wont execute !!

                   

                  for example if we add this code in Stage>click

                   

                  Flag = 0;

                   

                  after we click on the stage then now our button is active again, because by clicking on the Stage we changed Flag value from 1 to 0 and if we click on our button again it would execute our code for one more time !! because the Flag have 0 Value now !!

                   

                  it is very simple and easy, if you had any problem let me know, i will help you

                   

                  Zaxist

                  • 6. Re: How to make a click event null
                    zontaluma Level 1

                    R u a cider or lager man? I owe u a drink.  lol  Thank you very much ;-)

                    • 7. Re: How to make a click event null
                      Zaxist Level 4

                      you're welcome...

                       

                      and one more thing

                       

                      if you want to hide your button after click you just need to add this code in your button

                       

                      sym.$("my symbol name that is button now").hide();

                       

                      and if you want just to deactive it use the variable method !!

                       

                      and dont forget to buy me that drink

                       

                      Zaxist

                      • 8. Re: How to make a click event null
                        resdesign Adobe Community Professional & MVP

                        Hey Zaxist

                         

                        This is way easier than using bind and unbind on the buttons. I'll have to remember that!

                        • 9. Re: How to make a click event null
                          Zaxist Level 4

                          i'm sure if you use this method one time, you'll never use bind and unbind method again, cause this variable method is very simple and easy

                          • 10. Re: How to make a click event null
                            zontaluma Level 1

                            Thanks to both of you for the help!  I just made a qunatum leap on my project today.