Code inspection, analysis, and fixing

Syntax error checking and highlighting

Flash Builder performs code analysis as you type ActionScript or MXML code and identifies coding syntax errors and all other errors by default.

Depending on the nature and severity of the errors, your application might not run properly until the errors are corrected.

Syntax error checking in Flex projects

When code syntax errors are encountered in a Flex project, you are notified in the following ways when you save your file:

  • An error indicator is added next to the line of code, as the following example shows:

  • The Outline view indicates the error with an exclamation mark in the affected lines of code, as the following example shows:

  • The Problems view lists an error symbol and message. Double-clicking the error message locates and highlights the line of code in the editor, as the following example shows:

Unidentified reference error highlighting

Flash Builder generates error annotations for undefined identifiers in your code.

next to the line of code in the editor indicates an error annotation.

Unidentified reference error highlighting also helps you identify places in the code where you can generate stub code for an undefined method, variable, or class. For more information, see Generate from usage.

Live Error Highlighting in ActionScript projects

When you type ActionScript code in an ActionScript file or within an ActionScript block in an MXML file, Flash Builder detects errors as you type. You can quickly identify these errors before saving the file or compiling the code.

An error indicator with a bulb next to the error icon indicates that you can use Quick Fix to fix the problem.

For more information on using the Quick Fix feature, see Quick Fix.

next to the line of code in the editor indicates that there is no Quick Fix option available for that error.

To turn off Live Error Highlighting, select Flash Builder > Editors in the Preferences dialog box, and deselect Report Problems As You Type. The code errors are then reported only in the Problems view after you save the file.

You can also correct an error using the Quick Fix option in the Problems view. To do so, right-click the error in the Problems view and select Quick Fix.

Find references and refactor code

Flash Builder includes advanced search features that are more powerful than find and replace. To help you understand how functions, variables, or other identifiers are used, Flash Builder lets you find and mark references or declarations to identifiers in ActionScript and MXML files, projects, or workspaces. You can use refactor to rename the following identifiers in your code, and then update all references to them:

  • Variables

  • Functions

  • Types (interface, class)

  • Accessors (getter/setter)

  • Attributes

  • Metadata in MXML (effects, events, styles)

Mark references

  1. In Source mode, click the Mark Occurrences button in the toolbar.

  2. Click an identifier in the editor. All instances are marked, depending on settings in Preferences.

To change the appearance of marked references, in the Preferences dialog, select General > Editors > Text Editors > Annotations. For more information on Markers, see Use markers.

Find all references or declarations

  1. In Source mode, click an identifier in the editor.

  2. Select Search > References or Search > Declarations from the main menu. Then select File, Project, or Workspace. Matches appear in the Search view.

Refactor your code

  1. In Source mode, click an identifier in the editor.

  2. Select Source > Refactor > Rename from the main menu.

  3. Enter a new name.

    Flash Builder checks rename preconditions and prompts you to confirm problems before the rename operation occurs. Preconditions include the following:

    • References cannot be renamed in read-only files.

    • All files must be saved.

    • If a project has build errors, a warning appears.

    • The new name must be within scope, which is determined by the type of element and its location. Name-shadowing errors are also noted.

    • The new name must be a valid identifier.

    • The reference defined in a SWC file must include a source attachment.

  4. To review the change, click Preview to see the original and refactored source, or click OK to proceed with the change to your code.

Refactoring in CSS files

When you have references to ActionScript or MXML files in your CSS files, and you rename or move the ActionScript or MXML files to a different location. Then, Flash Builder automatically updates the CSS files with references to the new name or location. You can review the changes in the Preview dialog, and click OK to proceed with the change to your code.