所以,我的问题如下。
为什么我会收到此错误
(TypeError:错误 #2007:参数 child 必须为非空。在 TargetMain/killTarget() 的 flash.display::DisplayObjectContainer/removeChild() 处)
当试图通过鼠标点击从舞台上移除对象时?
我的应用程序代码如下。
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.ui.Keyboard;
public class TargetMain extends MovieClip
{
public function TargetMain()
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, spawner);//Spawning function listener
stage.addEventListener(MouseEvent.CLICK, killTarget);//Clicking function listener
}
public function spawner(k:KeyboardEvent):void
{
if(k.keyCode == 32)
{
trace ("spawned");
var theTarget:ParaspriteFull = new ParaspriteFull();
theTarget.x = Math.floor(Math.random() * stage.stageWidth);
theTarget.y = Math.floor(Math.random() * stage.stageHeight);
addChild(theTarget);
}
}
public function killTarget(toDie:MouseEvent):void
{
trace ("clicked")
var deadTarget:ParaspriteFull = (toDie.target as ParaspriteFull);
//Below is where I continually get an error and do not know how to fix it.
//This is also after searching the internet for hours trying to solve my issue.
//MovieClip(deadTarget).parent.removeChild(deadTarget);
removeChild(deadTarget);
}
}
}
任何帮助是极大的赞赏。