So im creating a library that holds a bunch of myObjects. I ‘register’ these objects and give them a label(String) so I can access them later. There’s 2 ways I can do this easily:
[AS]var library:Dictionary = new Dictionary();
//set reference (takes MyObject)
library[myObject.label] = myObject;
//get refernce (takes string, returns myObject)
return library[“label”][/AS]
[AS]var library:Object = {};
//set reference (takes MyObject)
library[myObject.label] = myObject;
//get refernce (takes string, return myObject)
return library[“label”];[/AS]
Though, I honestly think the best way to handle these objects would be using a Vector, that way I keep the object’s type. This would require more work though, having to store an id.
[AS]var library:Vector.<MyObject> = new MyObject();
//set reference (takes MyObject)
var id:int = getID()
myObject.id = id;
library[id] = myObject;
//get reference (takes string, returns myObject)
for(var i:int = 0 ; i < library.length;++i){
if(library*.label == “label”)
return library*;
}[/AS]
What do you guys think?