tags:

views:

14

answers:

1

Hi I have a text field which I would like to bind to a dynamic object.

<mx:TextInput id="ti4" text="{selectedObj['someProp']}" valueCommit="{selectedObj['someProp'] = ti4.text}"  x="1011.5" y="835"/>

If the property doesn't exist I get a reference error - Is there any way to fail a little more gracefully?

Any ideas much appreciated.

+1  A: 

You could wrap your accessor in a method which uses a try block to catch the reference error and return some reasonable default value.

<mx:TextInput text="{getMyProperty(selectedObject, 'someProp')}" ... />

...

protected function getMyProperty (fromObject:Object, propName:String):* {
    try {
        return fromObject[propName];
    } catch (err:Error) {
        return ""; // default value
    }
}
lach
Thanks, thats what I pretty much ended up doing.
Chin