One of my favorite things about Flex Builder is that you can create a pure ActionScript project that extends Sprite. I can’t imagine writing a Flash application these days without doing it in Flex, but this option is great you’re looking for something more lightweight or if it’s a non-UI project such as a SWF bridge to manage old AS1/AS2 content. Other things could be a Papervision 3D project or if you’re playing around with programmic movement or the drawing API.
It’s still a surprise to me that a lot of hardcore Flashers do all of their work in pure AS3 but still haven’t heard of binding. I thought I’d show how you can use binding and other Flex libraries. There is a “gotcha” or two along the way but I plan on explaining those too.
Lets start out by looking at some of the Flex libraries with the Flex SDK. Go into your Flex Builder installation directory and you should see the following folder path:
{FlexBuilder 3 Location}\sdks\3.0.0\frameworks\libs
It should contain some SWC’s like:
flex.swc
framework.swc
rpc.swc
utilities.swc
These are available for you to use in any ActionScript project, you just have to add them. So to add them right click on your ActionScript project and select properties.

This lists the existing build path libraries for the compiler. We’re going to add a few more. So go ahead and click on the button “Add SWC” or “Add SWC Folder”. You can add the entire lib directory we talked about above, but it has additional SWC’s you may not need like the automation testing and QTP classes. I just add them individually. Once you add all of them we now have to add the “locale” folder. This locale folder is used by the libraries for error warnings etc and is specific to the language you specify. So click on “Add SWC Folder” and select a similar location:

Now your properties should look similar to:

Click ok and wait for it to update the compiler settings. So now you’re ready to use binding and all of the Flex libraries! You also now have the code completion and all of the other good stuff that links to the libraries.
We’re not completely out of the woods yet, we do have to cover one more important item about implementing the actual Flex classes. Lets use mx.rpc.HTTPRequest as an example:
var myURLRequest:URLRequest = new URLRequest( tmpString );
var myService:HTTPService = new HTTPService();
myService.method = "GET";
myService.url = myURLRequest.url;myService.addEventListener( ResultEvent.RESULT, onHTTPServiceComplete, false, 0, true );
myService.addEventListener( FaultEvent.FAULT, onHTTPServiceError, false, 0, true );
myService.send();
This is very valid but it’s actually going to throw the following runtime error in your project:
No class registered for interface ‘mx.resources::IResourceManager’.
Believe it or not, during the initialization of a Flex Application, many classes are loaded to be used later. The solution is to create a method called initFlexFrameworkSpecifics() which you call in your constructor or inside init() and have the following code:
private function initFlexFrameworkSpecifics() : void
{
Singleton.registerClass("mx.resources::IResourceManager", Class(getDefinitionByName("mx.resources::ResourceManagerImpl")));
var resourceManager:IResourceManager = ResourceManager.getInstance();
}
HTTPService was making call to a IResourceManager which didn’t exist. The Singleton Class reference is what the Flex Framework does to ensure there is only one instance of your class. So what we do is create that class reference of IResourceManager for all other libraries to use.
That’s it! You’re good to go now. Please understand that there may be more libraries that you’ll have to initialize depending on which classes you use. I hope you find this post helpful!
–lp
Filed under: Flex, Flash, Actionscript, Papervision3D, Eclipse on March 30th, 2008 | No Comments »