AS3: how to find out if the data provider or its content (s) has been changed

I am implementing some kind of combobox control (expanding spark.components.supportClasses.DropDownListBase)

Now, inside this control; I need to know:

  • if the dataprovider is modified / assigned. (what can I do ... the first approach below works);
  • if any item in the dataparavir collection has changed.

I tried 2 methods that didn't do the trick ...

1st APPROACH:

        [Bindable("collectionChange")]
        override public function set dataProvider(value:IList):void
        {
            if (value) value.addEventListener(CollectionEvent.COLLECTION_CHANGE, onDataChange);

            super.dataProvider = value;
            trace("DATA CHANGED"); //fires
        }

        protected function onDataChange(event:CollectionEvent):void
        {
            trace("COLLECTION ITEM(S) CHANGED"); //does not fire
        }

2nd APPROACH:

Since it is based on DropDownListBase; should he send the event CollectionEvent.COLLECTION_CHANGEalready.?

        public function myClass() //constructor
        {
            addEventListener(CollectionEvent.COLLECTION_CHANGE, onDataChange);
        }

        protected function onDataChange(event:CollectionEvent):void
        {
            trace("DATA CHANGED"); //does not fire
        }

Any ideas?

UPDATE: Edited above. The first approach allows me to find out if the data provider is changed, but not if any element is updated in the data collection. The second approach does not work at all.

+3
source
1

, , .

  • dataprovider /.

. , , ? ( , ?). , , dataProvider.

, myClass collectionChange.

2, - .

. . , collectionChange. , , , - . , MXML.

, . :

(collection.getITemAt(x) as myObject).property = newValue;

- :

  var myObject : MyObject = collection.getITemAt(x) as myObject
  myObject.property = newValue;
  collection.setItemAt(x, myObject);

, collectionChange, .

, dropDownListBase: , , itemRenderers , dataProvider. - " ", , , [ dataProvider.

+1

Source: https://habr.com/ru/post/1784608/


All Articles