Pages

Friday, February 11, 2011

AS3: How to pass extra parameter in listener function

Trick for ActionScript-3 to pass extra parameter in the listener function.

SOURCE CODE
mc.addEventListener(MouseEvent.CLICK, foo("Wow!"));

function foo(str:String)
{
   return function(e:MouseEvent) { trace(str); }
}
OUTPUT
Wow!

No comments:

Post a Comment