Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 - How do I stop a function?

I have a function in my "enterFrameHandler* function and it is structured like this:

private function addBoss():void{
   if(kills >= 3){
     trace("boss time");
   }
}

Since "addBoss" is a part of my ENTER_FRAME event listener function, "boss time" is traced infinitely as soon as kills reaches 3. I would like this function to stop as soon as it activates 1 time.

Is there another event listener I could use that will check for the function, but then stop as soon as it goes off?

Any suggestions would be appreciated. Thanks!

like image 706
Joseph Wagner Avatar asked Aug 24 '26 07:08

Joseph Wagner


2 Answers

private function addBoss():void{
    if(kills >= 3){
       trace("boss time");
       removeBossEnterFrame();
   }
}
private function removeBossEnterFrame():void{
    removeEventListener(Event.ENTER_FRAME, addBoss);
}

I'd prob remove the Enterframe event listner thats calling the addBoss function once you trace out "boss time".

This should do it.

private var isBossTime:Boolean = false;

private function addBoss():void
{
    if(kills >= 3 && isBossTime == false)
    {
        trace("boss time");

        isBossTime = true;
    }
}
like image 40
xLite Avatar answered Aug 26 '26 23:08

xLite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!