Oct 2, 2008

What is mx_internal?

Here, I am going to tell you about the mx_internal namespace. You often come acrosss this work when you open any flex component.  I have used mx_internal namespace a couple of times, but I swear to god I have never understood what it means or why it is used. So I decided to plunge in a little bit and make some sense out of it.
So I decided to plunge in a little bit and make some sense out of it.

Before I get to that, it makes sense to discuss a little bit about namespaces. Namespaces are essentially used to limit the scope of methods, classes, variables or constants. One could say that they are used to avoid potential naming conflicts that may arise with other components having the same names. Namespaces are associated with a Uniform Resource Identifier that identifies the namespace. You can find more information on namespaces here.

Now, mx_internal is one such namespace that the Flex SDK uses to handle internal data. Just like all other namespaces, mx_internal contains a lot of variables which we can use in our code. To know which variables belong to mx_internal, dig into the Flex SDK code and you can find them. An example of the use of mx_internal can be found in the TextInput.as class of the Flex SDK. Some commonly used mx_internal variables/methods of this class are:

/**
* The internal subcontrol that draws the border and background.
*/
mx_internal var border:IFlexDisplayObject;

————————————————————————————–

mx_internal function get selectable():Boolean
{
return _selectable;
}

To you the mx_internal namespace, just import it and let Actionscript know you are using it.

import mx.core.mx_internal;

use namespace mx_internal;

You are then ready to use the variables of mx_internal.

Of course there are some issues with using this namespace. First there is no code hinting in Flex Builder when using this namespace. That means you have to dig yourself to know which variables are present in the namespace. Second, Adobe has mentioned this warning with using the namespace.

“This namespace is used for undocumented APIs — usually implementation details — which can’t be private because they need to visible to other classes. APIs in this namespace are completely unsupported and are likely to change in future versions of Flex.”

That means that the next time Flex updates happen and your code doesn’t work as it is supposed to, don’t blame Adobe.

Thanks,
Shaleen Jain

No comments:

Post a Comment