| « Truncate Labels in percent width containers | Flex 3 beta 2 family is out! » |
Debugging event handlers in MXML gotchas
Everybody knows how difficult to debug event handlers in MXML attributes. So if we try to debug creationComplete event of our simple application with Flex Builder’s debugger we’ll fail:
XML:
<?xml version="1.0" encoding="utf-8"?> | |
<mx:Application | |
creationComplete="helloLabel.text = 'Hello, ' + event.currentTarget" | |
xmlns:mx="http://www.adobe.com/2006/mxml" | |
layout="vertical"> | |
<mx:Label | |
id="helloLabel" /> | |
</mx:Application> |
Lets set breakpoint at line 3 and… we can debug Application’s addEventListener (namely Container’s) for subscribing to creationComplete event. It’s not that we need 
To debug inline MXML handlers we can use the other way of declarative expressiveness. Lets transform attribute to node:
XML:
<?xml version="1.0" encoding="utf-8"?> | |
<mx:Application | |
xmlns:mx="http://www.adobe.com/2006/mxml" | |
layout="vertical"> | |
<mx:creationComplete> | |
<![CDATA[ | |
helloLabel.text = 'Hello, ' + event.currentTarget; | |
]]> | |
</mx:creationComplete> | |
<mx:Label | |
id="helloLabel" /> | |
</mx:Application> |
Just set breakpoint at line 7 and voilà. We can examine event’s object properties in debugger’s Variable View.
The only problem is intellisense for event property, event object type (and properties) etc. in Flex Builder (tested in FB 3 beta 3). As the final release of Flex Builder will be very soon I’m looking forward for this behavior will be fixed.
Hope it helps!
Special thanks to Eldar ‘Pirrest’ Prilutskiy for pointing me this.
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
3 comments
creationComplete="completeHandler(event)"
and a suitable private function in a Script block, that would work too, and you could correctly type the argument to get insight on the event too.