« Stopping Flash 4 SWF with Sound in Flex 2 | Main | Credit Card Debt Take II »

mx_internal

Sometimes you want to change the behavior of a Flex component but its hidden behind a private method or variable so you can't subclass it. Thankfully they provide the source so you can just create your own version. This is heavy handed and in some cases you just need to tweak things a little. Many components within the Flex framework have methods and properties flagged as mx_internal. These you can access without having to do anything too funky.

As an example lets change the restrict set on the input field of a NumericStepper.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.core.mx_internal;
use namespace mx_internal;
private function setupStepper():void
{
    stepper.mx_internal::inputField.restrict = "0-9";
}
]]>
</mx:Script>
<mx:NumericStepper id="stepper" creationComplete="setupStepper();"/>
</mx:Application>

The key things to note are:

  1. import mx.core.mx_internal;
    Import the namespace that is going to be used

  2. use namespace mx_internal;
    Tell Actionscript that is a namespace

  3. mx_internal::inputField
    Prefix the property name with its namespace

That's all there is to it. Happy hacking.

Tags: flex mx_internal namespace

Comments

Good entry. I use this occasionally, but often forget the exact syntax. I'm going to link to this from my blog so I have a reference :)
Thanks for your hint.
A shortcut for the same result would be to create a QName as in: prop:QName = new QName(mx_internal, "my_property"); then use it like so: FlexComponent[prop];
This is good but be careful as 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. So good to use only those properties which can be override or defined as public.
thanks for that post :)
Hello Raghu, Nice explain but can u pls tell me if I want to use column numer property of Contextmenuevent how can I use it. coLNum is mx_internal property of datagrid column I want to access column index on which datagrid column context menu is click. mx_internal:: event.mouseTarget.data.colNum; Thanks

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)



About