javascript button states in html5 canvas
Hello people 🙂
I have 7 buttons on my stage (button1, button2, etc) all MC's. I would like to control the RollOver, RollOut & CLick with js.
At first I thought I could just tell my button Listener where to go
i.e. gotoAndStop(2) which is RollOver state. or gotoAndStop(3) which is Click state. and gotoAndStop(1) which is RollOut state.
But when I "Click" and then rollout, I need the button to stay "clicked" until some other button is "clicked".
i'm trying this but there is something wrong.
// loop through the buttons and give them mouse click listeners
for ( var i:int = 1 ; i <= 7; i++ ){
var curButton:MovieClip = getChildByName ("button"+i);
// set click lisitener
curButton.addEventListener ( MouseEvent.CLICK, buttonClickHandler.bind(this) );
// set rollover listener
curButton.addEventListener ( MouseEvent.ROLLOVER, buttonRollOverHandler.bind(this) );
// set rollout listener
curButton.addEventListener ( MouseEvent.ROLLOUT, buttonRollOutHandler.bind(this) );
// set initial state
curButton.gotoAndStop(1);
}
function resetStates (){
for ( var i = 1; i<=7; i++){
var curButton = getChildByName("button"+i);
curButton.gotoAndStop(1);
}
}
function buttonRollOverHandler ( evt:MouseEvent ){
resetStates();
evt.target.gotoAndStop(2);
}
function buttonRollOutHandler ( evt:MouseEvent ){
resetStates();
}
function buttonClickHandler ( evt:MouseEvent ){
resetStates ();
evt.target.gotoAndStop(3);
}
tnx to all
