Hi, I’m pretty new to Flash and I’m working on making a tower defense game and I am trying to set a delay between each “minion” as it spawns but with my current code each minion is being deleted when the other is spawned.
Here is my code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Source extends MovieClip
{
var minion:Array;
public var delay:Timer = new Timer(1000);
public function Source()
{
addEventListener(Event.ENTER_FRAME, loop);
minion = new Array ;
}
function loop(e:Event)
{
if (numChildren<20)
{
var m = new Minion ;
delay.addEventListener(TimerEvent.TIMER, spawnDelay);
delay.start();
function spawnDelay(event:TimerEvent)
{
addChild(m);
m.x = -40;
m.y = 300;
}
}
}
}
}