AS3 Button states

Posted on 2009-05-10
Last Modified: 2013-11-11
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(;
  colorTransform.color = 0xFF0000;
  DisplayObject( = colorTransform;

Open in new window

Question by:msukow
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 39

Expert Comment

ID: 24361871
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.

Author Comment

ID: 24363370
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.
LVL 39

Expert Comment

ID: 24373019
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.
LVL 22

Expert Comment

ID: 24415174

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
LVL 22

Accepted Solution

rascalpants earned 500 total points
ID: 24415215

forgot to add the code...

I assume your syntax is correct...

rp / ZA

var buttonsArray:Array = new Array( btn1, btn2, btn2, btn4);
public function navRelease(evt:MouseEvent):void
  var colorTransform1:ColorTransform = DisplayObject(;
  colorTransform1.color = 0x0000FF; // blue
  for(var i:int = 0; i < buttonsArray.length, i++)
    DisplayObject( buttonsArray[i] ).transform.colorTransform = colorTransform1;
  var colorTransform2:ColorTransform = DisplayObject(;
  colorTransform2.color = 0xFF0000;  // red
  DisplayObject( = colorTransform2;

Open in new window


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Action Script commands 4 332
blocked plugin flash 5 127
bandwidth 5 87
Could you point a workaround on how to open this Adobe Flash documents? 5 218
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question