@haxe-gurus: dynamic function as event listener does not work?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

@haxe-gurus: dynamic function as event listener does not work?

Mihail Ivanchev
Hey, I have the following situation best expressed by code. When I use a dynamic function as a listener, the mapping does not work. Instead just the code of select is called. However when I call the function manually, it works. How can this be? Bug?

select = selectFirst;

object.addEventListener(MouseEvent.CLICK, select);

select();
select();

dynamic function select(e) { trace("select"); }

function selectFirst(e)
{
trace("selectFirst");
selectSymbol = selectSecond;
}
function selectSecond(e)
{
trace("selectSecond");
}

Cheers,
M. Ivanchev

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: @haxe-gurus: dynamic function as event listener does not work?

Nicolas Cannasse
Le 12/10/2011 13:20, Mihail Ivanchev a écrit :
> Hey, I have the following situation best expressed by code. When I use a
> dynamic function as a listener, the mapping does not work. Instead just
> the code of select is called. However when I call the function manually,
> it works. How can this be? Bug?
>
> select = selectFirst;
>
> object.addEventListener(MouseEvent.CLICK, select);

The current "select" value is captured at the time of your
addEventListener. Use the following pattern to call the "current" select
function :

object.addEventListener(MouseEvent.CLICK, function(e) select(e));

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: @haxe-gurus: dynamic function as event listener does not work?

Mihail Ivanchev
Thank you, have a great day!

Regards,
M. Ivanchev

On Wed, Oct 12, 2011 at 1:31 PM, Nicolas Cannasse <[hidden email]> wrote:
Le 12/10/2011 13:20, Mihail Ivanchev a écrit :

Hey, I have the following situation best expressed by code. When I use a
dynamic function as a listener, the mapping does not work. Instead just
the code of select is called. However when I call the function manually,
it works. How can this be? Bug?

select = selectFirst;

object.addEventListener(MouseEvent.CLICK, select);

The current "select" value is captured at the time of your addEventListener. Use the following pattern to call the "current" select function :

object.addEventListener(MouseEvent.CLICK, function(e) select(e));

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org