I am working with a project already in place. It uses Cairngorm and is
built on Flex 3.0.2.2113
A standard ComboBox is implemented in one of the views like so:
<mx:ComboBox dataProvider="{model.facilities}" id="Facility">
"model" is a bindable singleton, and one of its properties, "facilities"
is a public ArrayCollection. On initialization, a function runs in the
singleton to populate facilities; it does this by pointing
model.facilities to another ArrayCollection that has been previously
populated, such as:
model.facilities = model.assigned_facilities;
This works without issue; when the application starts, the ComboBox is
properly populated with the values pointed to by model.facilities.
I have decided to come in and build a subclass of ComboBox in
ActionScript, and rather than pass the dataProvider in, I want to
include the singleton within the ActionScript, and simply do the same
assignment in the constructor. The resulting MXML would look like this:
<components:FacilityComboBox id="Facility" />
and the constructor would look like this:
public function FacilityComboBox(){ super();
BindingUtils.bindProperty(this, "dataProvider", model, "facilities");}
My question is: Is this the best practice when subclassing a UIComponent
and wanting to handle the dataProvider assignment internally? The reason
I ask is, I had originally built the constructor like this:
public function FacilityComboBox(){ super(); this.dataProperty =
model.facilities;}
which worked for other subclassed ComboBoxes where the dataProvider *did
not change after initialization*. However, because of how
model.facilities is assigned (to an existing ArrayCollection), no change
was ever detected, and upon launch the application, the ComboBox sat
dormant and never received any values to populate. Changing to the
BindingUtils method solved this problem, but I now fear I'm missing a
much broader concept about dataProvider assignment in pure ActionScript
classes. Is my BindingUtils methodology the one to go with? Or should I
be considering something drastically different?