2011-05-04 27 views
0

昨天有人在帮我解决我遇到的问题。我在测试之前接受了答案,并且遇到了问题。Actionscript - 函数不是有效的类型

我在做什么是我有一架飞机MC和一箱MC。飞机沿y轴飞行,我试图让箱子mc随机沿着飞机的路径随机掉落。这架飞机在y轴的每一个点上不断下降箱子。

我使用移动板/放箱子的代码是:

function makePlane():void 
{ 
    var chance:Number = Math.floor(Math.random() * 60); 
    if (chance <= 1) 
    { 
     trace(chance); 

     var tempPlane:MovieClip; 
     //Make sure a Library item linkage is set to Plane... 
     tempPlane = new Airplane(); 
     tempPlane.planeSpeed = 10; 
     tempPlane.x = Math.round(Math.random() * 1000); 
     tempPlane.y = Math.round(Math.random() * -1000); 
     addChild(tempPlane); 
     trace("Made Plane!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 
     planes.push(tempPlane); 
    } 
} 

function movePlane():void 
{ 

    var tempX:Number; 
    var tempCrate:MovieClip; 
    var tempPlane:MovieClip; 

    for (var j:int =planes.length-1; j>=0; j--) 
    { 
     tempPlane = planes[j]; 
     tempPlane.y += tempPlane.planeSpeed; 
     tempCrate = new Crate(); 
     tempCrate.y = tempPlane.y; 
     tempCrate.x = tempPlane.x; 
     addChild(tempCrate); 
     crates.push(tempCrate); 
    } 
} 

代码有人给我砸1个箱子代替众多的箱子是:

function addRandomCreation():void{ 
    var animationTime:Number = 5000; //The time the planes will be animating in ms 

    for(var i:int = 0; i < planes.length; i++){ 
     var planeTimer:Timer = new Timer(Math.round(animationTime * Math.random())); 
     planeTimer.addEventListener(TimerEvent.TIMER, timerComplete(i)); 
     planeTimer.start(); 
    } 
} 

function timerComplete(planeID:int):function{ 
    return function(event:TimerEvent):void{ 
     event.target.stop(); 
     event.target.removeEventListener(event.type, arguments.callee); 

     var tempCrate:MovieClip = new Crate(); 
     tempY = Math.round(Math.random() * planes[planeID].y); 
     tempCrate.y = tempY; 
     tempCrate.x = planes[planeID].x; 
     addChild(tempCrate);   
    } 
} 

当我尝试使用此代码时,出现错误“功能不是类型”。我从来没有见过函数用作返回类型。谁能帮我?

回答

2

退货类型function应该大写:Function。 timerComplete函数将planeID锁定在闭包中,以便可以从事件处理函数(从timerComplete返回的函数)访问该函数。

+0

啊很多谢谢肖恩:) – RapsFan1981 2011-05-04 21:39:28

相关问题