Creating Secure Collection Types in Flex

I am trying to create a collection class in Flex, which is limited to distributing the specific type of data that I use (interface). I decided not to extend the ArrayCollection class, since it is too general, and actually does not give me the compilation time that I need. In a simplified form, my collection contains an array, and I control how objects are added and removed, etc.

What I really want is to use these collections for each loop. It definitely doesn't look as straight forward as C # says, where you just implement IEnumerable and IEnumerator (or just use the Generic collection). Is there a way to do this in a script action, and if so, what information is on how this is achieved?

Greetings

+4
source share
2 answers

You need to extend the Flash Proxy class. The proxy extension allows you to change the operation of "get" and "set", as well as "for..in" and "for..each". You can find more information at Livedocs.

Here is an example of your problem:

package { import flash.utils.Proxy; import flash.utils.flash_proxy; public class EnumerableColl extends Proxy { private var _coll:Array; public function EnumerableColl() { super(); _coll = [ 'test1', 'test2', 'test3' ]; } override flash_proxy function nextNameIndex( index:int ):int { if ( index >= _coll.length ) return 0; return index + 1; } override flash_proxy function nextValue( index:int ):* { return _coll[ index - 1]; } } } 
+2
source

Take a look at Vector<> . This is about as good as you can go for a typed collection in Flex (4 years). Otherwise, however, you will need to implement your own class. Apparently, one way is to use the Iterator Pattern .

Also, see this SO post.

+2
source

All Articles