Binding a visual component to a singleton limits its reuse. So there may not really a best practice. The minimum code way is probably to assign the dataProvider in commitProperties instead of the constructor. The model.facilities might have its final assignment by then.
On 8/25/11 9:41 AM, "hanzo55" <shawn.a.hol...@gmail.com> wrote: 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(); thi! s.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? -- Alex Harui Flex SDK Team Adobe System, Inc. http://blogs.adobe.com/aharui