操作脚本 3 - Flash AS3:提供的显示对象必须是调用方错误的子项



我正在创建一些动作脚本来模拟 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
}

我做错了什么吗?

我假设当您尝试删除它们时不会添加它们。 在删除父母之前,请确保它们存在。 此外,您可以尝试 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
}

相关内容

最新更新