Include namespace in component declaration

I came across this while I recently played around with the Google Maps API for Flex. When you have a look at the example you see how they declare the map and realize that the namespace is declared within the component.

So let’s assume you have a TinyComponent implemented in the package and you use it in a view which extends Canvas.

Instead of:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx=""
	<components:TinyComponent />

you can write:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="">
	<components:TinyComponent xmlns:components="*" />

The advantage with this approach is that you can leave out the namespace declaration wihtin your MXML class in which your component is declared. If you for instance refactor the TinyComponent to another view you would have to remove the namespace from the old view and add it to the new view. If you declare the namespace within this task is obsolete and your wrapping components namespace declaration are a lot cleaner. Off course this concept does not apply for all use cases but I started to use it for custom components which I use a lot so it is easier to add them to another container without worrying about namespace imports.

2 comments to Include namespace in component declaration