Actionscript – Manually dispatch a collection change event

actionscriptapache-flexflex4

I have a standard combobox that dispatches a collection event when the dataprovider finishes initializing:

my_cb.addEventListener( CollectionEvent.COLLECTION_CHANGE, getMyStuff );

Then I have a custom component that also has a dataProvider. How do I get it to dispatch a collection change event when its dataprovider finishes loading?

From what I've read, I can't do it. Will dispatching a propertychangeevent work?

Thanks for any helpful tips!

UPDATE:

I have a custom component that I call 'SortingComboBox' but it is not a ComboBox at all; it extends Button and I set is dataProvider property to my arraycollection, model.product (which is an arraycollection).

And here is how I use the dataProvider in that component:

code

[Bindable]
private var _dataProvider : Object;

    public function get dataProvider() : Object
    {
        return _dataProvider;
    }

    public function set dataProvider(value : Object) : void
    {
        _dataProvider = value;

    }

code

In the createChildren() method of this component, I use this:

BindingUtils.bindProperty(dropDown, "dataProvider", this, "dataProvider");

The dropDown is a custom VBox that I use to display labels.

Best Answer

When you call the setter, you have to make sure

1) that you actually are changing the value with the setter. So even if you are inside the class, call this.dataProvider = foo instead of _dataProvider = foo

2) The binding will not trigger unless you actually change the value. If you trace you'll see that the setter actually calls the getter, if the values of what you pass into the setter and the getter are the same, the binding will not occur.

Your other option is to put an event on the getter, then just call it to trigger the binding.

[Bindable( "somethingChanged" )]
public function get dataProvider() : Object
{
    return _dataProvider;
}

dispatchEvent( new Event( "somethingChanged" ) );
Related Topic