Actionscript 3 removeChild不删除对象的子对象
我有一个叫blue_robot的电影剪辑,这个电影剪辑有一个叫right_hand的孩子,我想删除这个right_hand孩子,但删除孩子不要删除它。 下面是我的动作脚本代码:Actionscript 3 removeChild不删除对象的子对象,actionscript-3,actionscript,Actionscript 3,Actionscript,我有一个叫blue_robot的电影剪辑,这个电影剪辑有一个叫right_hand的孩子,我想删除这个right_hand孩子,但删除孩子不要删除它。 下面是我的动作脚本代码: var robot:blue_robot=new blue_robot(); addChild(robot); removeChild(robot.right_hand); 我尝试了此操作,但给出了错误类型错误:error#2007:参数child必须为非null。由于右手是机器人的子对象,您必须使用robot的移除子
var robot:blue_robot=new blue_robot();
addChild(robot);
removeChild(robot.right_hand);
我尝试了此操作,但给出了错误类型错误:error#2007:参数child必须为非null。由于
右手
是机器人的子对象,您必须使用robot的移除子对象方法:
robot.removeChild(robot.right_hand);
这会告诉robot
实例删除一个,如果它是子对象,robot.right\u hand
中引用的对象
以前,您告诉父上下文(示例代码中的this
)删除右手
,但是右手
不是this
的子对象,而是机器人
的子对象
您发布的错误意味着参考robot.right\u hand
不存在
仔细检查您实际上有一个名为“右手”的实例名或属性,它是否存在,并且在第一帧(如果创建了时间线)或构造函数(如果创建了代码)上有值。尝试以下操作:
robot.removeChild(robo.getChildByName("right_hand"));
但是最好是从blue_机器人类的内部移除右手。您应该使用面向对象的功能。这意味着blue_机器人必须自己做任何与其相关的事情。因此,结果应该如下所示:
class blue_robot extends MovieClip{
private var myRightHand:MovieClip ;
public blue_robot()
{
super();
myRightHand = this.getChildByName("right_hand");
}
public function removeRightHand():void
{
this.removeChild(myRightHand);
}
}
↑ 蓝色机器人课程和
var robot:blue_robot=new blue_robot();
addChild(robot);
robot.removeRightHand();
↑ 从机器人的父级移除右手。我尝试了此操作,但给出了错误类型error:error#2007:参数child必须为非null。