One great feature in Flash Builder 4.5 is the Code Templates feature. I wrote about these a bit when the public beta came out last fall, but I wanted to share more about them.
The templates (also known as “snippets”) feature allows you to define chunks of code that you use repeatedly. The templates show up as code hints, so to access a template just hit Ctrl+Space (or another key that you’ve defined to trigger code hints) and you will see them in the list.
Hit Ctrl+Space again to filter the code hints so that only template code hints show up.
Only the code hints that apply to the context where the cursor is positioned show up in the list–for example, if the cursor is inside a method, you won’t see the template for creating a function, but you will see the template for a for loop (“fori”).
Accept the code hint and the template is inserted:
One of the best things about templates is they really are “templated” as their name suggests. You can define variables in templates, and they show up as outlined areas in the inserted code (as shown in the image above). (See my post on creating templates and using template variables for more on template variables.)
You can hit TAB to jump through the different variable positions. Usually there is also a tab location at the end of the template (sometimes it’s specified as a location within the template) where you can go when you’ve finished building it out.