This content has been marked as final. Show 4 replies
Why would you create a dynamic mxml file rather then just using the built-in actionscript api methods for addChild(), addChildAt(), removeChild(), etc...?
The problem with creating the mxml file at runtime, is that before you can use it, it must be compiled.
MXML is just convenience, that adobe was kind enough to provide, at runtime mxml turns into AS, which further turns into bytecode, so you dont need to create mxml files, if you look into api ref docs most of the AS major components have mxml equivalent, for example HTTPService etc ..
everything that you do in MXML you can do directly through AS (theoretically at least) :) .if you pass compiler parameter -keep-generated-files (or something like this) after build you will see all generated as that is result of your mxml files.
so MXML is kind of like a mythical source code :).
you can create components like Hob, suggested instantiate it and the use addchild()
Well I create charts at runtime and I find it much easier to create a MXML file that can be saved to the local disk (I'm building AIR application) and open at later time by the user. At the same time I would like to use the compiler to visualise the chart. Right now I'm building an XML file that describes the chart through the steps and then I have to create methods that build the chart from this XML file. It would be half of the work to just build a MXML file(and class) and then tell the Flex compiler - compile and instantiate this class.
Hob: I suppose that the MXML file has to be compiled that leads to a question - can you tell the compiler to compile any source at runtime ?
In order to invoke the compiler you would have to be able to run system commands from your app. If this is a Flex app, that's not too hard. You just have whatever server technology your using spawn a system process and invoke the compiler.
From AIR its more difficult. It has no ability to spawn system processes, so you'd have to use Merapi. Merapi is a java/AIR bridge. Basically, the way it works is, you launch a java process which in turn launches your AIR app. Air can then communicate with java by generating system output.
Merapi has a set of APIs in both Java and AS3 to facilitate all of this, of course. Once you have it working, you can write java code to invoke the compiler.
All in all, I'd say it would probably be less work to just write your own domain specific xml variant that you can then parse at run time and create charts from.