Saturday, June 11, 2011

Namespaces in Flex 4

Today we continue learning Flex, and look deeper into the namespaces.

In the previous tutorial we've learned a bit about namespaces. So far we know that there are 3 namespaces in Flex 4 - mx, fx and s. We know that each of them references a library of code in the Flex framework.

Now let's take a look into the flex sdk folder to have a little better understanding of these namespaces. Go to wherever your flex sdk is located on your computer, then go to the framework folder. You will see these files:

Open the air-config file, and scroll down a little until you see the namespaces node. Here's what it looks like:

You can see that there are 4 namespace tags in this node, and each of them has two properties - uri and manifest. The uri is, if you remember, the string values that are used in our mxml file when declaring the namespaces:

You can see that in our mxml file, we only declare 3 namespaces, while there are 4 in the xml config file. This is because the fourth element is used for the older version of flex.

The manifest tags contain the url to the xml file that contains all the data of this namespace. These xml files can also be found in the same directory as air-config.

If you open the mxml-manifest file, you can see a lot of lines like this:

And you can probably find already familiar to you classes here, for example: the Button class. The mxml-manifest file contains all the MX component tags (which can be found in the mx-manifest file) plus Actionscript built-in types, such as String, Number, Boolean, and so on.

Now, if you open the spark-manifest file, you will notice that it has a lot of similarities with the mx-manifest file. It has a lot of similar classes (for example, the Button class) with the exception being the spark. instead of mx. in the beginning of the class path.

A question appears: why are there similar elements, like the Button component, both in the mx and s (spark) libraries?

Both of the components from the mx and the s libraries look exactly the same by default. The difference is that the components from the spark library are much more customizable. The spark library was introduced in Flex 4, and it is recommended to use the spark components instead of mx components when possible.

That's all for now.

Thanks for reading!

No comments:

Post a Comment