AS3: vs. event.currentTarget

I just figured out how to solve an ongoing bug in my AS3 code.

The problem: I added a MouseEvent.CLICK handler to a Label. Whenever I clicked on the label, the event would fire– but when I called “” in the event handler, it would return a TextField instead of a Label. This meant that to get the Label, I had to come up with messy workarounds like checking the type of the event and calling its parent if it wasn’t a Label.

The solution is actually quite simple: rather than calling “”, use “event.currentTarget” to get the object that originally had the event handler registered to it (in my case, the Label). I wish I’d known this earlier! For further reference regarding event propagation in Flex, see the Adobe documentation.