views:

231

answers:

1

I have a number of GUI dialogs defined using MXML. Assuming these mxml objects have been compiled into my application, is there any way to instantiate these objects using ActionScript, sort of like this?

    myFoo:  Mxml2ActionScriptClass("FOO.mxml") = new AutomagicalMXMLFactory( "FOO.mxml");
    myFoo.addEventListener(etc etc)
    this.AddChild(myFoo);
A: 

Yes. Whatever the file name is for your MXML class, that is the class name you use.

So, if you have an MXML document by the name of "Foo.mxml" , that file will be compiled into a class called "Foo". You can instantiate said class like any other in actionscript, with the "new" keyword.

var myFoo:Foo = new Foo();
whatever.addChild(myFoo);
ZackBeNimble
Thanks, that was a lot easier than I expected. I thought the mxml component would not be available as a class until runtime. :-)
Tim
just make sure you also import the namespace that the mxml file resides in
JTtheGeek