This content has been marked as final. Show 2 replies
Flex has its MXML language, but I don't believe you can load interfaces at runtime like that. They're translated into ActionScript code during compilation, so for it to work the same way, the MXML to AS compiler would have to ship with Flex apps. That doesn't seem likely to me.
You might have the freedom to rebuild the application when the XML changes. You might not even know you have this freedom yet. :) (Kind of like being in the Matrix and not knowing it.) If so, you can translate your XML schema into MXML using any of several tools: XSLT, custom code, whatever. Then you can build the app and serve it. Flex comes with an Apache module for doing this, so even if you have to upload the XML and serve the new app immediately, this would still let you do that. You'd basically have an unchanging engine, the XML to MXML translator, and then the Flex Apache module to assemble the whole thing and serve it.
If you can't rebuild the application, it wouldn't be too hard to slurp the XML into a running program, walk the resulting tree and translate the tags found into ActionScript object creation. Flex does let you build user interfaces on the fly, and the strong support for automatic layout makes the a lot less painful than you might initially imagine.
Yes actually you can dynamically type variables in Flash / Flex using something similar to this.
var myDynamicObject:* = whatEverObjectIFeelLikePuttingHere;
Perhaps what might help to accomplish your goal is to use reflection inside of Flex. It is possible to use (although somewhat irritating) reflection in Flex using a form similar to this.
var content:Class = getClassFromPath(objectClassPath);
newComponent = new content();
The only problem is that the compiler will scrub any variables/classes that are not currently being referenced, at least once, somewhere in the application. So somewhere in your application you must have a reference for the class, even if it set to null, so that the class will not be removed from the project.
It's also possible that the describeType function might be of some use.
Here are two references that describe each.
Utilizing these features it's possible to do quite a bit to reshape your application based on data stored outside your application or on parameters only known at runtime.