Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flash Builder Developer Center /

Coding productivity enhancements in Flash Builder 4.5

by Sreenivas Ramaswamy

Sreenivas Ramaswamy
  • flexpearls.blogspot.com

by Sameer Bhatt

Sameer Bhatt
  • techrays.wordpress.com

Content

  • Code templates
  • Customized code generation
  • Metadata code completion
  • Override/Implement methods
  • Quick Assists
  • Generate from usage
  • CSS editing enhancements from the document.
  • Where to go from here

Modified

11 April 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder Flex

Requirements

Prerequisite knowledge

Familiarity with Flex and/or ActionScript 3

User level

All

Required products

  • Flash Builder (Download trial)

Building on the release of Flash Builder 4, Flash Builder 4.5 introduces a range of improvements to the code editing environment that will help to make you more productive when writing Flex and ActionScript code.

Knowing what tools are available to you and how/when to invoke them are key to improving your coding productivity—by reading this article you’ll learn about the new features included in this release and be using them as you code in no time at all.

In particular, we’ll highlight the following Flash Builder 4.5 features:

  • Code templates
  • Metadata code completion
  • Override implement methods
  • Quick Assists such as Rename in file/workspace, Organize imports, Convert to field, Assign to variable, Split variable declaration
  • Generate from usage to generate a local variable, field, method, class, interface, and event handler from their usage
  • Customized code generation to change the code generated by Flash Builder
  • CSS improvements

Code templates

Say, you have defined a variable of type Array and want to write a ‘for loop’ to go through the  elements of that Array. Rather than typing all the code yourself, you can now use Flash Builder 4.5 to generate the for loop for you. To do so, just type “fori” and press Ctrl + Space (see Figure 1). 

For loop inserted using template
Figure 1. For loop inserted using template

Code templates enable you to auto-insert code patterns that you frequently use by using Content Assist (Ctrl + Space). Code templates are context-based and can range from a ‘for loop’ in ActionScript to a WebService tag in MXML. Over 100 pre-defined ActionScript, MXML and CSS templates are shipped with Flash Builder 4.5:

  • ActionScript—package, class, for loop, while loop, try-catch block, and more
  • MXML—Button, DataGrid, HttpService, WebService, and more
  • CSS—Button, DataGrid, @font-face, and more

You can view and edit the pre-defined templates by going to Preferences > Flash Builder > Editors > Code Templates > ActionScript/CSS/MXML (see Figure 2).

Code templates preferences page
Figure 2. Code templates preferences page

You can define new templates for frequently-used coding patterns, as well as import/export code templates, so as to share a consistent set of templates within a team environment.

Customized code generation

Apart from creating your own code templates, there are various scenarios in which Flash Builder generates code for you – event handler, function, getter/setter, etc..  Now, you can customize the code generated by Flash Builder by using templates. You can view and edit these templates by going to Preferences > Flash Builder > Editors > Code Templates > Flash Builder (see Figure 3).

Code generation templates.
Figure 3. Code generation templates.

You can edit the templates, as well as import/export the templates, so as to share a consistent set of templates within a team environment.

To customize the event handler template such that the generated namespace is private and the handler name is componentName_on_event, you can modify the event handler template (see Figure 4).

 Event handler template
Figure 4. Event handler template

The generated event handler will look like Figure 5.

Generated event handler
Figure 5. Generated event handler

Metadata code completion

You can use the new metadata code completion support to enter metadata tags. Metadata hints are displayed when you enter the ‘[‘ character in the editor close to a class, method, or variable definition. A list of valid metadata tags that are contextual to the location within the class or MXML appear. You can select the metadata tag that you want to insert from this list. If you don’t see the metadata tag you need, then simply press CTRL+space again to see the full list of available choices (see Figure 6).

Metadata proposal at a class level
Figure 6. Metadata proposal at a class level

On selecting a tag, Flash Builder generates the metadata tag with the mandatory attributes. You can then easily navigate from one value to another using the tab key (see Figure 7). 

Event metadata inserted with required attributes
Figure 7. Event metadata inserted with required attributes

You can use Content Assist to easily enter class names and property names in the metadata tag. For example, when you add an [Event] tag, you can select the required event class from a list of all the event classes available in the project (see Figure 8).

Event metadata with value proposals for event type.
Figure 8. Event metadata with value proposals for event type.

You can also insert the optional attributes using Content Assist.

Flash Builder also supports metadata tags from third party SWCs if they have the required metadata.xml file embedded in them.

Override/Implement methods

While implementing a class or customizing a base class behavior, you would need to frequently override super class methods and implement interface methods. In Flash Builder 4.5, you can achieve this task easily using the Override/Implement methods dialog box available from the Source menu. This dialog box displays a list of classes from which the active class inherits, and the interfaces that it implements (see Figure 9). 

Override/Implement dialog for a SampleClass implementing a SampleInterface
Figure 9. Override/Implement dialog for a SampleClass implementing a SampleInterface

From each super class, you can select the methods that you want to override, while for each interface, you can select the methods that you want to implement. You can also select the location at which the methods are to be inserted. Flash Builder generates the code stubs for the selected methods.

Quick Assists

Quick Assist provides a context-based list of actions to help you with everyday coding tasks. To invoke Quick Assist, use the keyboard shortcut CTRL + 1 or select Quick Fix/Assist from the context menu (see Figure 10). 

Quick Assists for variable.
Figure 10. Quick Assists for variable.

The various Quick Assists introduced in Flash Builder 4.5 are discussed below:

  • Rename in file—Allows you to perform a local inline rename of a variable, method, class, and argument without opening a dialog box. You just need to invoke this Quick Assist and start making changes to the selected element. As you type, all the references to the particular element within the file are renamed.
  • Rename in workspace—Provides a shortcut to open the Rename refactoring dialog box. Rename refactoring allows you to rename the selected element across files/projects.
  • Convert local variable to field—Allows you to promote a local variable to a field variable. A new field variable is created and the declaration statement for the local variable is removed.
  • Assign to variable—Creates a new variable for an expression statement. Type any expression and invoke Quick Assist. A new variable is generated and the  expression is created as the assignment statement for the new variable.
    For example, to assign a function call to a new variable, place the cursor on the function call and press Ctrl + 1. Select “Assign to variable” from the list that appears (see Figure 11 and Figure 12).
Assign to variable Quick Assist.
Figure 11. Assign to variable Quick Assist.
New variable created as a result of Assign to variable.
Figure 12. New variable created as a result of Assign to variable.
  • Split variable declaration—Allows you to split the variables (with initialization) into variable declaration and variable initialization.
  • Generate getter/setter—Provides an easy way to invoke the existing Generate Getter/Setter dialog box. It allows you to generate Getter/Setter for a variable. There are options to make the variable Bindable, dispatch a custom event, etc..
  • Organize imports—Allows you to organize import statements within the current file. Import statements will be sorted and organized. Unused imports will be removed depending on the value of the preference in Preferences -> Flash Builder -> Editors -> ActionScript Code .
  • Insert import—Allows you to add import for unknown Class/Interface used in a file. If the unknown Class/Interface is present in the project, selecting this assist will add an import for the respective Class/Interface.

Generate from usage

While coding, how many times do you realize that a variable, method, class or interface is not defined and that you can’t continue coding before you define these? Generate from usage is all about defining the undefined. It gives you a convenient option to generate place-holder stub code using Quick Assist (Ctrl + 1).  All the undefined references will be highlighted with orange squiggles, so that you know when something is not defined and use Generate from usage.

The following are the various generate from usage options:

  • Generate variable—Type the name of the variable that you want to create and invoke Quick Assist. Select the option to “Create a variable” and the variable declaration is generated for you. You can also use this Quick Assist if you are in an expression where something in not defined.  This option can also be used to create instance variables in other classes. For example, if obj is an object of type MyClass, pressing Ctrl + 1 on obj.property will give you an option to generate the instance variable property in class MyClass.
  • Generate method—Similar to generating a variable, just type the name of the method that you want to create and invoke Quick Assist. Selecting the Create function option generates the method with all the required arguments (see Figure 13).  Similar to how generate variable can be used to generate instance variables in other classes, this option can be used to generate methods in other classes as well.
Generate method
Figure 13. Generate method
  • Generate class/interface—If you are trying to generate a variable with an unknown type, invoke Quick Assist and you’ll get an option to create a class/interface (see Figure 14).
Generate Class/Interface
Figure 14. Generate Class/Interface
  • Generate event handler—Adding event handler to a component in ActionScript has become a lot easier now. Type
    component.addEventListener(“EVENT_NAME”, myHandler); and invoke Quick Assist. Select “Generate event handler” and the handler is generated for you (see Figure 15).
Generate event handler
Figure 15. Generate event handler

CSS editing enhancements from the document.

In addition to the code editing improvements already discussed, Flash Builder 4.5 provides enhanced support for editing CSS code.

Content assist improvements

You can insert a reference to a class is easily in Flash Builder 4.5 using the content assist available inside the ClassReference tag as shown in the following figure (see Figure 16).

Content assist in ClassReference tag
Figure 16. Content assist in ClassReference tag

Flash Builder 4.5 provides code completion support for various media query element (see Figure 17).

Media query support
Figure 17. Media query support

Hyperlinks

You can navigate to the class of a selector or a referenced class using the hyperlink as shown in the figures below (see Figures 18 and 19). The hyperlink is displayed by holding the Ctrl or Cmd key when hovering over with the mouse. You can also use Navigate->Open Declaration menu option when the cursor is on the selector or class name in the ClassReference tag.

 Navigation to a referenced class
Figure 18. Navigation to a referenced class
Navigation from the selector.
Figure 19. Navigation from the selector

Where to go from here

Now you’ve read about the new features in this release that will enhance your coding productivity, we encourage you to download Flash Builder 4.5 and experience them for yourself. To learn more, read the following article:

  • Understanding new Flash Catalyst CS5.5 and Flash Builder 4.5 workflows

You can also check out the What’s new in Flash Builder 4.5 article for more information on the other new features added in this release.


This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement