# Clear Interval Function: Beginner, Need Help

**URL:** <https://forum.kirupa.com/t/clear-interval-function-beginner-need-help/249247>\
**Category:** flash\
**Created:** [January 16, 2008, 10:04pm UTC](https://forum.kirupa.com/t/clear-interval-function-beginner-need-help/249247 "2008-01-16T22:04:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnns](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@bnns](https://forum.kirupa.com/u/bnns)\
**Post date:** [January 16, 2008, 10:04pm UTC](https://forum.kirupa.com/t/clear-interval-function-beginner-need-help/249247/1 "2008-01-16T22:04:34Z")

</div>

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=(15_Math.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.
