Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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 AS3中增加变量的问题_Actionscript 3 - Fatal编程技术网

Actionscript 3 AS3中增加变量的问题

Actionscript 3 AS3中增加变量的问题,actionscript-3,Actionscript 3,我有这个代码,它允许我检查两个对象之间的命中测试 public function loop(e:Event):void { y += speed; if (y > stageRef.stageHeight) { setupAsteroid(); } if (hitTestObject(target.hit)) { q++;

我有这个代码,它允许我检查两个对象之间的命中测试

public function loop(e:Event):void
    {
        y +=  speed;

        if (y > stageRef.stageHeight)
        {
            setupAsteroid();

        }

        if (hitTestObject(target.hit))
        {

            q++;

            if(q == 3){

            myTextBox.text = myText;
            stage.addChild(myTextBox)
            trace(myText)


            }
            trace("Hit");
            trace(q);



            stageRef.addChild(new Explosion(stageRef, x, y));
            removeSelf();

        }
    }
如您所见,当发生3次命中测试时,它应打印“游戏结束”,但我必须添加以下tid位:

  private function removeSelf():void
    {

        removeEventListener(Event.ENTER_FRAME, loop);



        if (stageRef.contains(this))
        {
            stageRef.removeChild(this);
        }





    }

然而,为了删除所有必需的内容,这又会删除我的事件侦听器,并再次使q=0。如果发生3次命中测试,对话将打印出来。我将把q的值存储在数组中,并在循环中的每次迭代中推送到数组中。我看不到生成
q=0
的代码,也没有显示如何初始化
q
的代码。你说的是
if(q==3)吗{
block不起作用?不确定你的问题是什么。@Sid Smith-你的代码有点不可读。所以,你想只在点击数等于3时显示文本并删除stageRef?什么是stageRef-一个stage引用?你为什么要跟踪它?每个DisplayObject都有stage的内部引用,你不需要保留自己的…@aada是的,我试着写了一个数组,我写了一条语句说if(myArray.length==3),但是,当我输入一个数字并使用trace命令时,它只是不断地将该数字添加到末尾,而不是填充整个数组,因此myArray.length保持为1,而不是3。我尝试使用Math.random,它只是为数组中的该插槽分配一个新的数字,但它实际上不会填充数组。@其他人,为混乱的代码感到抱歉e和缺乏文件。