我正在创建一些动作脚本来模拟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()
尝试这样做时
//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
}
我做错了吗?
答案 0 :(得分:1)
我假设你在尝试删除它们时没有添加它们。在删除之前确保父项存在。此外,您可以尝试使用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
}