Add a parameter (or even more then one) to Flex event listener

Hi All,

Well, sometimes you find yourself needing a work around to a default framework or language behavior.

I found myself needing exactly that on an application I’m building. No matter what I did I couldn’t find a “normal” way of doing what I did.

This is actually a pretty efficient way of creating your own event listener.

We will talk about the button and we’ll add an event listener.

By default the code looks like this:

[as3]

<?xml version=“1.0” encoding=“utf-8”?>

mx:Script

/mx:Script

/mx:Application

[/as3]

As you can see, the function listening to the click event can only accept one parameter passed to it. This parameter is the event the function is listening to.

Now, what if I want to do another thing: I want to pass the function another parameter. This parameter can be anything – it can be hard coded or it can come from a runtime result of the code.

In the same way, you can add more then 1 parameter of course.

Let us see our code now:

[as3]

<?xml version=“1.0” encoding=“utf-8”?>

mx:Script

/mx:Script

/mx:Application

[/as3]

Now, didn’t I make you happy?

Good luck and happy coding!

Submit to Hacker News

[NOTE] This post has been imported to Hugo from a Wordpress blog. It may be broken, missing images, code snippets or other information.

[NOTE] updated July 14, 2009. It's 3485 days old . This article may have outdated content.