Introduction
As ActionScript evolves as a language, a clearer line is being drawn between Flash Designers and Developers. Being a self taught programmer, I understand the fear and anxiety of moving away from Flash and off to the land of text editors and math. Hopefully this tutorial will be a good primer in getting set up and help ease the transition. I do have this warning, this is not a perfect setup for everyone. It has taken me a few years to get this to where it is now and I am always changing/tweaking it to serve my needs. ActionScript development is constantly evolving and no one solution is ever perfect. As you go through this tutorial please take each step with a grain of salt. You may need to play around with what works best for you. Depending on your OS you may even need to set things up a little differently. In the end, the notion of having a clean process and custom sandbox will help make you the most productive developer you can be.Step 1: Pick An OS

Step 2: Pick An Editor
To a lot of people, the most obvious editor for writing ActionScript is Flash CS 4. Most are are probably using it right now and there is nothing wrong with that. As a developer, I rarely use the Flash IDE. The only times I fire it up is if I need to do an animation that is too complex to be done programatically (hasn't happened yet), if I need vector assets in my project, or if I need fonts. Other then that, Flash CS 4 collects dust on my computer. Developer editors are broken down into 3 different types: Eclipse based, stand alone, or text editors. Here is a convenient chart to show all the editors available and which OS's they run on.| Editor | Type | ActionScript | OS | Cost |
| Flex Builder 3 | Eclipse Base | AS 3/Flex | Mac/PC | Starting at $249 |
| FDT | Eclipse Base | AS 2/3/Flex | Mac/PC | Staring at €399 |
| Flash Develop 3 | Stand Alone | AS 3/Flex | PC | Free |
| TextMate | Text Editor | AS 2/3/Flex | Mac | €39 |
| E-Editor | Text Editor | AS 2/3/Flex | PC | $34.95 |
Step 3: Download Editor


- Code Hinting Eclipse has a powerful string parsing engine. This allows Eclipse-based editors to offer up code hinting while you are typing. Let's say you want to create a new Sprite. Normally you would have to type out new Sprite() and import the sprite class by hand. In Flex Builder, when you start to type out Sprite it will automatically pop up a list of suggestions. When you select a class from the list, it will automatically import it for you. The best part is, as you add your own custom classes Flex Builder will offer up code hinting on them as well.
- Import organization Adobe has been making great strides in cleaning up the way you import and and manage classes. The latest builds of Flex Builder now offer up import organization to help you make sure you only import what you are using and find out what you are missing.
- Compiler Errors As you save your code, Flex Builder will automatically display any errors you may have in your code. This way you can try to fix them before compiling your application.
- Faster Compiling In Flex Builder, your application is automatically built in the background. Each time you hit "save" a new version is compiled so when you run your app, it launches instantaneously. Waiting for a large Flash App to compile is a thing of the past. This is part of the secret to how Flex Builder launches projects quickly. When they do the compile, any errors are shown in the editor and if everything is problem free Flex Builder just launches the compiled swf.
- Local Version Control We'll talk about version control in more detail later, but it's good to know that every time you hit "save" Eclipse makes a backup of your changes and time stamps them for you to review later. You can increase the amount of revisions Eclipse saves for each workspace so you can rest assured that you can go back and see what you did several saves before.
- Plug Ins Eclipse is completely extendible via plugins. You can keep adding plugins customized by Flex Builder to work they way you need them to. Do you work with PHP? Get a PHP plugin. Need some JavaScript? They have one for that as well. Need project management in your editor? You're covered.
- Organization Eclipse stores your projects in a workspace (we'll cover this later) keeping all of your projects in one place. This makes backing up a piece of cake.
- Debugger Flex's Debugger is amazing. I have not found anything else like it. It allows you to explore objects at runtime, go back through function calls, and use break points to debug your code.
- Profiler Flex Builder lets you monitor memory usage, isolate memory leaks, track instance creation and monitor the Garbage Collector. This is something I couldn't live without.

Hopefully you are a slow reader and by now have downloaded a copy of Flex Builder. If not, proceed when you're ready to install it.
Step 4: Installing Flex Builder
Simply install Flex Builder with the default settings. Don't worry, we'll be customizing a lot when it's installed. Once Flex Builder has finished installing, open it up - let's take it for a spin.
Step 5: Understanding The Workspace
The workspace is the main directory where Eclipse stores critical data such as settings, any customization you make to the editors, as well as some invisible meta data files it needs to run. Each workspace is a self contained development area. This allows you to back up the workspace and move it to a different computer yet retain all the settings and configurations you have set up. Eclipse also uses the workspace to store your projects. Flex Builder automatically creates this workspace for you in your Documents folder. It should be called "Flex Builder 3" and for right now don't worry about renaming your workspace. Even if you create your own workspace, Flex Builder automatically creates the Flex Builder 3 workspace, so you're kind of stuck with the way it automatically gets set up. Hopefully this will change with future versions of Flex Builder. As we start to create our ActionScript projects they will be automatically set up in the workspace. You may have used your own folder structure to help organize past projects but that is now how Flex Builder handles it. All projects sit in the root of the workspace folder. We'll use other techniques for organizing these projects, but understanding that everything goes in a single workspace is a tough thing to swallow at first. It is possible to put your projects anywhere on your computer, they do not always have to sit in the workspace folder, but to keep things organized its best to follow this setup.
Step 6: Tweaking The Settings
Now that Flex Builder is open, we want to tweak a few settings. Go to the Flex Builder > Preferences menu on Mac OS X or Windows go to Window > Preferences. Once you're in the Settings, unfold the "General" Tab and go to "Keys". This area handles all of the short cut keys and how to call them. Below is a chart of the keys I set up and a short description on what they do.
| Command | Description | Key |
| Debug Last Launched | I use this to debug my applications. Since I grew accustomed to Flash's Command + Return to run a Movie, I tend to map this function to that key set up. This allows you to debug the last program you have launched (I will explain Runs and Compiling a little later). This function I map to Command + Return since it is not set up to that by default. | Command Return |
| Run Last Launched *Optional* | If you don't want to use the Debug Player when you compile your Flash app, you can use this as your default build launcher. It will launch your project in a default browser without any debug code and will ignore any breakpoints. You should not map "Debug Last Launched" and "Run Last Launched" to the same key. When using both, I tend to map Run Last Launched to Shift + Command + Return | Shift + Command + Return* |
| Delete Line | To Delete an entire line of code simply press Command + D. | Command + D |
| Find and Replace | This is a standard Find and Replace in a document. | Command + F |
| Find in File | This is a powerful Find and Replace type function that lets you search across multiple files. | Shift + Command + F |
| Line End | Jumps to the end of the line. | Command + Right Arrow |
| Line Start | Jumps to the beginning of a line. | Command + D |
| Move Lines Up | Take a selection of lines and move them up. This is useful when organizing code or changing the order of actions in a given method. | Command + Up Arrow |
| Move Lines Down | Take a selection of lines and move them down. | Command + Down Arrow |
| Next Perspective | Perspectives represent different types of Editors or areas of functionality in Flex Builder. Imagine going from the ActionScript editor to the debugger to the SVN repository explorer. Each of these is a different type of perspective and have their own collection of relevant windows. I tend to think of this a an application switcher inside of Eclipse. I use this a lot and felt it was better to change the default keys to something easier to call. | Shift + Command + Right Arrow. |
| Previous Perspective | See Next Perspective description above. I change the default keys to the following. | Shift + Command + Left Arrow. |
| Organize Imports | I had mentioned before that Flex Builder will help you keep track of Imports. Well this is the short cut to do it. Flex Builder will automatically remove any packages that are not needed and reorder used imports based on their priority and source package. | Shift + Command + O |
| Save All | When you have multiple documents open and you need to save them all to do a build, use this. | Shift + Command + O |
| To Lower Case | Use this to convert a selection to lower-case text. | Shift + Command + Y |
| To Upper Case | Use this to convert a selection to upper-case text. | Shift + Command + X |
| Word Completion | Probably the most powerful command in Flex Builder. This calls an auto complete menu based on what you have typed in. If you were to type out "Spr" and call the word completion it would pop up a menu with Sprite (and a few other close matches) for you to choose from. Once you make a selection, Flex Builder will also attempt to import the class for you. Your custom classes will also show up in this menu along with the built in classes the Flash Player supports. I can't live without this! | Control + . |
Step 7: Installing Plugins
Since Flex Builder is built on top of Eclipse, we can take advantage of some great Eclipse plugins already out there. Plugins add missing features and editors to help extend the core application. Here is a list of Plugins I use:
- Spell Check: Anyone who has read my blog knows that I am not the best at spelling. It's vital that I have some sort of spell check in any editor I use. Although this one is far from perfect, it does at least show me where I am making a foool of myself.
- XMLBuddy A great plugin for writing xml in Eclipse. This does basic formatting, validation, and error flagging. Make sure you get the version for Eclipse 3.1+
- Mylyn If you're looking for a project manager/task manager check this plugin out. It integrates right into Flex Builder and offers a ton of features.
- SubClipse is a SVN client for Eclipse. I will go into installing this later in the tutorial.
Before we start installing plugins, let's talk about version control.
Step 8: Version Control
This is not a Flex Builder specific topic but a workflow and life saving tool. Version control is a way to manage changes in your documents. Every time you "commit" a file to the Version Control Repository the changes are saved. When you need to go back and compare what you did before, you are able to go back through the history of your document to compare revisions and changes. If you are not using Version Control you are missing out on an incredible life saving tool. How many times have you been frantically trying to fix a bug moments before a site is supposed to go live, saving and compiling the app over and over again. Eventually you get to a place from where you can't remember how to go back - and undo is not working. Version control is your answer. Also when working in a team, managing changes across multiple files and different developers is a lot easier with version control. Unfortunately, going into the details of version control is out of the scope of this tutorial but here is a list of the most common ones used.
- CVS This is the first Version Control system I ever used and is still very popular. CVS support is built into Eclipse.
- SVN This is the next step up from CVS. One of the most over looked features is SVNs ability to preserve folder structure.
- GIT This is a relatively new Version Control System but one I have been very interested in using. It allows for synchronization across multiple repo check outs including local and server versions. Unfortunately the GIT Eclipse plugin still needs a little more work.
For this tutorial we are going to use SVN. It is a really great Version Control system and, as you will see later, the one which Google Code offers free of charge.
Step 9: Installing SVN Plugin
Flex Builder comes with support for CVS built in but we are going to use SVN. To do this we are going to need a plugin. Let's go to SubClipse's site and check out the install instructions: Most Eclipse plugins are installed through the help menu. Let's got to Help > Software Updates > Find and Install...

Next, we choose "Search for new features to install" and hit next:

Click on "New Remote Site..." and now we will need to supply a name for the connection as well as the path to the plugin:
Name: Subclipse 1.4.x (Eclipse 3.2+) URL: http://subclipse.tigris.org/update_1.4.x

After clicking ok, you will be brought back to the Install window with Subclipse selected. Click "Finish" to begin the installation process:

Here's where the fun begins! Pay close attention to the packages I've selected. Some of parts of this plugin will not with with the stand alone version of Flex Builder. To save you the trouble of figuring out what works and what doesn't, I've made the following selections for you. Don't worry, you're not missing anything you don't need. We're simply selecting the basic setup to get you up and running.





Step 10: Setting Up A SVN Repo





# Project members authenticate over HTTPS to allow committing changes. svn checkout https://flashbums-demos.googlecode.com/svn/trunk/ flashbums-demos --username jessefreeman
# Non-members may check out a read-only working copy anonymously over HTTP. svn checkout http://flashbums-demos.googlecode.com/svn/trunk/ flashbums-demos-read-only
Step 11: Setting Up A SVN Repository Location
- trunk This is the main area where we keep our code. Trunk represents the current stable build of a project and is usually what is running on a production server.
- branches This is where you should keep copies of your project that are unstable or are being worked on by individual developers. Let's say you need to add a new feature to your project but you don't want it to affect the stable build in the trunk; we would create a new branch of it (basically copying files in the trunk) in the branches directory. From there we can make all of our changes then when its ready, merge it back into the trunk.
- tags When a project hits a stable build, such as 1.0, we take a copy of the trunk and copy it in the tags folder. This is similar to a branch since we are making a copy of the trunk, but tags are not meant to be worked on once they are created. Making tags is key when creating incremental builds of a project. If anything ever happened, you would be able to go back to a stable tag and compare the changes.
Here is a great resource for learning more about version control. Since checking out an empty project isn't fun, let's go to http://code.google.com/p/tweener/source/checkout and check out a copy of "Tweener". Tweener is a excellent animation library for ActionScript 2 & 3. We are going to need the following svn checkout url http://tweener.googlecode.com/svn/trunk/. Let's go into Eclipse and open the SVN Explorer. You can do this by opening Window > Perspective > Other and select the "SVN Repository Exploring" perspective.

Now you should see a SVN Repositories window and its tab selected on the left hand side. The content of this window will be blank, since we don't have any repositories set up yet. Right click in the white space of the window and select New > Repository Location... from the contextual menu which pops up.

You'll be presented with a url field, so paste in the path to Tweener's svn trunk http://tweener.googlecode.com/svn/trunk/ and hit finish. Since this is a public check out (meaning you cannot save edits back to the svn repository) you will not be prompted for a password.

There you go, you have just set up your first SVN repository in Flex Builder! You should see the following:

While you are at it, you may want to setup these other cool Google Code projects as well:
- gmaps-utility-library-flash Google Maps API for Flash Utility Library
- gskinner A collection of public AS3 classes released under MIT Licensing by gskinner.com
- monsterdebugger Debugger for Flash / Flex / AIR developed by design studio De Monsters.
- Papervision 3d Open Source realtime 3D engine for Flash
- Flash Camouflage Flash Camouflage is a skinning framework for AS 3 Applications
- as3corelib ActionScript 3.0 library for several basic utilities
Step 12: Checking Out A Project From SVN
Now that we have Tweener set up in our SVN Repository Explorer, let's check it out. Before we get too excited, let's unfold the repository and see what's in it first. You can do this by right-clicking on the repository and selecting "Checkout" from the contextual menu:

When checking out something from SVN, Flex Builder will present us with a project wizard. For Tweener we will want to select "Check out as a project in the workspace", rename it to "Tweener" and then click Finish:

SVN url: http://flash-camouflage.googlecode.com/svn/tags/FlashCamo_2.0.0_beta








Step 13: Shared Libraries
In Flex Builder there are two types of Shared Libraries; directories on your computer containing code (these will most likely sit inside one of your projects) and Flex Library Projects. Let's talk about a Library Project first. Don't be confused by the name, a Flex Library Project is not just for Flex but a great way to package up code for any AS 3 project. Basically, a Flex Library Project will bundle up code you place in the source directory and compile a SWC in the bin directory for you. A SWC is a zip-like file that contains a catalog.xml, ActionScript files, SWFS, and a few other files. SWCs have been around since MX 2004 and are an excellent way to compile code libraries to build off in other projects. It was previously only possible to create SWCs in the Flash IDE (it was an option in the "Publish settings" panel) but Flex Builder will automatically compile them for you if you are working in a Flex Library Project. It's important to note that you can't load SWCs into flash at run time and they don't have to contain only code. I have used SWCs to import assets such as vectors from flash and fonts into my ActionScript projects. In step 12 we checked out two code libraries from svn. We're going to look at how to convert Flash Camo into a swc. Make sure you're in the Flex Development Perspective. You can switch perspective at any time in the upper right hand corner of Flex Builder.

Severity and Description Path Resource Location Creation Time Id nothing was specified to be included in the library FlashCamo2 Unknown 1238534136480 1This is a simple error to fix, but one that may stress you out if you don't know what's going on. Sometimes when you set up a library the path to the src code does not get correctly set so you see "nothing was specified to be included in the library". To fix this we need to right-click on your FlashCamo2 Project in the Flex Navigator and go down to the bottom to select Properties. You should see a window like this:





Step 14: Creating An ActionScript Project
Wow, we have gone over a lot so far! All of this work just to set up our first project. Well now that you have a hang of how to set up Flex, check out projects, and set up Libraries, creating your projects will be a walk in the park. We'll start by right-clicking in the Flex Navigator and choosing New > ActionScript Project from the contextual menu.
- Flex Project - if you want to build a Flex App, this is the one to pick. You can still write AS 3 code but you will mainly be working in MXML templates and the project folder structure will be set up mainly for Flex Development work.
- ActionScript Project - this is the main project I use. It allows you to code in AS 3 similarly to how you would work in Flash, but without the IDE.
- Flex Library Project - this is a project comprised only of Code and will generate a .swc file in the end. All of my shared code and libraries are put into these.
- Project... - will open up the full project selector. Based on the plugins you have, you will see a Java project, XML project, PHP project etc.




- Flex 3.1 is already set up as your main lib. This makes sense since you are going to be using that to get the base AS 3 classes. Don't be alarmed that its says Flex, you will not have to import any of the Flash Framework to run your project. On a positive note you will be able to use some special Flex classes such as utilities if you want.
- Next up are the Add Project, Add SWC Folder, and Add SWC. Remember I told you that SWCs contain code? Well if you downloaded a SWC off the internet or you have a folder on your computer where you keep a collection of SWCs, you can use the last two options to import them into your project.


Step 15: Project Properties
So before we start coding we should check out the project's properties. Flex Builder is a little temperamental and making sure everything is set up correctly before you start coding will save you some time later, I promise!. Right-click on the HelloWrold project and let's check out what's going on under the hood. Head over to the ActionScript Application area. Here you will see all of the runnable class files or doc classes in this project. It's possible to have more then one Doc Class but you can only have one default class. If you had others or wanted to switch one for another you can add/remove them here.

Step 16: Understanding Flex Builder's Folder Structure
In our Default project we have a few folders automatically set up for us. The first one [source path] as3 is a link to our as3 folder in the Tweener project. As you can see, you can go through all the classes and edit them as if they were part of your own project, but the originals stay in their own project. Next up is the bin-debug folder. This where your application is built. This is a combination of the compiled code that makes up your project in the src folder and the html-template files. This bin directory is never committed to SVN, in fact Flex Builder will do its best to never let you even try. You would never commit your bin folder anyway, your project should contain all the code need to get up and running if someone was to check it out. The bin-debug folder should be unique for each developer and never copied across dev environments. The html-template folder is a special folder in your project. This contains a few basic files that Flex Builder uses to create a html wrapper page, as well as a the JavaScript embed/detection if you opted to have them created in the project settings. In this folder you'll find an index.template.html. If you open it up it will look like a normal html file except for a few variables scattered around. Flex Builder will fill these values in such as the size of the swf and the background color, all based on the compiler parameters you supply. It's important to note that this folder's entire contents get copied over to the bin-debug folder every time there is a compiler. I like to keep my loadables such as XML, images, css, and other swfs in the html-template folder so when I do a build and load up the html wrapper in the bin-debug (this is done automatically and I will talk about it in the Run a project step) all of my assets get copied over. Let's set up a few folders to get started. In the html-template let's add "images", "xml", "css" and "swfs" folders. Then in the main project folder add "docs"; this is where code documentation would go. Then "lib"; this is where our protects library assets such as FLAs, PSDs or reference material belong. After you create the lib folder lets add "FLAs" and "PSDs" folders in there. Afterwards your project should look like this:

Step 17: Working With The Default Class
Just as you would have a Doc Class when working in the Flash IDE, Flex Builder projects have a Default Application. Now we have finally set up Flex Builder and are ready to write some crazy amazing ActionScript in our new project. Let's open up the HelloWorld.as in our src folder and check it out.

Step 18: Running A Project
In order to compile your application you are going to have to select a run. Runs are wizards that automate the process of running the Flex SDK compiler and what builds your application. Above the Flex Navigator tab, you will see a row of icons, look for the green play button and roll your mouse over that. You should see the following:
Step 19: Debugging A Project
The debugger run is the bug looking button to the right of the play button. Press that and watch the amazing blue-green webpage come back again! This time I am not playing a joke on you. Close your browser's window and go back to Flex Builder. Under your main window a new tab should have opened up called "Console". Check the output:Hello World [SWF] Users:jessefreeman:Documents:Flex Builder 3 Demo:HelloWorld:bin-debug:HelloWorld.swf - 1,045 bytes after decompressionOur trace works and now you know where traces show up. An important thing happened here; there is a big difference between the normal run and the debug run. If you remember earlier I suggested mapping Debug Last Launched to command + return. If you did that, try running the shortcut. The browser window should pop up and Hello World gets printed to the Console again. You can now rebuild your app at any time by using the shortcut. Before we start wrapping up this tutorial I want to show you a few more things about the editor and the console window. Delete the trace and type in the following:
var timer:TimNow press control + space to pull up the code hinting and select the Timer as the variable's type. After you chose the Timer from the menu, Flex Builder automatically added the flash.utils.Timer class to the import list. Now let's continue typing out the following:
var timer:Timer = new Timer(Two things should have happened. First you should have seen the code hinting menu show up with possible solutions as you tried to type out Timer. Next, if you didn't select it from the menu but instead stopped at "(" you should see the following code hint:

var timer:Timer = new Timer(1000, 0); timer.addEventListener(TimerEvent.TIMER, onTimer);Now save your file and see what happens. You should have an error on line 11. Take note on how the Editor shows you the error. A red X on the left, a red tick on the right of the line, and in your problems panel a description.

Severity and Description Path Resource Location Creation Time Id 1120: Access of undefined property onTimer. HelloWorld/src HelloWorld.as line 11 1238554892201 8It looks like we forgot to create a function called "onTimer" for our event listener to call. We can fix that by adding in the following under line 12:
private function onTimer()
{
trace("Hello World");
}Now when you save, you should see a new type of error called a warning: 
private var counter:Number = 0;Now let's go to the onTimer function and create a new line above the trace statement on line 16. Before you start typing, let's see what happens when we press control + space.

counter ++;
trace("Hello World", counter);We just need to add one last thing in the constructor under line 13: timer.start();Great, now we can run our app. Make sure you use the debug run to compile this time. Note: Please read the next few lines so you know how to unlock your browser after running the code. Hopefully you read this before running the above code so you should notice that the browser just locked up and Flex Builder change to a new Perspective; the Debug Perspective.

ArgumentError: Error #1063: Argument count mismatch on HelloWorld/onTimer(). Expected 0, got 1. at flash.utils::Timer/_timerDispatch() at flash.utils::Timer/tick()Also, your browser is locked and waiting for you to make your next move in the Debugger. In the Debug tab you have controls that resemble an mp3 player:
private function onTimer(event:TimerEvent):voidNow we can run our program (bug free I promise) and watch "Hello World" count up in the Console. This shows you that the Console is always running so you can continue to debug your application just like you would in Flash. As we go deeper into the Debugger you will start to appreciate how little you will rely on traces to help problem solve your issues.
Step 20: Checking In A Project
Now that we have working project let's talk about how we can check this into our newly created SVN repo on Google Code. Let's start by right clicking on our project and selecting Team > Share project from the contextual menu:












discuss this topic to forum
