【问题标题】:Actionscript Error ArgumentError: Error #2025:Actionscript 错误 ArgumentError:错误 #2025:
【发布时间】:2014-07-03 00:43:42
【问题描述】:

我正在制作这个 Winterbells 类型的游戏,它给了我这个错误,但只有当我击中第一个对象时。

这是代码:

package{
import flash.display.MovieClip;
import flash.events.*;
public class Brandstof extends MovieClip {

    var _root:Object;//Dit symboliseert de hoofd-tijdlijn

    public function Brandstof() {
        addEventListener(Event.ADDED, beginClass);
        addEventListener(Event.ENTER_FRAME, eFrame);
    }

    private function beginClass(e:Event):void{
        _root = MovieClip(root);

        if(_root.brandstofAantal == 1){//Ervoor zorgen dat de brandstoftankjes, als het de eerste is, random op de stage komen
            this.x = Math.random()*525;
            _root.brandstofLaatsteCoord = this.x;
        } else {
            //Om ervoor te zorgen dat de nieuwe bel niet te ver weg is van de eerder, plaats met een afstand van 250px
            this.x = _root.brandstofLaatsteCoord + (Math.random()*500)-250;
            if(this.x > 537.5){//Ervoor zorgen dat de brandstoftonnetjes binnen de stage blijven
                this.x -= 250;
            } else if (this.x < 12.5){
                this.x += 250;
            }
        }
        this.y = _root.brandstofTop;//zorgen dat de y-waarde niet op de stage zit
    }
    private function eFrame(e:Event):void{
        this.y += 3;//Ervoor zorgen dat de brandstoftonnetjes langzaam naar beneden gaan
        if(this.hitTestObject(_root.mcRaket)){//ervoor zorgen dat mcRaket omhoogspringt als ie een object raakt
            _root.characterSpringen = true;
            _root.springSnelheid = _root.springSnelheidLimiet*-1;//springsnelheid resetten

            this.removeEventListener(Event.ENTER_FRAME, eFrame);//de listeners weghalen en van stage verwijderen
            _root.brandstofHolder.removeChild(this);
        }
    }
}
}

这是错误:

ArgumentError:错误 #2025:Het opgegeven DisplayObject moet een onderliggend item van de aanroeper zijn。 在 flash.display::DisplayObjectContainer/removeChild() 在 Brandstof/eFrame()

我是个新手,我正在学习教程。

【问题讨论】:

  • 你能把你的错误翻译成英文吗?
  • 当然,这基本上意味着:提供的 DisplayObject 必须是调用者的子对象。 AS3

标签: actionscript-3


【解决方案1】:

错误是因为这行:

_root.brandstofHolder.removeChild(this);

根据 Flash 播放器,_root.brandstofHolder 不是 this 的父级。

更安全的方法是:

if(this.parent) this.parent.removeChild(this);

这样this 仅在它位于 displayList 上(有父级)时才会被删除,并且无论您将父级设置为什么,您都将从正确的对象中删除它。

【讨论】:

  • 我试了一下,成功了!非常感谢,我会记住你的建议:)。
  • 哎呀,这个网站的新手;)。完成!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 2012-08-10
  • 1970-01-01
  • 1970-01-01
  • 2018-12-08
相关资源
最近更新 更多