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:

import package.ClassName;

For example: Say you have an MXML file: com.foo.FooBar.mxml; your import statement would look like:

import com.foo.FooBar;

Similarly, to import a class or another MXML file into an MXML file you would use the xmlns parameter:

<mx:RootNode xmlns:namespace="package">

Using the FooBar example:

<mx:Application
xmlns:mx=http://www.adobe.com/2006/mxml
xmlns:fb="com.foo.*">

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

<fb:FooBar>

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!

-erik

Posted by erikbianchi at 08:33 AM | Comments (0)

February 03, 2009

[Flex Tips] Flex Tips Introduction

Since I'm the kind of guy who needs structure and a reason to blog I've decided to create a new series of articles on my site akin to my Flash Quirks post: Flex Tips.

Flex Tips will be a place for me to store lessons learned and serve as a jump start to Flash Developers making the transition into Flex as I did but will hopefully help some of you native Flex dudes too.

I've got a number of different topics planned and will be sending out my first batch of tips in the coming days.

Also, for those who missed my original post, I'm back in the Flash / Flex consulting game and taking on new projects. To check out my previous "whats happening post" follow this link: http://www.erikbianchi.com/archives/2009/01/index.html

-erik

Posted by erikbianchi at 06:53 AM | Comments (0)