Flex Tip of the Day: mx free mxml
I have been doing this Flex Tip of the day series on flex-india and people have told me that these tips could be helpful to people outside the list as well so i will re-post the tips I have written about till now here on Rags to Riches over the next few days and then whenever I post a new tip I will post it on both mediums. Most people on the Flex-India list have a beginner – intermediate level expertise in Flex and these tips are focused at that target audience.
So lets start with a very basic yet useful tip ….
mx free mxml
How many times do you type ‘mx’ when writing an mxml application, i
type it zero times .. Here’s how …
<?xml version="1.0" encoding="utf-8"?> <Application xmlns="http://www.adobe.com/2006/mxml"> /*now you can use the tags without mx: and code hinting in FlexBuilder still works */ <Canvas> <Button/> </Canvas> </Application>









July 6th, 2007
Not sure about other IDEs but FlexBuilder doesn’t require you to type it anyways. Its essentially ignored in the auto-complete list, so typing “
July 6th, 2007
Ugh, tags got killed… typing “<Bu” will bring up <mx:Button in the list.
July 6th, 2007
Ben,
Thats strange…. for me once I’ve finished writing my Application tag as described above … <Bu brings up <Button>in the auto complete … which is how it should be cause when you have a different name space for components … Flex Builder’s auto-complete shows the correct name space.
As for your first comment … I have two things to say ..
1. I think this makes the code a lot cleaner
2. There are many who do not use Flex Builder and for them this saves a lot of typing.
July 6th, 2007
Nice tip for beginners.
July 6th, 2007
Are others seeing what Ben is seeing? … for me the autocomplete behaves properly.
@Anand: Thanks, thats the idea … I will be doing more such beginner-intermediate level tips over the coming days.
July 6th, 2007
Mrinal – Ben is saying that with xmlns:mx=” … Even if you still start typing But… rather than mx:But… FlexBuilder will autocomplete mx:Button – you don’t have to type mx: at all, you can just start typing the class name.
July 6th, 2007
Britt,
Thank you for trying to clarify … but Ben said .. “Ugh, tags got killed…” I feel he meant that after he uses xmlns=”… auto complete still suggests code with mx: for him and he does not like that
For me, that is not the case and autocomplete works as you would expect it to .. code is suggested without the mx:
Ben,
Some clarification would help.
July 6th, 2007
“Not sure about other IDEs but FlexBuilder doesn’t require you to type it anyways”
He’s referring to “mx” ( mx free mxml ).
In FlexBuilder, you don’t have to type “” tag… all you need to do is type “
July 6th, 2007
When he said “tags got killed” he meant that your blog ate up the greater than signs just like what happened on my post above.
anyways – you dont have to type “mx:Bu…” – to autocomplete the Button tag, all you need to do is start typing “Bu…” and flex builder will autocomplete the Button tag for you.
July 6th, 2007
Aha .. got ya .. damn Wordpress !
Anyways .. thanks for the clarification .. so we’re good here … Its established that the code hinting works fine … and this approach can be useful although everyone would have their preference.
My preference is mx free mxml .. because:
1. Its cleaner code
2. It means less typing, at least for people without FlexBuilder.
July 7th, 2007
It could be a good approach. Every XML based languages I know (XHTML, Mozilla XUL, Microsoft XAML) don’t use a prefix for the default namespace. I don’t understand why Adobe use the not necessary mx: prefix in all examples and documentation.
July 7th, 2007
The explicit inclusion of the default namespace prefix both provides an immediately apparent visual cue and lends semantic context to an XML node.
Arguably, the first thing a new user learns when encountering MXML for the first time is that “these blocky things that make the flashy parts all have the same prefix”.
From that point on they know, when looking at examples online or in the documentation, that when they see “mx:”, it precedes a “blocky thing”, or class, that comes from Adobe/Macromedia, rather than from the author of the example they are attempting to understand.
After some experience writing and using their own classes, and those of others (the far majority of whom employ the “mx:” prefix, serving to reinforce the notion), they arrive at a point that they can comprehend understand that the prefix is superfluous and optional.
That said, I can say with (relative) confidence that including a namespace for every MXML node is what many would consider to be a ‘best practice’ for Flex development. Not so for general purpose XML… but this isn’t general purpose XML…
I would argue it’s just one of those pain-in-the-ass things that may make it infinitely easier to maintain or extend a project in the future… right up there with the use of concise, human-readable, and semantically appropriate variable names, placing spaces between operators and the values adjacent to them, and applying just enough comments to communicate whatever intention the well-written-for-clarity-as-well-as-performance code requires, and doing so during development rather than afterwards.
I don’t know what is the ‘right answer’, or even if there is one, but I do know that simply because you CAN do something (and are even perfectly justified in doing so), doesn’t mean you SHOULD do something.
Nice to have the choice, though. Thank you.
July 7th, 2007
Hi Eric,
All the points you make are very true and I agree with you on
all counts, you said:
“After some experience writing and using their own classes, and those of others ….. they arrive at a point that they can comprehend understand that the prefix is superfluous and optional.”
Well with this tip, I was just helping them arrive at that point.
July 7th, 2007
Indeed. Good show.
July 9th, 2007
Good trick, thanks for this nice tip.
July 9th, 2007
Normally I would agree this is a time-saving tip. For writing pseudo code on whiteboards, it could definitely make things easier. But, as others have said, getting into the practice of not using the mx namespace will look funny as soon as you start using custom namespaces.
Given that typing the mx namespace takes no time at all when using the auto-completion in Flex (Ctrl-SPACE), which is quite powerful compared to Flash or DW, I would agree with the above that, as a best practice, the mx namespace should be included at all times.
Although from a capabilities standpoint it’s good to know that Flex is ‘flex’-ible
enough to assume the mx namespace has been included if the developer prefers not to use it.
September 14th, 2007
[...] So I was just minding my own business, getting in what little procrastination I could fit into my busy day, and happened upon the blog of one Mrinal Wadhwa discussing his tip that permits MXML without the mx:. Now I know what you’re thinking, and no, Mrinal is not, as far as I know, the kind Namibian man who continues to leave requests in the comments for me to help him transfer millions of dollars of his family’s money out of the country. [...]
February 17th, 2009
I need the code and understanding for a cube panorama using flex and papervision3D
February 27th, 2009
Coll…
Good tip Mrinial.. i will definitely try this….