1

如何创建两个按钮:一个按钮被按下,另一个按钮上升。我尝试使用这个:

//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: Error #1006: stop is not a function。在 Untitled_fla::MainTimeline/setToFemale()

4

1 回答 1

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;
    }   
}
于 2013-08-17T23:35:34.750 回答