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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/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 gotoAndStop导致对象删除自身_Actionscript 3_Removechild - Fatal编程技术网

Actionscript 3 AS3 gotoAndStop导致对象删除自身

Actionscript 3 AS3 gotoAndStop导致对象删除自身,actionscript-3,removechild,Actionscript 3,Removechild,我有一个学生正在做AS3中的塔防游戏,有一个问题困扰着我。他正在使用hitTestObject更改电影剪辑的移动方向。movieClip有自己的时间轴,其中包含对象所面对的不同方向的帧,以及一个链接的.as文件,其中包含对象行为的代码 当他调用gotoAndStop来更改movieClip的内部帧时,将触发移除的事件,但对象仍保留在屏幕上,不再移动 我所有的搜索都能找到关于删除对象的答案,但我没有看到任何关于阻止对象删除自身的内容 以下代码是由movieClip对象的.as类文件中的ENTER_

我有一个学生正在做AS3中的塔防游戏,有一个问题困扰着我。他正在使用hitTestObject更改电影剪辑的移动方向。movieClip有自己的时间轴,其中包含对象所面对的不同方向的帧,以及一个链接的.as文件,其中包含对象行为的代码

当他调用gotoAndStop来更改movieClip的内部帧时,将触发移除的事件,但对象仍保留在屏幕上,不再移动

我所有的搜索都能找到关于删除对象的答案,但我没有看到任何关于阻止对象删除自身的内容

以下代码是由movieClip对象的.as类文件中的ENTER_FRAME事件触发的循环:

private function eFrame(event:Event):void
    {

        if (_root.isPaused == false)
        {
            //MOVING THE ENEMY
            this.x +=  speed * xDir;
            this.y -=  speed * yDir;
            if (health <= 0)
            {
                _root.currency +=  4;

                this.parent.removeChild(this);
            }
            if (this.x > 770)
            {
                this.parent.removeChild(this);
                _root.health -=  10;
                _root.gotHit = true;
            }
            //checking if touching any invisible markers
            for (var i:int=0; i<_root.upHolder.numChildren; i++)
            {
                //the process is very similar to the main guy's testing with other elements
                var upMarker:DisplayObject = _root.upHolder.getChildAt(i);
                if (hitTestObject(upMarker))
                {
                    yDir = 1;
                    xDir = 0;
                    this.gotoAndStop(3);


                }
            }
            for (i=0; i<_root.downHolder.numChildren; i++)
            {
                //the process is very similar to the main guy's testing with other elements
                var downMarker:DisplayObject = _root.downHolder.getChildAt(i);
                if (hitTestObject(downMarker))
                {
                    yDir = -1;
                    xDir = 0;
                    this.gotoAndStop(7);

                }
            }

            for (i=0; i<_root.rightHolder.numChildren; i++)
            {
                //the process is very similar to the main guy's testing with other elements
                var rightMarker:DisplayObject = _root.rightHolder.getChildAt(i);
                if (hitTestObject(rightMarker))
                {
                    yDir = 0;
                    xDir = 1;
                    this.gotoAndStop(6);
                }
            }
            for (i=0; i<_root.leftHolder.numChildren; i++)
            {
                //the process is very similar to the main guy's testing with other elements
                var leftMarker:DisplayObject = _root.leftHolder.getChildAt(i);
                if (hitTestObject(leftMarker))
                {
                    yDir = 0;
                    xDir = -1;
                    this.gotoAndStop(2);

                }
            }
        }
    }
    private function remove(event:Event):void
    {
        trace("remove");
        removeEventListener(Event.ENTER_FRAME, eFrame);
        _root.enemiesLeft -=  1;

    }
}
私有函数eFrame(事件:事件):void
{
如果(_root.isPaused==false)
{
//转移敌人
这个.x+=速度*xDir;
这个.y-=速度*yDir;
if(健康770)
{
this.parent.removeChild(this);
_root.health-=10;
_root.gotHit=true;
}
//检查是否接触任何不可见的标记

对于(var i:int=0;i您在哪里添加删除侦听器


如果没有更多信息,我猜您正在收听动画中的剪辑,并且它并非在所有帧上都存在(或者,更可能的情况是,flash pro正在将该实例替换为另一个相同的实例。这可能取决于您添加关键帧的顺序、月亮的对齐方式和电离层的波动。最简单的修复方法是删除所有关键帧,然后重新创建它们。然后永远不要使用flash pro f。)或者再也没有了。)

如果我没有弄错的话,移除事件是由从包含它的MovieClip或Sprite内的舞台移除的任何内容触发的。尤其是对于具有动画的MovieClip,每次都会移除和添加内容,例如,如果动画的某个部分在时间轴或关键帧上结束


Event.REMOVED\u FROM\u STAGE仅在容器本身从STAGE中移除时才被调度。可能这导致了您的混淆?从您的代码示例中,我看不出您正在侦听的事件类型到底是什么。

谢谢。将我的事件侦听器从REMOVED更改为REMOVED\u FROM\u STAGE解决了问题。