Skip to main content
Inspiring
March 9, 2011
Answered

Help urgently needed...about buttons!

  • March 9, 2011
  • 1 reply
  • 1172 views

Hey guys!

Was wondering if someone could help me out here.

I have a selection of buttons that once clicked will play an animation. You can see what I mean by visiting my link below!

http://robshaw.me/test/UB/AS3-535-3.html

I only want one button to raise at a time and when you click another button the one that has already raised animates back down and the new button clicked raises up.

I have been told that I only need three functions.

Could anyone please please please tell me how to go about this?

Thankyou so much in advance!

_Rob

This topic has been closed for replies.
Correct answer Ned Murphy

Cheers Ned!!!

I am almost there I can taste it!!!

now...

Would I create the boolean var in the stage and set it as false (as no animation is occuring)

make it listen for a mouse click

set it to true

then removeEventListener(of all buttons)?

sorry about this but if you could help me with this last bit I can offer you 6 hours of my animating services should you ever need it!


Nope, no need to juggle listeners...

var selectedMC:MovieClip = null;

var allowPlay:Boolean = true;

function sharedPlay(evt:MouseEvent):void {

     if(allowPlay){

         allowPlay = false;

         if(selectedMC != null){ // deal with previous selected mc

              selectedMC.play();

         }

         selectedMC = MovieClip(evt.currentTarget.parent);  // process current
         selectedMC.play();

     }
}

and in your movieclips in the animation stop frame you can use something like...

MovieClip(parent).allowPlay = true;

1 reply

Ned Murphy
Legend
March 9, 2011

You'll need to show the code you currently have and explain how the animated objects are designed.

RobulonZAuthor
Inspiring
March 9, 2011

Thanks for the reply, I will offer a few hours animation in flash for the person that can help me ( I am an animator at heart that got caught up in some actionscript..fail I know...!)

Ok so here is my actionscript

its listening for the buttons to be pressed then animates the movie clip.

How the movie clip works

The buttons are contained within the movieclip.

When pressed they will play 35 frames and be stopped by a stop(); command

at the moment you click it again and it will play the rest of the timeline which is just the button animating down and will loop to the begining ready to animate again.

I think i need to set a unique value as true when one is selected and then use if statements to decide what to do if one button is up

stop();
function aniDevelopingFunction(evt:MouseEvent):void {   
aniDevelop.play();
}
aniDevelop.developing_btn.addEventListener(MouseEvent.CLICK, aniDevelopingFunction)

function aniTeamworkFunction(evt:MouseEvent):void {   
aniTeamwork.play();
}
aniTeamwork.teamwork_btn.addEventListener(MouseEvent.CLICK, aniTeamworkFunction)

function aniInterpersonalFunction(evt:MouseEvent):void {   
aniInterpersonal.play();
}
aniInterpersonal.interpersonal_btn.addEventListener(MouseEvent.CLICK, aniInterpersonalFunction)

function aniManagingFunction(evt:MouseEvent):void {   
aniManaging.play();
}
aniManaging.managing_btn.addEventListener(MouseEvent.CLICK, aniManagingFunction)

function aniResilienceFunction(evt:MouseEvent):void {   
aniResilience.play();
}
aniResilience.resilience_btn.addEventListener(MouseEvent.CLICK, aniResilienceFunction)

function aniChangeFunction(evt:MouseEvent):void {   
aniChange.play();
}
aniChange.change_btn.addEventListener(MouseEvent.CLICK, aniChangeFunction)

function aniDriveFunction(evt:MouseEvent):void {   
aniDrive.play();
}
aniDrive.drive_btn.addEventListener(MouseEvent.CLICK, aniDriveFunction)

function aniOwnershipFunction(evt:MouseEvent):void {   
aniOwnership.play();
}
aniOwnership.ownership_btn.addEventListener(MouseEvent.CLICK, aniOwnershipFunction)

function aniMakingFunction(evt:MouseEvent):void {   
aniMaking.play();
}
aniMaking.making_btn.addEventListener(MouseEvent.CLICK, aniMakingFunction)

function aniInsightFunction(evt:MouseEvent):void {   
aniInsight.play();
}
aniInsight.insight_btn.addEventListener(MouseEvent.CLICK, aniInsightFunction)

function aniCustomerFunction(evt:MouseEvent):void {   
aniCustomer.play();
}
aniCustomer.customer_btn.addEventListener(MouseEvent.CLICK, aniCustomerFunction)

function aniBusinessFunction(evt:MouseEvent):void {   
aniBusiness.play();
}
aniBusiness.business_btn.addEventListener(MouseEvent.CLICK, aniBusinessFunction)

function aniGettingRightFunction(evt:MouseEvent):void {   
aniGettingRight.play();
}
aniGettingRight.gettingRight_btn.addEventListener(MouseEvent.CLICK, aniGettingRightFunction)

function aniWorkingTogetherFunction(evt:MouseEvent):void {   
aniWorkingTogether.play();
}
aniWorkingTogether.working_btn.addEventListener(MouseEvent.CLICK, aniWorkingTogetherFunction)

function aniGettingDoneFunction(evt:MouseEvent):void {   
aniGettingDone.play();
}
aniGettingDone.gettingIt_btn.addEventListener(MouseEvent.CLICK, aniGettingDoneFunction)

Any help would be greatly appreciated! And I will hold true to my offer if anyone can help!

Ned Murphy
Legend
March 9, 2011

While you would still need to have all the listeners assigned, the event handler functions could be combined into one function.  For all of it you can probably get away with just one function.  You would need to store the identity of the currently selected mc so that you can tell it to close when the next is selected.

var selectedMC:MovieClip = null;

function sharedPlay(evt:MouseEvent):void {

     if(selectedMC != null){ // deal with previous selected mc

          selectedMC.play();

     } 

     selectedMC = MovieClip(evt.currentTarget.parent);  // process current
     selectedMC.play();
}

aniMaking.making_btn.addEventListener(MouseEvent.CLICK, sharedPlay);

aniInsight.insight_btn.addEventListener(MouseEvent.CLICK, sharedPlay);

etc...

Note, you will probably run into issues when you make another selection while one is already animating.  To get around this you should consider using gotoAndPlay() commands and have labels in your mc's that you can target with them.