Reputation: 44181
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; }
Upvotes: 0
Views: 886
Reputation: 10423
Initially I thought:
The mx:Binding
source should be the field name itself, not the value. Flex is complaining because it is dereferencing myObj.prop
because of the {}
and seeing the value there (a Number
) when it wants a string with the field name.
<mx:Binding source="myObj.prop" destination="combobox.text" />
However:
ActionScript inside curly braces is allowed in the mx:Binding
source expression, and is required in this case. See Adobe's data binding examples.
The text
property is expecting a String
to be assigned to it, so you will want to cast in your binding:
<mx:Binding source="{String(myObj.prop)}" destination="combobox.text" />
My apologies for the initial misleading answer, hopefully this is on the right track.
Upvotes: 1