I would like to su开发者_如何学Cbclass an Array
or Vector
to dispatch and Event.CHANGE
when any elements value changes.
How would I go about doing this?
How about using an ArrayCollection and listen to the CollectionEvent (mx.events.CollectionEvent.COLLECTION_CHANGE)
/** * Dispatched when the ICollectionView has been updated in some way. * * @eventType mx.events.CollectionEvent.COLLECTION_CHANGE * * @langversion 3.0 * @playerversion Flash 9 * @playerversion AIR 1.1 * @productversion Flex 3 */ [Event(name="collectionChange", type="mx.events.CollectionEvent")]
There is two ways of approaching it, if you want to create your own collection: 1) Extend Array class, and use method like updata(index:int, value:*) to update data in it instead of array accessors (myArray[i] = newValue). And in update method you can dispatch change event. This might make your code less concise.
2) Extend Proxy and override setProperty and getProperty methods in flash_proxy namespace. This will allow you to use array access operators ([key]), downside is – Proxy is slow.
There is number of ready open source collections based on proxy out there.
精彩评论