Customizing File Templates

Flash Builder allows you to customize the default information contained in new MXML, ActionScript, and CSS files. Examples of information you can specify include variables for specifying author and date, variables for opening and closing tags and attributes, variables for various ActionScript declarations, namespace prefixes, and just about any content you want to include in a template file. File templates are especially useful for specifying introductory comments and copyright information.

The content of a new file is specified in a file template available from Preferences > Flash Builder > File Templates. Templates are available for the following types of files:

ActionScript

ActionScript file

ActionScript class

ActionScript interface

MXML

MXML web application

MXML desktop application

MXML component

MXML module

MXML skin

ItemRenderer for Spark components

ItemRenderer for MX components

ItemRenderer for MX DataGrid

ItemRenderer for Advanced DataGrid

ItemRenderer for MX Tree

FlexUnit

FlexUnit TestCase class

FlexUnit TestSuite class

FlexUnit4 TestCase class

FlexUnit4 TestSuite class

CSS

CSS file

After modifying a template, you can export the template so it can be shared with other members of your team.

Modify a file template

  1. Select Preferences > Flash Builder > File Templates

  2. Expand the file categories and select a file template to modify.

  3. Select Edit and modify the template.

    You can type directly in the Template editor or select Variables to insert pre-defined data into the template.

  4. Click OK to save the changes.

    Changes apply to new files.

Exporting and Importing File Templates

  1. Select Preferences > Flash Builder > File Templates

  2. Expand the file categories and select a file template.

  3. Select Export to export a template to the file system, or Import to import a previously exported template.

    Templates are exported as XML files.

Restoring Defaults

Note: Restoring defaults restores all file templates to the default values. You cannot restore a single template to the default value.

 To restore the default templates, open Preferences > Flash Builder > File Templates and select Restore Defaults

Template Variables

Template Variables for All File Types

Variable

Description

Example

${date}

Current date

Feb 15, 2009

${year}

Current year

2009

${time}

Current time

3:15 PM

${file_name}

Name of the newly created file

HelloWorld.mxml

${project_name}

Name of the Flex or ActionScript project

Hello_World_Project

${user}

Username of the author

jdoe

$$

${dollar}

Dollar symbol

$

Template Variables for MXML Files

Variable

Description

Example

${application}

${component}

${module}

Specifies the application, component, or module MXML tag names.

For a web application, ${application} expands to “Application.”

For a desktop application, ${application} expands to “WindowedApplication.”

${component} expands to “Component.”

${module} expands to “Module.”

These tags are typically used to position the starting and closing tags of a file.

The following:

<${application} ${xmlns}${wizard_attributes}${min_size}> 
${wizard_tags} 
 
</${application}>

expands to:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768"> 
<s:layout> 
    <s:BasicLayout/> 
</s:layout> 
 
</s:Application>

${xml_tag}

XML version

<?xml version="1.0" encoding="utf-8"?>

${xmlns}

Resolves to the namespace definition, based on the project's Flex SDK type and the namespace prefix defined in Preferences.

For a Flex 4 SDK project:

xmlns="http://ns.adobe.com/mxml/2009"

${min_size}

Minimum size of an MXML web application.

minWidth="1024" minHeight="768"

${ns_prefix}

Namespace prefix for the project’s Flex SDK.

You cannot change the default values for this variable.

For Flex 3: mx:

For Flex 4: fx:

${wizard_attributes}

Specifies the position of the attributes defined by the New File wizard.

For a new web application:

${application} ${xmlns}${wizard_attributes}>

expands to:

<Application xmlns="http://ns.adobe.com/mxml/2009" layout="vertical">

${wizard_tags}

Specifies the layout property for containers defined by the New File wizard

For a new application using Flex 4 SDK:

<s:layout>

<s:BasicLayout/>

</s:layout>

Template Variables for ActionScript Files

Variable

Description

Example

${package_declaration}

Generates the package declaration.

For a file in the com/samples package, generates:

package com.samples

${import_declaration}

For a new ActionScript class or ActionScript Interface, generates required import declarations .

For a subclass of TextBox, generates:

import flex.graphics.TextBox;

${interface_declaration}

For a new ActionScript interface, generates the interface declaration.

For a new Interface that extends IButton interface, generates:

public interface IMyButton extends IButton

${class_declaration}

For a new ActionScript class, generates the class declaration.

For a new subclass of CheckBox, generates:

public class MyCheckBox extends CheckBox

${class_body}

Generates all the required statements for a new class.

For a new subclass of Button that implements the IBorder interface, generates the following for the class body:

public function MyButton() {    super(); } public function get borderMetrics():EdgeMetrics {    return null; }

${interface_name}

${class_name}

${package_name}

Specifies the interface, class, or package name.

Typically used when generating comments.

For example, the following template specification:

/*  * ${class_name} implements. . .  */

generates the following code:

/*  * MyButton implements. . .  */

Template Variable for CSS Files

Variable

Description

Example

${css_namespaces}

Defines namespaces for Spark and Halo style selectors.

Default values for Flex 3:

""

(In Flex 3, namespace declarations are not required in CSS files)

Default values for Flex 4:

@namespace s "library://ns.adobe.com/flex/spark"; 
@namespace mx "library://ns.adobe.com/flex/halo"; 

Template File Example

The following listing shows an example of an MXML Component file template, followed by a new MXML Component file generated from the template.

Example File Template for an MXML Component file

${xml_tag} 
<!-- 
* ADOBE SYSTEMS Confidential 
* 
* Copyright ${year}. All rights reserved. 
* 
* ${user} 
* ${project_name} 
* Created ${date} 
* 
--> 
<${component} ${xmlns}${wizard_attributes}> 
    ${wizard_tags} 
 
    <${ns_prefix}Script> 
    <![CDATA[ 
 
    ]]> 
    </${ns_prefix}Script> 
</${component}>

New MXML Component file generated from the example template

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
* ADOBE SYSTEMS Confidential 
* 
* Copyright 2009. All rights reserved. 
* 
* jdoe 
* FileTemplates 
* Created Jul 13, 2009 
* 
--> 
 
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/halo" width="400" height="300"> 
    <s:layout> 
        <s:BasicLayout/> 
    </s:layout> 
     
    <fx:Script> 
        <![CDATA[ 
         
        ]]> 
    </fx:Script> 
</s:Group>