我建议创建一个字符串对象,该对象将通过单击按钮进行组合,然后与您设置的特定序列进行比较。这样做的好处是你可以让它适用于任何长度的序列。
这里最重要的是,您不希望所有三个按钮都使用相同的事件侦听器。您希望他们的操作是唯一的,否则,单击一个与单击所有其他操作相同(这是您当前代码的问题。)
var checkString:String = "";
//Create event listeners and their functions.
YellowButton.addEventListener(Mouse.CLICK, yellowClick);
RedButton.addEventListener(Mouse.CLICK, redClick);
BlueButton.addEventListener(Mouse.CLICK, blueClick);
function yellowClick(evt:Event):void
{
//In each event listener function, add a letter or
//string to the checkString variable.
checkString += "y";
//Then, see if the string matches or not.
check();
}
function redClick(evt:Event):void
{
checkString += "r";
check();
}
function blueClick(evt:Event):void
{
checkString += "b";
check();
}
//If the proper sequence is red, yellow, blue, the string would read "ryb".
function check():void
{
if(checkString == "ryb")
{
//Clear the checkString for convenience before going on.
clearString();
//CODE TO GO TO NEW FRAME
gotoAndStop(20);
}
else
{
//Make sure the string is at least 3 characters long.
if(checkString.length >= 3)
{
clearString();
gotoAndStop(foo);
}
}
}
function clearString():void
{
//You will want to have a function for clearing the string.
//This is especially useful if you have a button for "start over."
checkString = "";
}
这应该足以让你开始。如果您需要其他帮助,请随时评论我的回答。