I’m trying to databind an object’s property to a ComboBox’s (editable=true) text property. This property is of type Number.
If I bind using the inline syntax, it works:
<mx:ComboBox text="{myObj.prop}">
If I bind using mx:Binding, I receive an error:
<mx:Binding source="{myObj.prop}" destination="combobox.text" />
// 1067: Implicit coercion of a value of type Number to an unrelated type String.
Why this difference in behaviour?
Property definition:
private var _prop: Number;
[Bindable] public function get prop(): Number { return _prop; }
public function set prop(value: Number): void { _prop = value; }
Initially I thought:
The
mx:Bindingsource should be the field name itself, not the value. Flex is complaining because it is dereferencingmyObj.propbecause of the{}and seeing the value there (aNumber) when it wants a string with the field name.However:
ActionScript inside curly braces is allowed in the
mx:Bindingsource expression, and is required in this case. See Adobe’s data binding examples.The
textproperty is expecting aStringto be assigned to it, so you will want to cast in your binding:My apologies for the initial misleading answer, hopefully this is on the right track.