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.
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
}
}
精彩评论