开发者

For Each In enumeration for custom data set classes

开发者 https://www.devze.com 2023-04-11 17:15 出处:网络
I have a pretty standard implementation of a开发者_如何学Go circular, two-way linked list. For arrays I\'d generally use for each in to go through each element without need to worry.

I have a pretty standard implementation of a开发者_如何学Go circular, two-way linked list. For arrays I'd generally use for each in to go through each element without need to worry.

The problem is with my custom Linked List which cannot be looked through with simple call. I'd guess, if there is a Proxy class in AS3 there are high chances the Adobe team came up with an idea to implement, I don't know... Enumerable class or something? Nevertheless my search turned out nil.

Is there a way to make For Each In work with a custom class in Flash? Not to go through all of the object's properties but go through the whole data set represented by this class.


You can read this post about Proxy class in my blog. You can find examples of implementing "for each" logic.


Yes, you are correct, check out the Proxy class.

Specifically the nextName, nextNameIndex, and nextValue methods will be of interest.

As long as you have easy access your list's elements by index you should be able implement the for...in loop.


You should implement custom hasNext() and next() metods, and just iterate through object list

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号