ActionScript projects.
Having come to Flash Builder from Flash Develop, it was natural to create ActionScript projects instead of Flex or Flash IDE projects. All this means is that you will not need an FLA or any MXML to compile your Flash. We have found this to be the simplest approach in creating any Flash-based applications.
You create an ActionScript project in Flash Builder the same way you would any other type of project. It simply creates as a ‘.as file’ in the root class-path of your application. This file is your ‘Document Class’ that you would ordinarily associate with an FLA in the Flash IDE. That FLA is just not needed in an ActionScript project.
Setting the project properties, including background colour, frame rate and dimensions, is simple in an ActionScript project. You just have to add the following line right before your class definition:
[SWF(width="760", height="580", frameRate="31", backgroundColor="#FFFFFF")]
Compiler Commands.
One issue that always plagued our developers is how to create a proper preloader that can be simple to set up and implement. Using Flash Builder compiler arguments (Project Preferences>ActionScript Compiler) along with a couple other simple tricks has allowed for a quick and reusable method of preloading that resembles the way preloaders were created in older version of Flash.
As a compiler argument, we add the following:
-frame two com.cultcreative.projectname.DocumentClass
That document class now needs to be created in your project’s workspace. It can be anything you want. Just make sure that you are correctly pointing to the file in the argument.
The next step is to go to your main class and let it know that it is just a preloading class and nothing else. We usually have a data model that gets instantiated in this class and the data loaded along with the rest of your Flash file. Also note that the main class should extend MovieClip and not Sprite since we are going to be calling for some MovieClip functionality that doesn’t exist in the Sprite class.
In its simplest form, our main class looks like this:
package {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.Event;
import flash.utils.getDefinitionByName;
// Set the stage dimensions and colour here
[SWF(width="760", height="580", frameRate="31", backgroundColor="#FFFFFF")]
public class CultCreativeProject extends MovieClip {
public function CultCreativeProject() {
//Set an eventlistener for the animation
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(ARG_evt:Event):void {
// check to see if the movie is loaded
if(this.framesLoaded >= this.totalFrames) {
movieLoaded = true;
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
init();
} else {
// update the preloader
var percent:Number = root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal;
// do anything with your preloader now
}
}
private function init():void {
if (movieLoaded) {
nextFrame();
//Get our main class
var mainClass:Class = Class(getDefinitionByName("com.cultcreative.project.DocumentClass"));
if(mainClass) {
//And instantiate it
var app:Object = new mainClass();
//finally we add it to the DisplayList
addChild(app as DisplayObject);
}
}
}
}
}
That class now creates a SWF file that loads preloads the project moves the project into the DocumentClass that we specified in the compiler argument.
Managing Visuals
Another matter that must be considered when creating projects this way with Flash Builder is how to work with all the project’s visual aspects, including artwork and animations. To handle, this we use a ‘compile SWC file.’ A SWC (“swick”) file is a self-contained document that can be published by the Flash IDE. It includes a library of shared assets that are used in your project. A benefit of using the SWC in Flash Builder is that you get access to the auto-complete functionality of the application when you want to instantiate an asset.
To create a SWC, go to the Flash IDE and create a MovieClip (or any other type of asset), then add a linkage ID to it. With this linkage ID, we like to create packages to keep the assets organized. In order to set a package, you just need to specify it in the linkage ID. For instance, if you have an asset that you want to call Preloader, you can call it ‘assets.Preloader’ in the linkage ID and it will now be in the assets package when it is accessed in Flash Builder.
Once you have the linkage ID set up, save your Flash file somewhere (preferably in the Flash Builder workspace) and open up the Publish Settings in Flash. Go to the Flash tab and make sure that Export SWC is selected. From there you can just publish your movie to export the SWC file.
Back in Flash Builder, go to your Project Properties (right click on the project and click properties) and go to the ActionScript Build Path tab. Make sure that you are on the Library Path option and click the Add SWC button and point the dialogue to your SWC file. Click OK and you are all set to start working with any assets in your SWC file.
If, for example, you created the preloader asset described above, you would instantiate it as follows:
var preloader:Preloader = new assets.Preloader();
Final Thoughts
For those that find their projects get messy or who would like to find ways to make coding in ActionScript a little bit faster, we strongly recommend using Flash Builder. Whether you use our tips or not, the application provides a great way to quickly get working on your projects without having to be stuck in the Flash IDE or deal with MXML.

Nice tutorial. Great way to include swcs and add appropriate preloaders for ActionScript projects. Helped a lot.
Like your writing! Still you can do some things to improve it.
Swiffer Coupons…
[...]listed below are several listings to internet websites we link to because we think these are truly worth checking out[...]…
Superb inforamiton here, ol’e chap; keep burning the midnight oil.
hello buddy!…
I reckon something genuinely interesting about your blog so I saved to bookmarks….
… [Trackback]…
[...] Read More: cultcreative.com/tutorials/09/10/2010/flash-builder-intro/ [...]…