1

我想检查一个孩子是否存在,如果它确实删除了它。如果不做其他事情......我还计划为更多的孩子做检查......

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown3);

function onKeyDown3(event:KeyboardEvent):void
{
    if( event.keyCode == Keyboard.BACK )
    {
        if (over.stage){
        event.preventDefault();
        removeChild(over);
        gotoAndPlay(350, "Scene 1");
        }else {
        event.preventDefault();
        gotoAndPlay(346, "Scene 1");        
        }

    }
}

我试过了,但它不起作用。但我认为它基本上显示了我想做的事情,但如果是为了其他孩子的话,还有更多其他事情。“结束”只是一个电影剪辑

错误:

TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/setChildIndex()
    at Bike_safety_fla::MainTimeline/onKeyDown1()[Bike_safety_fla.MainTimeline::frame146:17]
    at runtime::ContentPlayer/sendKeyUpDown()
    at runtime::SimulatedMobileDeviceContentPlayer/onBack()
4

1 回答 1

4

Use contains() to test if over is on the display list.

From DisplayObjectContainer documentation:

Determines whether the specified display object is a child of the DisplayObjectContainer instance or the instance itself. The search includes the entire display list including this DisplayObjectContainer instance. Grandchildren, great-grandchildren, and so on each return true.

Implemented as:

if (this.contains(over))
{
    removeChild(over);
    gotoAndPlay(350, "Scene 1");
}
else
{
    gotoAndPlay(346, "Scene 1");        
}
于 2012-10-25T05:28:48.897 回答