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

时间:2015-06-03 02:01:49

标签: actionscript-3 addchild

我的问题是我调用函数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();
            }
        }
}

对这两个问题的任何建议??

1 个答案:

答案 0 :(得分:0)

addSpotlight中使用:

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

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