How to pass arguments from an event listener in AS3 - SIMPLE

In AS2, I often found it useful to pass arguments to a function on a button press like so:

[COLOR=Blue]btn.onRelease = function(){
doSomething(“arg1”, “arg2”, “arg3”);
}[/COLOR]

I searched the interweb for DAYS trying to find how to accomplish this via an event listener in AS3, but everything I found suggested creating a custom Event. The problem with this, is you have to decide the arguments you wish to pass in advance, and I wanted to create them dynamically on the fly ( for example: passing a string that a user entered into a textfield to some function for processing ).

So last night I spent hours scouring forums - and UREKA! I finally found something that I was able to tweak to send a variable number of arguments of any data type. I’ve never posted on a forum, but it was such a breakthru that I had to share it with the world. I hope you find it as useful as I do.

Here is the code:

[COLOR=Blue]btn1.addEventListener( MouseEvent.CLICK, function onClick(e:Event ) { displayArgs(e, new Array(“Larry”, “Curly”, “Moe”) ) } );

btn2.addEventListener( MouseEvent.CLICK, function onClick(e:Event ) { displayArgs(e, new Array(“John”, “Paul”, “George”, “Ringo”) ) } );
[COLOR=Silver]
// this can be any function that needs to take zero or more parameters[/COLOR]
function displayArgs(e:Event, arg:Array){
trace(e.currentTarget + " args = ");
for ( var i:uint = 0; i < arg.length; ++i )
{
trace( arg* );
}
}[/COLOR]