2

In Java, this can be done with LinkedHashMap by removing eldest entry/oldest accessed entry. Any equivalent class in ActionScript 3?

Thanks.

Community
  • 1
  • 1
Lee Chee Kiam
  • 11,450
  • 10
  • 65
  • 87

1 Answers1

1

No, unfortunately not. You could easily implement one, if I were going to implement it I would extend the Proxy object It'll give you a fair bit of flexibility.

UPDATE:

This update is to clarify on the question in the comment by the OP. Comment was "It will be a new class extends Proxy and not Dictionary/etc?"

Yes, you would want to extend Proxy, the reason for this is that it allows you to override several magic methods to accomplish your goal. Particularly in your case, you can override setProperty(name:*, value:*):void. This method will be called every time a property is set on your class (its up to you to supply the set implementation) so you can count the number of values that are set at a given time. If you extend Object or dictionary, you do not have access to this, and have know way of knowing when a new property is set.

If you extended object instead, you would need to rely on an interface to to acheive your goal, requiring user to set properties through method calls.

A Proxy implementation would allow you still set properties like this:

myObj.foo = 'bar';
myObj["foo"] = 'bar';

A method implementation (extending Object) would look like this:

myObject.setVal("name", "val");
Tyler Egeto
  • 5,505
  • 3
  • 21
  • 29
  • It will be a new class extends Proxy and not Dictionary/etc? I am new to ActionScript and very appreciate if someone create a ready to go class to be shared... – Lee Chee Kiam Feb 13 '11 at 13:51