开发者

Why does the button stay selected?

I'm doing a simple 2 button menu. Each button is a movie clip with 3 labels for the states "none" "selected" and "hover". smartBtn needs to be set to "selected" on enter frame. When cinemaBtn gets clicked, smartBtn should go to its "none" state. But I'm not sure why smartBtn keeps on being selected.

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

var smartBtn = menu_mc.smart_mc;
var cinemaBtn = menu_mc.cinema_mc;

smartBtn.buttonMode = true;
cinemaBtn.buttonMode = true;

this.addEventListener(Event.ENTER_FRAME, EnterFrameHandler);
smartBtn.addEventListener(MouseEvent.CLICK, menuSmartClic开发者_C百科k);
cinemaBtn.addEventListener(MouseEvent.CLICK, menuCinemaClick);

function EnterFrameHandler(event:Event):void {
    smartBtn.gotoAndStop("selected");
}

function menuSmartClick(e:MouseEvent) {
    smartBtn.gotoAndStop("selected");
    smartBtn.buttonMode = false;

    cinemaBtn.gotoAndStop("none");
    cinemaBtn.buttonMode = true;
}

function menuCinemaClick(e:MouseEvent) {
    cinemaBtn.gotoAndStop("selected");
    cinemaBtn.buttonMode = false;

    smartBtn.gotoAndStop("none");
    smartBtn.buttonMode = true;
}


ENTER_FRAME is fired at the begining of each frame, so smartBtn will be set to "selected" state every time even if you set it to "none" state.

Remove EnterFrameHandler call or add a test like this :

function EnterFrameHandler(event:Event):void {
        if(cinemaBtn.currentFrameLabel != "selected")
            smartBtn.gotoAndStop("selected");
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜