如何创建两个按钮:当按下其他按钮时,其他按钮会上升

时间:2013-06-28 15:35:15

标签: actionscript-3 flash actionscript

如何创建两个按钮:一个按钮被推动其他按钮上升。我试过用这个:

//Create male/female button objects
var maleButton:maleButtonObejct = new maleButtonObject();
var femaleButton:femaleButtonObject = new femaleButtonObject();

//Add evnet listeners to both buttons
maleButton.addEventListener(MouseEvent.CLICK, setToMale);
femaleButton.addEventListener(MouseEvent.CLICK, setToFemale);

//Create isMale variable
var isMale:Boolean;

//Male/Female button functions
function setToMale(event:MouseEvent):void  {
isMale = true;
maleButton.stop(3);
femaleButton.stop(1);
}

function setToFemale(event:MouseEvent):void  {
isMale = false;
femaleButton.stop(3);
maleButton.stop(1);
}

我收到运行时错误: TypeError:错误#1006:stop不是函数。     在Untitled_fla :: MainTimeline / setToFemale()

1 个答案:

答案 0 :(得分:0)

以大写字母重命名您的班级,例如MaleButton。

这是一种轻松实现目标的方法:

var maleButton:MaleButton = new MaleButton();
var femaleButton:FemaleButton = new FemaleButton();

maleButton.addEventListener(MouseEvent.CLICK, clicked);
maleButton.addEventListener(MouseEvent.CLICK, clicked);

function clicked(event:MouseEvent):void
{
    switch(event.target)
    {
        case maleButton:
            maleButton.gotoAndStop(3);
            femaleButton.gotoAndStop(1);
            break;
        case femaleButton:
            maleButton.gotoAndStop(1);
            femaleButton.gotoAndStop(3);
            break;
        default:
            return;
    }   
}