Currently, I have two classes MC_Dictionnary_Bad, and MC_Dictionnary_Good, initialized like so:
package classes
{
import flash.utils.Dictionary;
public dynamic class MC_Dictionnary_Bad extends Dictionary
{
public function Custom_Dictionary()
{
this["monster,0,0,0"] = "Monster_Light_Swanp_Red";
this["monster,0,0,1"] = "Monster_Light_Swanp_Blue";
this["monster,0,0,2"] = "Monster_Light_Swanp_Yellow";
this["monster,0,0,3"] = "Monster_Light_Swanp_Dark";
...
}
}
}
They are initialized during loading, and are saved like so during the entire game.
I need to link a name and three indexes to class names, so I can create the appropriate class when needed, given user input.
However, I don't want to use a dynamic class.
Is there a clean way not to use a dynamic class here?
There's no need to extend Dictionary
for this model - simply have two dictionaries in a class:
package {
import flash.utils.Dictionary;
public final class Game {
protected var MC_Dictionnary_Bad:Dictionary = new Dictionary();
protected var MC_Dictionnary_Good:Dictionary = new Dictionary();
public function Game() {
initialize();
}
protected function initialize():void {
MC_Dictionnary_Bad["monster,0,0,0"] = "Monster_Light_Swanp_Red";
MC_Dictionnary_Bad["monster,0,0,1"] = "Monster_Light_Swanp_Blue";
MC_Dictionnary_Bad["monster,0,0,2"] = "Monster_Light_Swanp_Yellow";
MC_Dictionnary_Bad["monster,0,0,3"] = "Monster_Light_Swanp_Dark";
}
}
}
If your keys are always strings, this could be defined as JSON
which would also enable easy data loading. Instead of embedding the object in your app, it could be loaded from a url and parsed.
package {
public final class Game {
protected var monsters:Object = {
"good": {
"monster": {
0: {
0: {
0: "Monster_Light_Swanp_Red",
1: "Monster_Light_Swanp_Blue",
2: "Monster_Light_Swanp_Yellow",
3: "Monster_Light_Swanp_Dark"
}
}
}
},
"bad": {
/* etc... */
}
};
public function Game() {
// Example accessor:
trace(monsters["good"]["monster"][0][0][1]);
}
}
}