I was working on piece of a project that required me to create bullets dynamically. I needed to be able to give them properties and functions.
so i created an initializer function and when certain conditions were met the function would be removed and call upon other related functions.
Below is the function i am using i had some traces running which informed me that the function was still functioning after the clip had been unloaded.
function fInitializer()
{
if(bRequestRotation == true)
{
iInitializerLocation = iInitializer;
clearInterval (iInitializer);
iRequestRotation = setInterval(fRequestRotation, 1000 / 12);
iUnloader = setInterval(fUnloader, 5000);
bRequestRotation = false;
}
}
The code in all its entirity is posted below:
var bBulletActive:Boolean = new Boolean(false);
var nBulletVelocity:Number = new Number(5);
var nBulletAngle:Number;
var nStoredLocation;
var bRequestRotation;
var iRequestRotation;
newThis = this;
var iInitializerLocation;
var iInitializer = setInterval(fInitializer, 1000 / 12);
var iUnloader:Number;
function fInitializer()
{trace("initializer Run, Number: "+iInitializer);
trace("nStoredLocation: "+nStoredLocation);
//trace("iRequestRotation: "+iRequestRotation);
if(bRequestRotation == true)
{
iInitializerLocation = iInitializer;
clearInterval (iInitializer);
iRequestRotation = setInterval(fRequestRotation, 1000 / 12);
iUnloader = setInterval(fUnloader, 5000);
bRequestRotation = false;
}
}
function fRequestRotation()
{
trace(“running”);
trace("nStoredLocation: "+nStoredLocation);
trace("nRotationValue: "+nBulletAngle);
var angle:Number = Math.round(nBulletAngle);
nBulletRadian =(nBulletAngle/180)Math.PI;
dy=(15Math.sin(nBulletRadian));
dx=(15*Math.cos(nBulletRadian));
newThis._x+=dx;
newThis._y+=dy;
trace("dx: “+dx +” Loaction X: "+this._x);
trace("dy: “+dy+” Loaction Y: "+this._y);
}
function fUnloader()
{
unloadMovie(newThis);
clearInterval(iUnloader);
clearInterval(iRequestRotation);
clearInterval (iInitializerLocation);
iInitializer=null;
trace(“Movie Unloaded”)
}
I would be most grateful for anyhelp at all.