16 Replies Latest reply on Nov 30, 2013 12:23 PM by Zaxist

    Unbinding and re-binding click action

    pmfr01 Level 2

      Hi.

      I have this totally animated button (symbol), with mouseover, mouseout, "mouseoff" and click states. I've been trying to unbind the click action from it  at 1125ms (almost at the end of the timeline) and then re-binding it again when it returns to 0ms, but with no success. The .unbind occurs only at 1125ms, where the mouseover animates a sort of "deactivated state ("mouseoff")", but when the animation returns to the beginning, the .bind doesn't work. I've also tried the .on/.off and .die/.live methods, so it must be wrong syntax or something...

      So, basically I want to deactivate the button for a moment. Maybe there's a better way for going this?

       

      Here´s my file.

      (the .bind and .unbind methods are commented - triggers 0ms and 1125 ms)

       

      Pedro

        • 1. Re: Unbinding and re-binding click action
          elainecc Adobe Employee

          Hey, Pedro-

           

          Your file isn't linked correctly - I can't see it.  I question why you're unbinding and binding the click action, though; if you're trying to do something different depending on where you are in your animation or some other state, it's easier to save a variable and then use either a large if statement or a switch statement to handle your code instead of messing with bind/unbind.

           

          -Elaine

          • 2. Re: Unbinding and re-binding click action
            pmfr01 Level 2

            the link is a rar file not html.

            Well, It's kind of a petty detail really, but, the general idea is to disable the user to click again after the 1st click and, after the final mouseout, to have the clicking enabled again (it returns to begining of the timeline).

            • 3. Re: Unbinding and re-binding click action
              elainecc Adobe Employee

              Okay, so you could do this with one variable.  Here's how I would handle the same issue:

               

              In the Stage.compositionReady handler, add the following code:

                   sym.setVariable("btnClickable", true); // sets the initial value

               

              In your click handler, add this:

                  // the first time, it will always run.  Afterward, it will disable it and it will never run.

                  var btnClickable = sym.getVariable("btnClickable");

                  if (btnClickable) {

                      sym.setVariable("btnClickable", false);

                      // insert whatever code you want to do when it's clicked

                  }

                 

              And then, finally, in your last mouseout:

                  sym.setVariable("btnClickable", true); // reset the variable to the correct value

                  sym.play(0);

               

              So, just like my previous post on your other question, we're using in-app variables to save some information on where we are in the project.  This is called "saving state," and can be very powerful in combination with some good if statements or switch statements.  You can also save multiple states by saving a string in the variable instead of saving a Boolean variable.

               

              Hope that helps!

               

              -Elaine

              1 person found this helpful
              • 4. Re: Unbinding and re-binding click action
                pmfr01 Level 2

                I'm missing something here... you better have a look at my Edge file. I think it has something to do with the mouseout...

                Meanwhile I've kinda solved the issue by using an if else in the Click action.

                • 5. Re: Unbinding and re-binding click action
                  elainecc Adobe Employee

                  Hey, pmfr01-

                   

                  I'm looking at your file, and I just realized that I don't quite understand what you're trying to accomplish.  But it sounds like you worked out a solution anyway.

                   

                  -Elaine

                  1 person found this helpful
                  • 6. Re: Unbinding and re-binding click action
                    joshuagf82gf Level 1

                    Hello Elaine,

                     

                    following this thread on Edge, I am really interesting on the possibility to make a symbol do NOTHING (disable the clik function) when it's at 0 milliseconds in the timeline.

                     

                    I have very little idea of coding, so i really hope you can help me out with this.

                     

                    On this link http://test-colpen.giorgioalanfranco.com/home-it.html if you click on PENNE it will play the animation, because i've got the following click function for that symbol: sym.play(1750)

                     

                    But I dont' want the animation to play when it's at (0) in the timeline, because you can easily see that doesn't make sense.


                    The same goes for the other symbol.

                     

                    Any help would be highly appreciated.

                     

                    Thx

                    Giorgio

                    • 7. Re: Unbinding and re-binding click action
                      Zaxist Level 4

                      Dear josh

                       

                      it's very Simple you need to use a variable to check

                       

                      Stage > compositioReady

                       

                      button = 1

                      ///////////////////////////////////////////

                      boton1 > click

                       

                      if (button == 1)

                      sym.play(1750)

                      button = 2

                      ///////////////////////////////////////////

                      boton2 > click

                       

                      if (button == 2)

                      sym.play(0)

                      button = 1

                      ///////////////////////////////////////////

                       

                       

                      Zaxist



                       

                       


                      • 8. Re: Unbinding and re-binding click action
                        joshuagf82gf Level 1

                        Thanks for your reply Zaxist!

                         

                        sorry but it's not easy for me at all.

                        Should i just put that code in Stage - compositionReady event? And delete the events I have assigned to the symbols (a click event sym.play)?

                        I tried this and it won't do nothing, clicks do not work, so animation won't start

                         

                        I also tried to keep the my previous events and add the code you provided to  Stage - compositionReady, but no luck.

                         

                        Let me tell you exactly what my starting point was, maybe this can help:

                        each symbol has a "click" event assigned:

                         

                        boton1

                        sym.play(1750)

                        boton1.jpg

                         

                        boton2

                        sym.play(0)

                         

                        boton2.jpg

                         

                        And nothing in the Stage.

                         

                        Thank you for your patience, really appreciate your help

                        best

                        Giorgio

                        • 9. Re: Unbinding and re-binding click action
                          Zaxist Level 4

                          ok i explain a little more

                           

                          A - you just write this code in your Stage in compositionReady part

                           

                          button = 1

                           

                          note : you dont have any code in there right now

                           

                           

                          B - remove every actions you have in boton1 and boton2 symbols

                           

                           

                          C - select boton1 and add click Action and write these codes in there

                           

                          if (button == 1)

                          sym.play(1750)

                          button = 2

                           

                          D - select boton2 and add click Action and write these codes in there

                           

                          if (button == 2)

                          sym.play(0)

                          button = 1

                           

                           

                          Now run your project to see how it works

                           

                          i hope you can make it this time

                           

                          Zaxist

                          1 person found this helpful
                          • 10. Re: Unbinding and re-binding click action
                            joshuagf82gf Level 1

                            Great,

                            we are nearly there!

                             

                            It works just as I need to, but I had to delete the "sym.stop" action at the very beginning of the animation.

                            So as soon as I open it, it plays the first part (as if I clicked the "boton2" button).

                             

                            Because if I use the "sym.stop" action at the beginning in order not to let it play, the boton2 does not even work.

                             

                            Of course I want it NOT to play automatically as I open it, and be able to use the buttons as you taught me.

                             

                            Thank you very much, you are being very helpful, I understand if you decide to just drop this.

                             

                            cheers

                            giorgio

                            • 11. Re: Unbinding and re-binding click action
                              Zaxist Level 4

                              you dont need those sym.stop() actions at beginning to prevent autoplay timeline

                               

                              just go to your symbol that you dont want to play it automatically, select your symbol and uncheck autoplay option from left pannel

                               

                              hope this time you can make it work great

                               

                              Zaxist

                              1 person found this helpful
                              • 12. Re: Unbinding and re-binding click action
                                joshuagf82gf Level 1

                                i've unchecked autoplay option from the symbol (boton2), but no chance, it still plays.

                                 

                                So I tried to uncheck it for the Stage, and boton2 doesn't work.

                                 

                                totally lost

                                • 13. Re: Unbinding and re-binding click action
                                  Zaxist Level 4

                                  i rechecked your Project now

                                   

                                  i saw that your Stage autoplay option is still checked, uncheck it and

                                   

                                  replace your codes in Stage > compositionReady with these codes:

                                   

                                  button = 2

                                  sym.stop(3250)

                                   

                                  save and reupload it, you will see your problem will gone

                                   

                                  Zaxist

                                  • 14. Re: Unbinding and re-binding click action
                                    Zaxist Level 4

                                    did you get success with my codes ?

                                     

                                    Zaxist

                                    • 15. Re: Unbinding and re-binding click action
                                      joshuagf82gf Level 1

                                      awesome!

                                       

                                      (I had unchecked it and checked it back again, cause it didn't work the first).

                                       

                                      Now it works perfectly, with the new code!

                                       

                                      thank you so much, really appreciate all your efforts!

                                       

                                      giorgio

                                      • 16. Re: Unbinding and re-binding click action
                                        Zaxist Level 4

                                        Great !!

                                         

                                        i'm happy to hear that

                                         

                                        Zaxist