I just finished writing my own collecion class, and i'd really like to make it iterable with the for each or the simple for construct, or just to access elements with the collection[key] notation.
I've written a getElementAt(index):MyOwnElement
function, but using it, is not as sexy as using the square brachets, don't even let me start on iterating..
Is there any way?
You should take a look at mx.utils.Proxy
-- subclassing your collection class from that (and setting it as dynamic) might give you access to some of the functionality you want (or at least something that's close enough.)
For example, here's an excerpt from the documentation of the nextValue()
method:
"Allows enumeration of the proxied object's properties by index number to retrieve property values. However, you cannot enumerate the properties of the Proxy class themselves. This function supports implementing
for...in
andfor each..in
loops on the object to retrieve the desired values."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With