开发者

Why does the button stay selected?

开发者 https://www.devze.com 2023-03-08 09:18 出处:网络
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

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

精彩评论

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