Link to home
Start Free TrialLog in
Avatar of msukow
msukowFlag for United States of America

asked on

AS3 Button states

I have a site that has multiple buttons. In AS2, I program the movieClips for the Up, Over, Down and Hit states. Whena user clicks on a "button", then I used gotoAndStop to a seperate timeline frame in which I show that "button" in its Over state.

I know want to do the same thing in AS3. I have code below that allows me to change the color as needed. However, when I click on a new button, the new button changes color correctly, but the previously clicked button still shows the Over state, instead of the Up state.

Do I need to add a loop to go through the button states and change them all back to the Up state, or is there an "addListener" function I should use to change the button state back?
public function navRelease(evt:MouseEvent):void {
  var colorTransform:ColorTransform = DisplayObject(evt.target).transform.colorTransform;
  colorTransform.color = 0xFF0000;
  DisplayObject(evt.target).transform.colorTransform = colorTransform;
}

Open in new window

Avatar of blue-genie
blue-genie
Flag of South Africa image

you'll need to use listeners to check for the different mouse states ie over out etc to go to the correct state for each of the buttons.
Avatar of msukow

ASKER

I had used listeners for the different states. However, when I click on a mvoieclip button, I want the state of that to be "On".

I had change the clicked state to be "On", but was unable to turn it off when I clicked on another button. Instead, all buttons stayed in the "On" state.
can you provide the code you're using.
if you have listeners on the buttons that says if the mouse is not over me go to the off state and the mouse is on another button it should do that.
Avatar of rascalpants

you would need to have some code that turns the state of all buttons to the "off" state first with a for/loop, and then turn the button that needs the "on" state to on.


rp / ZA
ASKER CERTIFIED SOLUTION
Avatar of rascalpants
rascalpants
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial