February 05, 2009
[Flex Tips] Importing MXML into ActionScript and Vice Versa
I get this question a lot from Flash peps first coming into Flex so figured I should make this my first real tip.
At compile time, MXML files actually get converted to ActionScript so the only real difference between ActionScript and MXML is the syntax. Under the hood, it’s all the same.
To import just rock the import statement like you would for any other class:
For example: Say you have an MXML file: com.foo.FooBar.mxml; your import statement would look like:
Similarly, to import a class or another MXML file into an MXML file you would use the xmlns parameter:
Using the FooBar example:
From there on out, you can reference your FooBar class or any other file inside the com.foo package (MXML or AS) by typing in the namespace you created in the xmlns parameter
Something to watch out for (and still bites me in the rear on occasion) is to make sure you import using the wildcard (.*) at the end of package in the MXML file.
More to come!
Posted by erikbianchi at February 5, 2009 08:33 AM