Publishers of technology books, eBooks, and videos for creative people

Home > Blogs > Easier Coding in Flash Builder

Easier Coding in Flash Builder

Flash Builder, like any good IDE, can facilitate programming in several different ways. By taking advantage of what Flash Builder can do, you can write ActionScript code  more quickly and, most importantly, with better accuracy.

The first thing you should remember when using Flash Builder is to let it do as much of the work as possible. For example, Flash Builder can automatically build the shell of event handlers, service calls, and ActionScript classes for you (among other things). Taking the event handler example, if you're in Source mode, when you add an event property to an MXML component, you'll be offered the opportunity to generate the event handler (Figure 1). In Design Mode, there's a button in the Properties panel you can click to do the same.


The generated event handler will use the naming scheme componentName/Type_eventHandler, such as button1_clickHandler. By default, the handler will take an event argument, return no value, and be protected:

protected function button1_clickHandler(event:MouseEvent):void


    // TODO Auto-generated method stub


Another benefit of having Flash Builder generate this for you is that the required Event classes will be imported automatically, so you don't have to worry about forgetting that.

On a similar note, through code completion and code hinting, Flash Builder will automatically suggest or enter components, properties, variables, and so forth for you. You'll be prompted as you code -- just use the arrow keys and press Enter/Return to select the appropriate choice from the list (Figure 2).

If you keep typing, you'll narrow your selections. If the suggestions don't immediately appear, press Control+Space to activate them. Repeatedly pressing Control+Space will cycle among suggestion types: properties, events, effects, and styles. Code completion and code hinting works within both MXML and ActionScript, too. If you use this feature, you'll have less typing to do but also be assured that you're using the proper spelling, capitalization, namespaces, etc.

Complex applications can quickly become overwhelmed with code. At best this will just slow down your development time (searching around for stuff) and at worst it can lead to problems. To keep things tidy, you should first consider using external ActionScript files. Within Source mode, though, you can easily find references to functions, variables, and components by pressing Alt+O (Windows) or Command+O (Mac OS X). This will bring up the Outline view in a separate pane.

To make the code easier to read, you'll see that Flash Builder will automatically handle indentations for you as you type, even for code you paste. If the indentations get out of whack, select Source > Correct Indentation to have Flash Builder clean up.

Another way to make the code easier to peruse is to make use of folding: the ability to hide blocks of code. Beside line numbers corresponding to the beginning of functions, control structures, and the like, you'll see a minus sign in a circle. Click that once to collapse the block. The icon will turn into a plus sign which you can later click to expand the block of code again. In the interim, you'll still be able to see what the code block is, without seeing its entire contents (and an ellipses will indicate that some code is being hidden).

Finally, if you decide at some point in time later that you'd like to use a different name for a function or class, don't try to change it yourself. You'll spend too much time chasing down references to the item and you're likely to miss some. Instead, select the item's name, then choose Source > Refactor > Rename. At the prompt, you can provide a new name and choose to update all the references (Figure 3). If you're renaming a class, the prompt will differ slightly.