hello all,
I have been working on a button class and ran into a little bit of a snag.
Here is the class I created:
package
{
import flash.display.;
import flash.events.;
public class BasicButton extends Sprite
{
private var allButtons:Array;
public var buttonChange:Boolean = true;
public function BasicButton()
{
buttonMode = true;
allButtons = [up_mc,down_mc,over_mc];
hideAllExcept(up_mc);
addEventListener(MouseEvent.MOUSE_DOWN, buttonDown);
addEventListener(MouseEvent.ROLL_OVER, buttonOver);
addEventListener(MouseEvent.ROLL_OUT, buttonOut);
}
// button over function
private function buttonOver(event:MouseEvent):void
{
hideAllExcept(over_mc);
}
//button down function
private function buttonDown(event:MouseEvent):void
{
hideAllExcept(down_mc);
removeEventListener(MouseEvent.ROLL_OUT, buttonOut)
addEventListener(MouseEvent.ROLL_OUT, buttonOut2);
buttonMode = false;
}
// button out function
private function buttonOut(event:MouseEvent):void
{
hideAllExcept(up_mc);
}
// button out when pressed function
private function buttonOut2(event:MouseEvent):void
{
hideAllExcept(down_mc);
}
private function hideAllExcept(except:MovieClip):void
{
for(var i:uint = 0; i < allButtons.length; i++)
{
allButtons*.alpha = (allButtons* == except) ? .80 : 0;
}
}
}
}
Now while this class is working, I can’t seem to figure out how to make it so when you click on one button it makes sure all the other buttons are sent back to the offState. I am using _mc’s for my buttons. I think I need to put my buttons into an array and keep track of them at way, but I’m not sure about how to do that. Would I be able to get this effect to work in this .as file or would i need to write another one to control the buttons and where they are in there states(up/down/over).
Thanks for your help in advance!