7 Replies Latest reply on Dec 11, 2014 1:33 PM by smenegassi

    if button clicked

    smenegassi Level 1

      I'll reformulate my question...

       

      I have two instances of the same button in two differents Symbols (say...  movieclips).  I want to bind distincts actions to each button.

      How do I recognize  witch one was clicked ?

      thanks forever,

        • 1. Re: if button clicked
          resdesign Adobe Community Professional & MVP

          Well, if you have 2 instances, all you need to do is insert each click event on each instance.

          You can give each instance a different name so it is easier to know which one you are addressing.

          • 2. Re: if button clicked
            smenegassi Level 1

            It doesn't work like that because my buttons are inside a Symbol "my_own_audio_player" with a play, pause and stop audio buttons.

            When I put an action on the button inside de "my_own_audio_player_instance1" it will change all over the others instances.

            It is like I have  3 movieclips in my project and on each movieclip I have 2 or 3 "my_own_audio_player" playing differents audio files.

            Sorry to use the movieclip but I really prefer that to Symbols... ;-)

            • 3. Re: if button clicked
              resdesign Adobe Community Professional & MVP

              So, if I understand right, you are using the same symbol and it has actions in it that of course are the same. Another idea would be to duplicate that symbol in the symbol library so that you can change the code inside them since that when you duplicate in the elements panel it is the same instance and therefore the same code.

              • 4. Re: if button clicked
                smenegassi Level 1

                Hi, thank you resdesign,

                 

                But I wanted to try not to duplicate the symbol, to make it a proper code, I guess.

                I wanted to bind actions from outside de symbol. It can work, but I have to know how to recognize which  button was clicked.

                I guess they do have an adress like : symbol1.buttonPlay, symbol2.buttonPlay,symbol3.buttonPlay.

                • 5. Re: if button clicked
                  resdesign Adobe Community Professional & MVP
                  • You could give an id name to your buttons like this:

                  sym.$('symbolNane').attr("id',"newIdName');

                  then use the name with #

                  sym.getSymbol('#newIdName').play();

                   

                  • You could add a class name and use that. 

                  sym.$('symbolNane').addClass('className');

                   

                  Questions - are you creating these symbols dynamically?

                  What version of Animate are you using?

                  • 6. Re: if button clicked
                    resdesign Adobe Community Professional & MVP

                    You could also add a flag.

                    for example:

                     

                    P = 0;

                     

                    sym.$('btn').bind("click", function(){

                       if (P==0){

                       // do something

                       P==1;

                       } else{

                       // do something

                       p==0

                       }

                     

                     

                    });

                    • 7. Re: if button clicked
                      resdesign Adobe Community Professional & MVP

                      Check out this as well:

                      Edit fiddle - JSFiddle

                      • 8. Re: if button clicked
                        smenegassi Level 1

                        hey Thanks resdesign !

                        I think you give me good hints. I'll check them out tomorrow in the afternoon and I let you know.