为什么按钮保持选中状态?

时间:2011-05-24 05:55:16

标签: actionscript-3

我正在做一个简单的2按钮菜单。每个按钮都是一个带有3个标签的影片剪辑,状态为“无”,“已选择”和“悬停”状态。需要在输入框架上将smartBtn设置为“选中”。当clickBtn被点击时,smartBtn应该进入“无”状态。但我不确定为什么smartBtn继续被选中。

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, menuSmartClick);
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;
}

1 个答案:

答案 0 :(得分:1)

在每帧开始时触发ENTER_FRAME,因此即使将其设置为“无”状态,每次都会将smartBtn设置为“选定”状态。

删除EnterFrameHandler调用或添加如下测试:

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