Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如果用户单击了错误的按钮,如何捕获?_Actionscript 3_Flash Cs6 - Fatal编程技术网

Actionscript 3 如果用户单击了错误的按钮,如何捕获?

Actionscript 3 如果用户单击了错误的按钮,如何捕获?,actionscript-3,flash-cs6,Actionscript 3,Flash Cs6,我为第一条鱼做了一个游戏。我找到了这样的代码。我也有错误的按钮 错误按钮列表: pinkButton.addEventListener(MouseEvent.CLICK, pinkClick); whiteButton.addEventListener(MouseEvent.CLICK, whiteClick); greyButton.addEventListener(MouseEvent.CLICK, greyClick); 我使用这个代码 import flash.events.Mouse

我为第一条鱼做了一个游戏。我找到了这样的代码。我也有错误的按钮

错误按钮列表:

pinkButton.addEventListener(MouseEvent.CLICK, pinkClick);
whiteButton.addEventListener(MouseEvent.CLICK, whiteClick);
greyButton.addEventListener(MouseEvent.CLICK, greyClick);
我使用这个代码

import flash.events.MouseEvent;
var checkString:String = "";
 
//Create event listeners and their functions.
YellowButton.addEventListener(MouseEvent.CLICK, yellowClick);
RedButton.addEventListener(MouseEvent.CLICK, redClick);
BlueButton.addEventListener(MouseEvent.CLICK, blueClick);



/*True choices*/ 
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();
}
/*True choices*/
 
//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(3);
}
else
{
 //Make sure the string is at least 3 characters long.
 if(checkString.length >= 3)
{
clearString();
gotoAndStop(1);
    }   
  }
}
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 = "";
}


如果我点击黄色、红色、蓝色,它就会工作。我怎么能做出错误的选择?我必须为所有可能的情况编写代码吗?玩家有1次机会。例如,如果玩家单击了2 false和1 true按钮,或者2 true和1 false按钮,这将导致玩家失败

使用一个值数组。像

var correctSequence:Array = ["r", "y", "b"];
然后使用递增变量来控制遍历数组

var arrayPosition:int = 0;
您需要一个变量来保存布尔值,即是否存在任何错误猜测:

var noneWrong:Boolean = true;
然后你可以做类似的事情

private function playerNextGuess(e:MouseEvent):void{
    if (e.target._color == correctSequence[arrayPosition] && noneWrong == true){
        arrayPosition++;
        if (arrayPosition == 3){
            playerWin();
            arrayPosition = 0;
        }
    } else {
        // put whatever logic you want for when the guess is wrong
        noneWrong = false;
        arrayPosition++;
        if (arrayPosition == 3){
            playerLose();
            arrayPosition = 0;
        }
    }
这将使玩家在得到结果(对或错)之前进行3次猜测。但它不会告诉玩家哪些是对的,哪些是错的。如果没有错误,则调用win函数。如果有错误,则调用lose函数。这就是你想要的吗


希望这能让你走上正确的方向。如果我写的东西不够清楚,请告诉我

谢谢你,博士。我忘记了那个代码,因为它不工作。我使用了一个新代码,但我有问题。这是代码fish1。addEventListener(MouseEvent.CLICK,click1);fish2.addEventListener(MouseEvent.CLICK,click2);fish3.addEventListener(MouseEvent.CLICK,click3);fish4.addEventListener(MouseEvent.CLICK,click4);var PC:Boolean=false;函数click1(m:MouseEvent){PC=true;}函数click2(m:MouseEvent){PC=true;}函数click3(m:MouseEvent){PC=true;}函数click4(m:MouseEvent){if(PC){PC=false;gotoAndPlay(1);}它应该在单击2按钮的true之后执行。那么2按钮true 2按钮false。新问题?写一篇新文章。我不想在评论中阅读未格式化的代码。我开始新的主题,如果你想帮助我,请阅读。谢谢,谢谢,但这对我来说太复杂了。我尝试了,但我做不到。