Ok, you have to write a class for a Flex project, so do you use MXML or Actionscript? What I’ve often seen in Flex projects is MXML everywhere, even when a simple Actionscript class would have done the trick, hence this post. I understand the urge to use MXML, but there are a few caveats that make it a deal-breaker that I’m going to look at here.

– no parameters in the constructor. When you design a class, parameters in the constructor indicate the parameters without which the class cannot function. As far as I know, there is no other way to push this information towards the person integrating the class, except maybe with a doc that won’t be read unless you twist their arm. What is also nice about parameters in the constructor is that you don’t have to worry about them being set, because they are available for the whole lifespan of the class.

Limited inheritance. If you created an MXML file and want to add elements in a sub-class, you can’t. Not only that but it doesn’t break at compile-time but at run-time with an incomprehensible debug message.
– increased compilation time. Remember, MXML is converted to Actionscript. So it takes longer to compile. As a side note, the generated Actionscript is really ugly, but that would be for another post.

– no internal classes for MXML files. Ok, this is nitpicking, but when you gotta do it, you gotta do it and you can’t.

After all that, the one place where I feel MXML shines and is really justified is when you need to do some floating layouts with boxes. I’ve tried doing it in Actionscript and it’s just completely unreadable compared to MXML.

So in conclusion, my rule of thumb is the following: If it doesn’t at least have 2 levels of imbrication of boxes, it’s probably better to go straight to Actionscript.

Pin It