hovercraft
Technical User
It is my understanding that by using setInterval I can run a function every few miliseconds and then use clearInterval to reset the variable and allow the function to be ran again...and again and again.
However, I'm not having any luck with this.
I've included my script which is the first (and only) frame.
What it does is create a random number of enemys (tie fighters)and moves each enemy from the top to the bottom with a random yet constant speed.
and I want it to run the createTie function every couple of seconds, so that there is a steady supply of enemys.
Any help would be greatly appreciated.
Thanks,
Dave
However, I'm not having any luck with this.
I've included my script which is the first (and only) frame.
What it does is create a random number of enemys (tie fighters)and moves each enemy from the top to the bottom with a random yet constant speed.
and I want it to run the createTie function every couple of seconds, so that there is a steady supply of enemys.
Any help would be greatly appreciated.
Thanks,
Dave
Code:
//---- variables ----
var intervalId:Number;
var randTieNum:Number = Math.floor(Math.random() * (3 - 1 + 1)) + 1;
var i:Number = 0;
//---- functions ----
function createTie()
{
for ( i;i<randTieNum;i++)
{
var currenttimer:Number = getTimer();
attachMovie("tiefighter", "myTie"+i+currenttimer, _root.getNextHighestDepth());
myTie = _root["myTie"+i+currenttimer];
placeTie(myTie);
myTie.onEnterFrame = function()
{
if (this.hitTest(_root.mylaser01))
{_root.myscore += 10;
removeMovieClip(_root.mylaser01);
removeMovieClip(this);
}
if (this._y > 400)
{
removeMovieClip(this);
}
this._y += this.Speed;
clearInterval(intervalId); }
}
}
function placeTie(which)
{
var randTiex:Number = Math.floor(Math.random() * (550 - 1 + 1)) + 1;
var randTieSpeed:Number = Math.floor(Math.random() * (5 - 1 + 1)) + 1;
which._x = randTiex;
which._y = 70;
which.Speed = randTieSpeed;
}
//---- start ----
intervalId = setInterval(_root, "createTie", 1000);