FlashSim Blog

Product simulations, Flash, state machines, and observations

Where am I?

I am not so lost as my title suggests, but I ran into an issue as I get into AS 3 that doesn’t quite make sense to me yet.

I was setting up an event handler within the scope of a class definition, and using an anonymous function to handle the event:

title.addEventListener(MouseEvent.MOUSE_DOWN, function (e:MouseEvent) { ...

I expected that if I used ‘this’ inside the anonymous function, I would be able to reference the instance.  However, I get something different, some global variable (on trace, it comes out [object global]).  If I use ‘parent’ inside the anonymous function, I get the parent of the instance, but I can’t seem to get a pointer to the instance.

Of course  If I make my event handler as a method of the class, I get ‘this’ to refer to the current instance.  No time to dwell on this now as to why I get this behavior, but I thought it was interesting.

November 22, 2008 Posted by jonkaye | AS 3.0 | | No Comments Yet