动作脚本 3:在已添加的子问题中添加子问题

Action Script 3: Addchild within an already added child issue

我的问题是调用函数 addSpotlight 时出错。

TypeError: Error #1010: A term is undefined and has no properties.
    at BubbleBoy_fla::MainTimeline/addSpotlight()
    at BubbleBoy_fla::MainTimeline/policeHeli()
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

我的代码是这样的:

//Adding Helicopter
function addHelicopter(xLocation: int, yLocation: int, passSpeedX, passSpeedY): void {
    var helicopter: Helicopter = new Helicopter(xLocation, yLocation, passSpeedX, passSpeedY);
    back.addChild(helicopter);
    heliList.push(helicopter);
    playFly();
}

//Adding Spotlight
function addSpotlight(xSpotlightLocation: int, ySpotlightLocation: int, spotlightSpeedX): void {
    var spotlight: Spotlight = new Spotlight(xSpotlightLocation, ySpotlightLocation, spotlightSpeedX);
    back.helicopter.addChild(spotlight);
    spotlightList.push(spotlight);
}

我这样做的原因是因为直升机可以被摧毁并且聚光灯同时被移除,但是如果你不摧毁直升机并且聚光灯打到你然后你就会被抓住。

我之前的代码只是将聚光灯添加到后面的容器中,然后将它与直升机排成一行,但这只会删除阵列中的第一个聚光灯。

if (heliList.length > 0) {
    for (var h: int = 0; h < heliList.length; h++)
        for (var l: int = 0; l < spotlightList.length; l++) {
            if (heliList[h].hitTestPoint(boy.x + upBumpPoint.x, boy.y + upBumpPoint.y, true)) {
                trace("SCORE POINTS")
                score += 100;
                playCrash();
                playFly();
                heliList[h].removeHeli();
                spotlightList[l].removeSpotlight();

                //policeTimer.start();
            }
        }
}

对这两个问题有什么建议吗??

addSpotlight中使用:

trace('spotlight: ', spotlight);
trace('back: ', back);
trace('back.helicopter: ', back.helicopter);
trace('spotlightList: ', spotlightList);

无论缺少什么 - 都会导致问题:)