31 Replies Latest reply on Mar 22, 2012 1:12 PM by kglad

    One Click Two Buttons

    BinaryBloke

      Hi.

       

      I have a puzzle which I cannot appear to fix.

       

      I have a button on the stage which works fine and performs various actions.

       

      I have a movie clip on the stage, that contains 10 different buttons which when you click advances you to the next button and does different things and so on and so on. Again independantly this movie clip with buttons works fine.

       

      What I want to do however is this...

       

      I want to click on the main button on the stage, have that 'click' replicated to the other button within the movieclip so I can action both with a single clip.

       

      Any ideas please?

       

      Thanks

        • 1. Re: One Click Two Buttons
          kglad Adobe Community Professional & MVP

          if you have an object (eg, mc.btn1) with an onRelease handler defined, you can use;

           

          mc.btn1.onRelease()

           

          to trigger that handler.

          • 2. Re: One Click Two Buttons
            BinaryBloke Level 1

            Hi Thanks for this. Could you explain in more detail please.

             

            Im not sure how to set this up.

             

            I have.

             

            Button 1 (button) - Actions on click doing a countdown of number sequence from 100 to 0.

             

            MovieClip - with 10 buttons inside. stop code at frame 1. 1 click advances the movie clip to the next flag, two clicks to flag 2 and so on. If the buttons in the movie clip are not not pressed for 1 second then the clip returns and stops at frame 1 again.

             

            I need the onRelease to be actioned from button 1 to simulate a click on the movieclip which starts it playing, then with each release advances the clip as if you were actually clicking on the movie clip with the 10 buttons.

             

            Hope this makes sence. Happy to send an example fla.

            • 3. Re: One Click Two Buttons
              kglad Adobe Community Professional & MVP

              what's the instance name of Button 1 and what's the instance name of your movieclip with 10 buttons and what is the name of one of those 10 buttons? 

               

              (i need 3 instance names.)

              • 4. Re: One Click Two Buttons
                BinaryBloke Level 1

                Hi. Thanks.

                 

                Button1 has an instance name of MyButton1

                 

                The Movie Clip with the buttons in has an instance name of mc10

                 

                The 10 buttons in that movie clip have instance names starting at multi1 and go upto multi10

                • 5. Re: One Click Two Buttons
                  kglad Adobe Community Professional & MVP

                  use:

                   

                  MyButton1.onRelease=function(){

                  for(var i:Number=1;i<=10;i++){

                  mc10["multi"+i].onRelease();  // if you defined onPress handlers for your 10 buttons, use onPress here.  if you added code directly to your 10 buttons, remove that code and use onRelease

                  }

                  }

                  • 6. Re: One Click Two Buttons
                    BinaryBloke Level 1

                    Hi. I still cant seem to get this to work.

                     

                    I added your code to button 1

                     

                    In the mc10 movie clip I had this code on each button

                     

                    on (press) {

                    gotoAndPlay("play2");

                    }

                     

                    Which increased "playx" by 1 each time advancing to the flag "play10"

                     

                    I removed that code from the buttons but it did nothing when pressing button1

                     

                    Please can you offer further assistance.

                    • 7. Re: One Click Two Buttons
                      kglad Adobe Community Professional & MVP

                      each of your 10 buttons executes the same gotoAndPlay("play2")??

                       

                      or multi2 had that code and multi3 executed gotoAndPlay("play3") etc?

                      • 8. Re: One Click Two Buttons
                        BinaryBloke Level 1

                        each of the 10 buttons advances you to the next flag. goto and play 2 then 3 etc until 10.

                        What I am trying to do here is simulate a multi click. so if you click once and then again within a second you are advanced to the second flag and you get a load of different action in that time slot. Click again and you advance to flag 3 etc.

                        • 9. Re: One Click Two Buttons
                          kglad Adobe Community Professional & MVP

                          then on MyButton1's timeline where multi1,multi2,...,multi10 exist, after removing all code attached to each of those 10 buttons, use:

                           

                          for(var i:Number=1;i<=10;i++){

                          this["multi++i].onRelease=function(){

                          gotoAndPlay("play"+i);

                          }

                          }

                           

                          ////////// then attached to your timeline that contains MyButton1, use the following.  you can change clickFrequency and you should call clickSimulationF() when you want to start your sequential click simulation:

                          // frequency of multi1,multi2, etc click click simulation, in ms

                          var clickFrequency:Number=1000;

                          var clickTO:Number;

                           

                          function clickSimulationF():Void{

                          clickF(1);

                          }

                          function clickF(i:Number):Void{

                          MyButton1["multi"+i].onRelease();

                          if(i<10){

                          clearTimeout(clickTO);

                          clickTO=setTimeout(clickF,clickFrequency,(i+1));

                          }

                          }

                          • 10. Re: One Click Two Buttons
                            BinaryBloke Level 1

                            Hi.

                             

                            I am still struggling with this. I have removed all the other code for testing and just tried to put the code below on the myButton1 timeline on frame 1 of the scene:

                            for(var i:Number=1;i<=10;i++){

                            this["multi++i].onRelease=function(){

                            gotoAndPlay("play"+i);

                            }

                            }

                             

                            But I get the following compile errors

                            Line 2 String literal was not properly terminated

                            Line 3 ']' expected

                            Line 5 unexpected '}' encountered

                             

                            Just to confirm the setup now I have stripped back for testing.

                             

                            I have in the scene.

                             

                            Frame 1 - myButton1 which updates dynamic text box with counter (tried to put code above here on this frame) - but got the above error

                             

                            Frame one  - another layer  - mc10 movie clip with the 10 buttons inside (I have removed goto and play ... code on the all the buttons).

                             

                            Please can you advise further.

                            • 11. Re: One Click Two Buttons
                              kglad Adobe Community Professional & MVP

                              there's a typo.  use:

                               

                              for(var i:Number=1;i<=10;i++){

                              this["multi"+i].onRelease=function(){

                              gotoAndPlay("play"+i);

                              }

                              }

                              • 12. Re: One Click Two Buttons
                                BinaryBloke Level 1

                                Thanks. I am still having trouble getting this to work. Can I please confirm where I should be placing the code.

                                 

                                In the scene. All layers are on a single frame.

                                 

                                Frame 1 - 1st layer contains myButton1 (this is a component button) which currently updates a dynamic text box with a counter. On the frame with the button I applied the code:

                                 

                                for(var i:Number=1;i<=10;i++){

                                this["multi"+i].onRelease=function(){

                                gotoAndPlay("play"+i);

                                }

                                }

                                 

                                Frame 1  - 2nd layer  contains the mc10 movie clip with the 10 buttons inside - (I have removed goto and play code on the all the buttons inside this movie clip). On the frame with the movie clip on I applied the code starting with:

                                 

                                var clickFrequency:Number=1000;

                                 

                                etc

                                 

                                Please can you advise further.

                                • 13. Re: One Click Two Buttons
                                  kglad Adobe Community Professional & MVP

                                  if mc10 contains your 10 multi buttons, on the timeline that contains mc10, use:

                                   

                                  for(var i:Number=1;i<=10;i++){  // when mc10 and the buttons within it are defined.

                                  mc10["multi"+i].onRelease=function(){

                                  gotoAndPlay("play"+i);

                                  }

                                  }

                                  • 14. Re: One Click Two Buttons
                                    BinaryBloke Level 1

                                    Hi.

                                     

                                    I have added that code to the frame on the timeline that holds mc10, but it still does not appear to work. I left the prevous code var clickFrequency:Number1000; etc as it is.

                                     

                                    Would it be possible to send you the .fla so you can show me where I am going wrong please.

                                    • 15. Re: One Click Two Buttons
                                      kglad Adobe Community Professional & MVP

                                      i don't download and correct files unless hired.  this should be solvable on this forum free of charge.

                                       

                                      copy and paste the trace out using:

                                       

                                      for(var i:Number=1;i<=10;i++){  // when mc10 and the buttons within it are defined.

                                      trace(mc10["multi"+i]);

                                      mc10["multi"+i].ivar=i;  // add this line, too and retest

                                      mc10["multi"+i].onRelease=function(){

                                      gotoAndPlay("play"+this.ivar);

                                      }

                                      }

                                      • 16. Re: One Click Two Buttons
                                        BinaryBloke Level 1

                                        Hi.

                                         

                                        Is this what you are looking for? I tested the movie and copied the output.

                                         

                                        Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.

                                        _level0.mc10.multi1

                                        undefined

                                        undefined

                                        undefined

                                        undefined

                                        undefined

                                        undefined

                                        undefined

                                        undefined

                                        undefined

                                        • 17. Re: One Click Two Buttons
                                          kglad Adobe Community Professional & MVP

                                          _level0.mc10.multi1

                                          undefined

                                          undefined

                                          undefined

                                          undefined

                                          undefined

                                          undefined

                                          undefined

                                          undefined

                                          undefined

                                           

                                          means you do NOT have buttons named multi2,...,multi10 in mc10 when that code executes.  you need to fix that.  code referencing a non-existant object isn't going to work.

                                          • 18. Re: One Click Two Buttons
                                            BinaryBloke Level 1

                                            Hi. In that case not sure what's wrong.

                                             

                                            In mc10 I have a layer called 'Button'. This contains 10 keyframe separated instances of a button called 'multihop' over 250 frames. On key frame 1 I click on the button and have entered 'multi1' in the instance name under the properties tab. At keyframe 25 I click on the button and have 'multi2' in the instance name under the properties tab. This is the same increase in number / frames up to multi10 at frame 225. Am I putting the button name in the wrong place?

                                             

                                            Thanks.

                                            • 19. Re: One Click Two Buttons
                                              kglad Adobe Community Professional & MVP

                                              again, you do NOT have buttons named multi2,...,multi10 in mc10 when that code executes.

                                               

                                              you explained in your last message why that is happening.  your buttons are not all defined until frame 250 or so when multi10 is finally defined.  in fact, only multi1 is defined when that code executes.

                                              1 person found this helpful
                                              • 20. Re: One Click Two Buttons
                                                BinaryBloke Level 1

                                                Sorry. I do not understand what you mean.

                                                 

                                                I can send a screen shot if you like.

                                                 

                                                Here is what is in mc10 by frame number.

                                                 

                                                mc10 - layer - 'Button'

                                                 

                                                On

                                                 

                                                Frame 1 - keyframe - instance of multihop button - Instance name - multi1

                                                Frame 25 - keyframe - instance of multihop button - instance name - multi2

                                                Frame 50 - keyframe - instance of multihop button - instance name - multi3

                                                Frame 75 - keyframe - instance of multihop button - instance name - multi4

                                                Frame 100 - keyframe - instance of multihop button - instance name - multi5

                                                Frame 125 - keyframe - instance of multihop button - instance name - multi6

                                                Frame 150 - keyframe - instance of multihop button - instance name - multi7

                                                Frame 175 - keyframe - instance of multihop button - instance name - multi8

                                                Frame 200 - keyframe - instance of multihop button - instance name - multi9

                                                Frame 225 - keyframe - instance of multihop button - instance name  - multi10

                                                 

                                                • 21. Re: One Click Two Buttons
                                                  kglad Adobe Community Professional & MVP

                                                  i understand.

                                                   

                                                  does frame 25 in mc10 play before the code i suggested executes?  ans:  no.  so multi2 doesn't exist when the code i suggested executes.

                                                   

                                                  put all 10 buttons on frame 1 of mc10.  use their visible property to fix your display so only the button(s) you want to display on a frame are visible.

                                                  • 22. Re: One Click Two Buttons
                                                    BinaryBloke Level 1

                                                    Hi.

                                                     

                                                    I am hoping this is some progress. Here is the output now all the buttons are on the first frame.

                                                     

                                                    _level0.mc10.multi1

                                                    _level0.mc10.multi2

                                                    _level0.mc10.multi3

                                                    _level0.mc10.multi4

                                                    _level0.mc10.multi5

                                                    _level0.mc10.multi6

                                                    _level0.mc10.multi7

                                                    _level0.mc10.multi8

                                                    _level0.mc10.multi9

                                                    _level0.mc10.multi10

                                                     

                                                    So what do I need to do now please and how do I action an event on the mutiple clicks. Also where do I now trigger the other events (movie clips that play for each button click) - do I do this on each buttons hit keyframe?

                                                     

                                                    Thanks.

                                                    • 23. Re: One Click Two Buttons
                                                      kglad Adobe Community Professional & MVP

                                                      that is progress.  now, attached to your main timeline where you have that trace() statement, replace that code with:

                                                       

                                                      for(var i:Number=1;i<=10;i++){

                                                      mc10["multi++i].ivar=i;

                                                      mc10["multi++i].onRelease=function(){

                                                      gotoAndPlay("play"+this.ivar);

                                                      }

                                                      }

                                                       

                                                      ////////// then attached to your timeline that contains MyButton1, use the following.  you can change clickFrequency and you should call clickSimulationF() when you want to start your sequential click simulation:

                                                      // frequency of multi1,multi2, etc click click simulation, in ms

                                                      var clickFrequency:Number=1000;

                                                      var clickTO:Number;

                                                       

                                                      MyButton1.onRelease=clickSimulationF;

                                                       

                                                      function clickSimulationF():Void{

                                                      clickF(1);

                                                      }

                                                      function clickF(i:Number):Void{

                                                      mc10["multi"+i].onRelease();

                                                      if(i<10){

                                                      clearTimeout(clickTO);

                                                      clickTO=setTimeout(clickF,clickFrequency,(i+1));

                                                      }

                                                      }

                                                      • 24. Re: One Click Two Buttons
                                                        BinaryBloke Level 1

                                                        I'm getting errors on this part:

                                                         

                                                        for(var i:Number=1;i<=10;i++){

                                                        mc10["multi++i].ivar=i;

                                                        mc10["multi++i].onRelease=function(){

                                                        gotoAndPlay("play"+this.ivar);

                                                        }

                                                        }

                                                         

                                                        Line 3 - String literal not properly terminated

                                                        Line 5 ] expected

                                                        Line 7 ] expected

                                                        Line 11 Unexpected }

                                                        • 25. Re: One Click Two Buttons
                                                          kglad Adobe Community Professional & MVP

                                                          use:

                                                           

                                                           

                                                           

                                                          for(var i:Number=1;i<=10;i++){

                                                          mc10["multi"+i].ivar=i;

                                                          mc10["multi"+i].onRelease=function(){

                                                          gotoAndPlay("play"+this.ivar);

                                                          }

                                                          }

                                                           

                                                          ////////// then attached to your timeline that contains MyButton1, use the following.  you can change clickFrequency and you should call clickSimulationF() when you want to start your sequential click simulation:

                                                          // frequency of multi1,multi2, etc click click simulation, in ms

                                                          var clickFrequency:Number=1000;

                                                          var clickTO:Number;

                                                           

                                                          MyButton1.onRelease=clickSimulationF;

                                                           

                                                          function clickSimulationF():Void{

                                                          clickF(1);

                                                          }

                                                          function clickF(i:Number):Void{

                                                          mc10["multi"+i].onRelease();

                                                          if(i<10){

                                                          clearTimeout(clickTO);

                                                          clickTO=setTimeout(clickF,clickFrequency,(i+1));

                                                          }

                                                          }

                                                          1 person found this helpful
                                                          • 26. Re: One Click Two Buttons
                                                            BinaryBloke Level 1

                                                            Ok great thanks. I have no compile errors now.

                                                             

                                                            So going forward. I assume now (not sure how to tell) that when you click myButton1 depending on how many clicks you do up to 10 clicks within a second of each other it will advance you to the relevant multi(1-10) buttons, and if you leave it longer than a second it resets the sequence back to a single click to start with multi1 again.

                                                             

                                                            My next question is where do I fire off the event that play the 10 movie clips (one for each of the multi1 to multi10 buttons).

                                                             

                                                            Thanks

                                                            • 27. Re: One Click Two Buttons
                                                              kglad Adobe Community Professional & MVP

                                                              when you click MyButton1 each of your 10 multi button's should execute their onRelease functions 1000 milliseconds apart.  do they?  do your multi buttons work as expected?

                                                              • 28. Re: One Click Two Buttons
                                                                BinaryBloke Level 1

                                                                No.

                                                                 

                                                                The buttons do nothing (im not sure if they are set-up correctly to do anything).

                                                                 

                                                                Each button in mc10 was previously setup to play a frame in a movie clip click eg:

                                                                 

                                                                on (press) {

                                                                Object(this._parent).mc11.gotoAndPlay(Yes_2);

                                                                }

                                                                 

                                                                When I multi click myButton1 it does not appear to effect the buttons in mc10 and in doing so does not advance the other movie clip mc11 to the next flag with each click.

                                                                 

                                                                Please advise. Thanks.

                                                                • 29. Re: One Click Two Buttons
                                                                  kglad Adobe Community Professional & MVP

                                                                  what did your message 6 then?

                                                                  • 30. Re: One Click Two Buttons
                                                                    BinaryBloke Level 1

                                                                    This was a 250 frame movie clip with simple stop frames and code to move it on if it was pressed again within 25 frames (1 sec). If it was not pressed then it would go back to frame 1

                                                                     

                                                                    So frame one (stop)

                                                                    Frame 2-24 play another movie clip in mc11 and if pressed again advance frame 26

                                                                    Frame 25 stop and If not pressed return to frame 1

                                                                    Frame 26-49 play another movie clip mc11 and if pressed again advance frame 51

                                                                    Frame 50 stop and If not pressed return to frame 1

                                                                     

                                                                    and so on

                                                                     

                                                                    I have tried to replicate this by using on on press for each of the buttons in mc10 on frame 1 using a similar principle 

                                                                     

                                                                    eg:

                                                                     

                                                                    on (press) {

                                                                    Object(this._parent).mc11.gotoAndPlay(Yes_2);

                                                                    }

                                                                     

                                                                    and

                                                                     

                                                                    on (press) {

                                                                    Object(this._parent).mc11.gotoAndPlay(Yes_3);

                                                                    }

                                                                     

                                                                    and so on for each button but I am guessing this does not work because there is no press to action it.

                                                                    • 31. Re: One Click Two Buttons
                                                                      kglad Adobe Community Professional & MVP

                                                                      i don't know what you're doing, any more. 

                                                                       

                                                                      i solved the problem using the information you supplied.  now, you're supplying additional, that appears to be contradict previous information.

                                                                       

                                                                      i think someone will need to download and correct your file to see what you're doing.   at least some of your explanation of what you're doing isn't correct.