如何创建两个按钮:一个按钮被推动其他按钮上升。我试过用这个:
//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()
答案 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;
}
}