May 19, 2007


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="" layout="vertical">
import mx.core.mx_internal;
use namespace mx_internal;
private function setupStepper():void
    stepper.mx_internal::inputField.restrict = "0-9";
<mx:NumericStepper id="stepper" creationComplete="setupStepper();"/>

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