Based on what you're asking, it sounds like you're attempting a type of Factory-pattern (Factory Method) where a class is responsible for dynamically generating objects based upon information given from an external source.
I would recommend looking into Design Patterns for Flex and ActionScript. I haven't written a Factory Method in Flex yet, but it can't be much harder than Java, which isn't too bad.
In general, here's what I would expect your program to look like:
- Your XML describes the object which will be generated (class type, params, etc.). Your example appears to show this.
- You have an XSD which can verify the XML file conforms to your program's expectations -- if it doesn't, an appropriate error would be outputted. I would highly recommend something along these lines for validation: you need to have a mechanism which guarantees the XML is correct.
- You've abstracted the values you are expecting to be in the XML. I would recommend using Enums or static/constant String values in a separate utility class.
- You have a Factory class whose sole responsibility is to take in the XML data, generate the objects based upon the contents, and return it to whoever needs it.
The 4th point, obviously, is what you are looking or (I think). CookieOfFortune's example shows what this Factory Method might look at. I would, however, recommend you also abstract out the String values into a variable or Enum:
...
var BALL_CLASS_TYPE:String = "Ball";
...
function createNewClass(var name:String):Object {
if (name == BALL_CLASS_TYPE)
return new Ball();
}
Your first parameter, however, is confusing to me. It sounds like you're trying to create a dynamic object with a dynamically-named reference to it (e.g. var <x>:Object where <x> is defined as data in the XML). I don't know if this is even possible. I would certainly think it not necessary.