Instantiate a class from a dynamic variable
Hi everyone. I am just working on a little tilebased project, and I would like to be able to place any of my tile objects with one bit of code.
Right now I've just got this in my left click function:
__________________________________
if(tileType == "grass"){
var grasstile:grass = new grass;
addObj(grasstile, absMX, absMY);
}else if(tileType == "dirt"){
var dirttile:dirt = new dirt;
addObj(dirttile, absMX, absMY);
}
__________________________________
Where tileType is a variable that changes depending on what tile the user has select from the menu, and addObj is a custom function for adding objects.
However there are many tiles, and I'd much prefer to be able to use one bit of generation code rather than duplicating it over and over again for every tile.
Is there a way to do this?
Thank you very much for your time.
Brendan
