Adding inline function and removing it AS3

Saves you making real functions for tiny little functions – handy.

timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent){trace("inline function")});

To remove it, it can only be done when it is called (see the dudes link below for the source for this!)

myButton_btn.addEventListener(MouseEvent.CLICK, 
   function(e:Event)
   {
      trace(e.currentTarget.name+" was just clicked!");
      //removing anonymous listener
      e.currentTarget.removeEventListener(e.type, arguments.callee);
   });

src: (ty!): http://sierakowski.eu/list-of-tips/61-using-an-anonymous-inline-function-when-adding-an-event-listener.html

Tech Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑