It works in MXML and not in AS3 because these are different languages
with different rules... one is declarative and one is procedural.

 

You obviously find the MXML syntax convenient... and that's why we
support it! But in a procedural language like AS3, when you pass Foo(2)
as a method parameter, it always means to evaluate the value Foo(2) and
pass that.

 

You can write either

 

    btnFoo.addEventListener(MouseEvent.CLICK, Foo);

 

where Foo is a method that takes a single argument of type MouseEvent
and returns void

 

or use an anonymous function with the same signature

 

   btnFoo.addEventListener(MouseEvent.CLICK,
function(event:MouseEvent):void { ... });

 

As for wanting to pass an additional parameter to an event handler, this
simply isn't how the Flash Player works. When it calls your event
handler, it passes ONLY the event object that was passed to
dispatchEvent(). This may seem like a major restriction, but we had no
problem writing all the Flex components with this event model.

 

You can 

 

1. Access any data on the 'this' object if your event handler is a
method of a class.

2. Access any data on the event.target or event.currentTarget objects.

3. Put the data in the event object itself, either by subclassing or by
using DynamicEvent.

 

Gordon Smith

Adobe Flex SDK Team

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jason The Saj
Sent: Wednesday, April 16, 2008 12:13 PM
To: [email protected]
Subject: [flexcoders] Click Lite: The right click now. But not now?

 

Why does click work here?

<mx:Button id="btnFoo" label="Foo x 2" click="Foo(2)"/>

But not here?

btnFoo.addEventListener(MouseEvent.CLICK,Foo(2));

Now, it's obviously Adobe has coded the button component to allow for
arguments to be passed via the click parameter. But we're not given
that same privilege when using just AS3.

But obviously, they must have already coded this functionality. I'd
rather not have to re-invent the horse. Any answers?

 

Reply via email to