Thursday, June 25, 2009

Adding an event listener function with arguments using Actionscript

This might come handy whenever you can't use directly mxml and you need to add an event listener function that needs one or more arguments.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute" creationComplete="myInitialize()">
import mx.controls.Alert;

private function myFunction(arg:String):void {"Received call with argument=" + arg);

private function myInitialize():void {
myButton.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void{
var someArg:String="an_argument";

<mx:Button id="myButton" label="Click me!"/>

See this code in action here

No comments: