How to create custom MouseEvent.CLICK event in AS3 (pass parameters to function)?

Matt W answers;
Take advantage of the dynamic function construction in AS3.


private function myCallbackFunction(e:Event, parameter:String):void
{
     //voila, here's your parameter
}

private function addArguments(method:Function, additionalArguments:Array):Function 
{
     return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}

    var parameter:String = "A sentence I want to pass along";
    movieClip.addEventListener(Event.COMPLETE, addArguments(myCallbackFunction, [parameter] ) );

Leave a Reply

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