I was reading through my blog roll this morning (and when I say this morning I really mean early afternoon because I am off) when I came across a very interesting post. We have all either used flex or at the very basics have seen some MXML code. Here is a quick hello world example that just puts a button on the screen.
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Button label="Hello World!"/> </mx:Application>
Nothing special going on there right. Mrinal Wadhwa has a great article about writing flex applications without the mx prefix to each of the tags. All you have to do is simply change the application tag to match the one below. Then all of your tags can be written without using mx: prefix. I thought well this is great but I am still a newbie and really need the code insight that Flex Builder offers. To my amazement you still have your code insight. Mrinal offers up a couple of reasons on why this approach is better and in my opinion I could not agree more.
- I think this makes the code a lot cleaner
- There are many who do not use Flex Builder and for them this saves a lot of typing.
Here is the new code, go ahead and change your application tag to the following and have fun saving time. What a great tip Mrinal!
<?xml version="1.0" encoding="utf-8"?> <Application xmlns="http://www.adobe.com/2006/mxml"> /* now you can use the tags without mx prefix and code hinting still works */ <Button label="Hell World!"/> </Application>

#1 by Simeon on 7/6/07 - 1:54 PM
I like using the mx namespace because it creates a look of consistency through my application.
#2 by Dan Vega on 7/6/07 - 2:00 PM
#3 by Mrinal on 7/6/07 - 2:34 PM
I'm very glad you like the tip. This will not cause any problem when you start using other namespaces for your custom components,
Simeon,
I guess its a question of preference .. one point to add though (for people who are new to this) is that even when inside components you can still follow this approach ... for example when you are inside a component inheriting from a Canvas you could set the namespace in the canvas tag as xmlns=" and then the code of the component will be mx free as well ... so I think things are consistent enough ... again this is a preference thing.
#4 by Evert on 7/6/07 - 3:09 PM
This is really an XML namespaces discussion, instead of a Flex one.. I would want to suggest to anyone who uses MXML to understand how XML works and read up on for example XML namespaces.
#5 by Josh on 7/6/07 - 5:46 PM
#6 by Tony on 7/6/07 - 5:54 PM
To me the prefix conveys userfl information about where the classes come from, and sister classes in the same project shoud have no prefix, and classes from the framework should be maked as such.
Just my $0.02
#7 by Tink on 7/6/07 - 6:29 PM
"e inside a component inheriting from a Canvas you could set the namespace in the canvas tag as xmlns=" and then the code of the component will be mx free as well ... so I think things are consistent enough"
So when you come to use this custom component in another class, along with Adobe components and a couple of others u have created in diff packages, your back to having to use namespaces (or back to having a mix which I would really try to avoid).
"Please remember that I am a Flex newb and from very basic applications this seems easier to me"
Start as you mean to go on and don't get into bad habits!
#8 by Mrinal on 7/7/07 - 8:25 AM
I do not agree on the consistency point ... I do see that the mx prefix obviously states that all tags starting with mx prefix represent classes from the flex framework ..... but the same message could very easily be conveyed by not using any prefix for classes from th flex framework .... many other XML based languages do it that way (XHTML, XUL etc) ... the default name space does not have any prefix and everything else does ...... to me these languages seem quite consistent and readable.
One point against this approach that I do agree to is this .... If your code s going to be public facing and absolute novice flex programmers are going to look at it ... then this approach may throw them off a bit as all the mxml that they have seen until this point used mx prefix and your code does things differently.
So i still think its a preferences thing.
#9 by Keith Peters on 7/9/07 - 11:14 AM
#10 by joeflash on 7/9/07 - 12:35 PM
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.