Flash AS3:提供的DisplayObject必须是调用者错误的子对象
我正在创建一些动作脚本来模拟3个按钮状态,并相应地加载到电影剪辑中 我犯了这个错误Flash AS3:提供的DisplayObject必须是调用者错误的子对象,flash,actionscript-3,Flash,Actionscript 3,我正在创建一些动作脚本来模拟3个按钮状态,并相应地加载到电影剪辑中 我犯了这个错误 ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::DisplayObjectContainer/removeChild() at Untitled_fla::MainTimeline/sack_btnMouseOut() 当你试图这么做的时
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Untitled_fla::MainTimeline/sack_btnMouseOut()
当你试图这么做的时候
//get the objects
var addSackStill:sack_still = new sack_still();
var addSackHover:sack_hover = new sack_hover();
var addSackClick:sack_click = new sack_click();
//add the still object to the stage
addChild(addSackStill);
var SACK_X = 570.55;
var SACK_Y = 603.95;
addSackStill.x = SACK_X;
addSackStill.y = SACK_Y;
addSackHover.x = SACK_X;
addSackHover.y = SACK_Y;
addSackClick.x = SACK_X;
addSackClick.y = SACK_Y;
//create the event listeners
addSackStill.addEventListener(MouseEvent.MOUSE_OVER, sack_btnMouseOver);
addSackHover.addEventListener(MouseEvent.MOUSE_OUT, sack_btnMouseOut);
addSackHover.addEventListener(MouseEvent.CLICK, sack_btnClick);
//here are the functions for mouse over, mouse off, and click
function sack_btnMouseOver(event:MouseEvent):void {
trace("mouse over");
removeChild(addSackStill); //remove the movie clip
addChild(addSackHover); //add sackclick to the stage
}
function sack_btnMouseOut(event:MouseEvent):void {
trace("mouse out");
removeChild(addSackHover); //remove the movie clip
addChild(addSackStill); //add sackclick to the stage
}
function sack_btnClick(event:MouseEvent):void {
trace("Click");
removeChild(addSackHover); //remove the movie clip
addChild(addSackStill); //add sackclick to the stage
}
我做错什么了吗?我假设在您试图删除它们时它们没有被添加。在删除父对象之前,请确保父对象存在。此外,您可以尝试parent.removeChild,而不是该对象的remove:
//here are the functions for mouse over, mouse off, and click
function sack_btnMouseOver(event:MouseEvent):void {
trace("mouse over");
if (addSackStill.parent) { addSackStill.parent.removeChild(addSackStill); } //remove the movie clip
addChild(addSackHover); //add sackclick to the stage
}
function sack_btnMouseOut(event:MouseEvent):void {
trace("mouse out");
if (addSackHover.parent) { addSackHover.parent.removeChild(addSackHover); } //remove the movie clip
addChild(addSackStill); //add sackclick to the stage
}
function sack_btnClick(event:MouseEvent):void {
trace("Click");
if (addSackHover.parent) { addSackHover.parent.removeChild(addSackHover); } //remove the movie clip
addChild(addSackStill); //add sackclick to the stage
}
我在想,如果是这种情况,会抛出一个空对象引用错误吗?这是两种可能的情况——空父对象和非已删除子对象的父对象……如果我从试图删除的对象调用removeChild,通常会出现此错误。。尝试将removeChild包装在if(thing.parent)thing.parent.removeChild(thing)中;