我正在尝试做一个直升机游戏,我有一个标题屏幕添加到我的游戏,但每当我尝试removeChild的按钮不是删除-它给我这个错误:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at CopterScratch/gameStart()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.controls::LabelButton/keyUpHandler()下面是我的代码:
public function gameStart(e:MouseEvent):void {
removeChild(objTitleScreen);
if (btnStart.enabled){
removeChild(btnStart);
}
removeChild(rbNormal);
removeChild(rbDifficult);
tmrMoveMap.start();
tmrGravity.start();
addChild(objHelicopter);
}发布于 2013-06-05 11:13:10
您可以执行以下操作:
if (objTitleScreen.parent)
objTitleScreen.parent.removeChild(objTitleScreen);不过,理想情况下,您应该知道对象的父对象,以及这是否真的是必要的。
发布于 2013-06-05 08:24:15
以下一项(或多项):objTitleScreen、btnStart、rbNormal或rbDifficult...不是定义函数“”gameStart“”的对象的子级。“本机函数'removeChild‘需要一个子代作为参数,但它抱怨说没有得到子代。在调用'gameStart‘函数的类中运行下面的代码,看看有哪些子代(假设每个子代都已显式命名,如果不是这样-在代码中省略'.name’)。
for (var i:uint = 0; i < this.numChildren; i++) {
trace('child at: ' + i + ' = ' + this.getChildAt(i).name);
}阅读AS3显示列表上的一篇内容非常丰富的文章,您将了解如何解决您的问题。
https://stackoverflow.com/questions/16929369
复制相似问题