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

Home > Blogs > Custom File Templates in Flash Builder

Custom File Templates in Flash Builder

The Flash Builder IDE is a powerful tool, making Flex development that much easier. You can streamline your development process even more by taking a peek into the application's Preferences panels to customize its behavior to suit your style. One tweak that will pay off immediately is to edit the file templates, as I'll explain here.

File templates are, as you would expect, models for how new files should be defined. When you create a new Flex project, ActionScript class, CSS file, or even something as simple as an item renderer, Flash Builder uses the associated file template to pre-populate the new document. If there's code you commonly want in these documents, instead of adding the code to each new file, place it in the template to save yourself the time. Here's how...

1. Bring up the Flash Builder Preferences panel.
2. In the Preferences panel, under Flash Builder, select File Templates.
3. In the list of templates, click on any individual one to see the template code (Figure 1).

4. Click Edit to bring up the editor window.
5. In the editor window, tweak the code as needed (Figure 2).

It may help if you've already created the some of the sample code in Flash Builder so that you can just paste it in here. Anything with the syntax ${var} is a placeholder that will be replaced in the generated file with an actual value. You should probably leave anything that includes the term "wizard" in there, as that data will come from the new <thing you're creating> wizard.

6. Click the Variables button to find other placeholders you can use. There aren't too many, but things like the current date or the current file name may be of use, particular in predefined comments you might add.
7. When you're done with the file template, click OK (in the editor window).
8. When you're done with every file template, click OK in the Preferences panel.

Those are the basic steps. How you use this information is really dependent upon how you program.  For example, I don't care for the default minimum size entered into my MXML Web Application file, and I normally like to start with a vertical layout, so I change that template accordingly. I would also highly recommend you include some default comments in your files: who created it, when, why, etc. Good documentation is a hallmark of a professional application and yet is something easily omitted. By including those basics in your templates, you'll get your code off on the right foot.