Traditionally in OOO languages access specifiers are used to control visibility of declarations (public, private, protected). Now with XML based languages like MXML making debut, a new mechanism for controlling visibility of declarations has evolved… using namespaces. Namespaces are essentially custom access specifiers, which can have names of your choosing. Namespaces are outfitted with a Universal Resource Identifier (URI) to avoid collisions, and are also used to represent XML namespaces when working with E4X.
What I’m interested in discussing here is an internal namespace that FLEX framework uses for its internal data, called mx_internal. A lot of variables in Flex are mx_internal variables and are available to the developers if they use the mx_internal namespace. Before we go into the details of how to use them… lets look at how to identify these variables. There are 2 ways to do this…
One is the straight forward way of looking into the source. Since Flex is Open Source and comes bundled with the source code.. one can easlily locate these variables in the source. For example, under the class defenition of VideoDisplay.as, you can see the an mx_internal variable called videoPlayer (of type VideoPlayer, which in turn extends from flash.media.Video)
mx_internal var videoPlayer:VideoPlayer = null;
This way of identifying mx_internal variables is not always effective, so a better way is to use FlexBuilder to identify them. This is what you need to do…
- Switch to Flex Debugging View
- Use the following code
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”>
<mx:Script> <![CDATA[
public function debug():void{ } ]]>
</mx:Script>
<mx:VideoDisplay id=”vid”/>
<mx:Button label=”Debug” click=”debug()”/>
</mx:Application>
- Make sure that you can view the mx_internal variables in the debugging mode. You can do this by checking the options in the debug Layout as below
- Now put a break point in the debug() function and run the app in the debug mode. Click on the button to come to the debug view and add a watch for the VideoDisplay object. You’ll see the following in the debug view, when you search for videoDisplay under the watched vid variable…
The variables are color coded as below
- Red Rectangle – private
- Green Circle – public
- Yellow Rhombus – mx_internal
- Char codes “C” & “S” – constants and static vars
Now you have identified the mx_internal variables that you need to use. Now lets see how to use them. This is a 3 step process…
- Import the namespace that is going to be used. Note that this needs to be done after all other imports
import mx.core.mx_internal;
- Tell Actionscript that is a namespace
use namespace mx_internal;
- Prefix the property name with its namespace
vd.mx_internal::videoPlayer.clear();
Thus you can now access and use the mx_internal variable and all its properties, methods, styles etc. I’ll tell you about some scenarios where this is most useful in the coming posts. Hope this makes your job easier 🙂
Addendum (4th Sep ’07) :Â As rightly pointed out by Mrinal…. I should add this disclaimer.
Adobe uses the mx_internal namespace to mark things that may change in future versions of the framework .. So you have to use it at your own risk, because your inherited class or component may not work with future releases of Flex.