Skip to main content
Inspiring
March 16, 2012
Answered

One Click Two Buttons

  • March 16, 2012
  • 3 replies
  • 3110 views

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

This topic has been closed for replies.
Correct answer kglad

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

mc.btn1.onRelease()

to trigger that handler.

3 replies

Inspiring
March 18, 2012

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.

kglad
Community Expert
Community Expert
March 18, 2012

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));

}

}

Inspiring
March 19, 2012

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.

Inspiring
March 17, 2012

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

kglad
Community Expert
Community Expert
March 17, 2012

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

}

}

Inspiring
March 17, 2012

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.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 16, 2012

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

mc.btn1.onRelease()

to trigger that handler.

Inspiring
March 16, 2012

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.

kglad
Community Expert
Community Expert
March 16, 2012

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.)