What is mx_internal ?

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…

  1. Switch to Flex Debugging View
  2. Use the following code
      <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”&gt;
      <mx:Script> <![CDATA[
      public function debug():void{ } ]]>
      </mx:Script>
      <mx:VideoDisplay id=”vid”/>
      <mx:Button label=”Debug” click=”debug()”/>
      </mx:Application>
  3. 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
  4. 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…

  1. 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;
  2. Tell Actionscript that is a namespace
      use namespace mx_internal;
  3. 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.

About these ads

6 Responses to What is mx_internal ?

  1. Raghu, A vary nice explanation.

    Just to add the customary 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

  2. Paul D says:

    If “mx_internal” is for things that may change in future versions, how important is the “_parent” of UIComponent?

    /**
    * @private
    * Reference to this component’s virtual parent container.
    * “Virtual” means that this parent may not be the same
    * as the one that the Player returns as the ‘parent’
    * property of a DisplayObject.
    * For example, if a Container has created a contentPane
    * to improve scrolling performance,
    * then its “children” are really its grandchildren
    * and their “parent” is actually their grandparent,
    * because we don’t want developers to be concerned with
    * whether a contentPane exists or not.
    */
    mx_internal var _parent:DisplayObjectContainer;

  3. Tom says:

    I cant believe that we have to hack all the time the framework! Why they didn’t declare these fields as public?? For the videoplayer the smoothing is very important and every time you need to extends components to access protected or mx_internal fields.

    Is there a performance issue between public/protected/mx_internal??

  4. amar shukla says:

    i am a newbie in flex !
    can you tell me what is the use of using it as its already default namespace inside flex ???
    As i got to know about it that its just to define the scope as public/protected/internal …
    so why to use this explicitely as mx_internal var xyz:string ;

    instead we can use internal var xyz:string;
    what is the need of using mx_internal ?
    can you please explain it to me Raghu ?

  5. Toby Ho says:

    Nice! This info was just what I needed. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.