I have xml-structure where I load most of the data of my program. In this case I want to instantiate a class which is specified in xml. I figured that I could write class' name in xml, and then instantiate it and pass parameters to it. Turned out it wasn't that easy!
I tried code like this:
//special objects
for each (o in xml.Objects[0].special)
{
p.x = o.@x;
p.y = o.@y;
s.x = o.@width;
s.y = o.@height;
trace(o.@classname);
//var type:Class = o.@classname as Class;
var type:Class = getDefinitionByName(String(o.@classname)) as Class;
trace(type);
objectArray.push(new type(p, s));
trace("special");
}
As you can see I have the name of my class in classname attribute in xml-file. I managed to get the definition with getDefinitionByName (at least next trace shows correct class name) but when I try to instantiate it and push it into array I get pile of errors which begin
Error #2136: The SWF file file:///Users/tuomas/Dropbox/Flash/ScorpionBox/bin-debug/ScorpionBox.swf contains invalid data.
Any idea how I should go with this?