Amethyst Tutorials

Back to -Tutorials -Amethyst Tutorials

ActionScript Snippets in Amethyst

How to use and create code snippets using the Snippet Editor

The latest beta of Amethyst (our IDE for developing Flex, AIR and ActionScript applications) includes auto-expanding snippets or ‘code templates’. And, if you want to create your own snippets, it also has a snippet editor...

Snippets are great time-savers. They give you a way of entering long code blocks without having to enter it longhand. Just enter a snippet ‘shortcut’ such as the text ‘foreach’...

...then press the Tab key to turn the shortcut into the entire code of a ‘for each’ block:

The highlighted areas are ‘edit points’. Your cursor is placed on the first edit point so that you can change it to the desired identifier, then you tab to the next edit point to edit it and so on. Press Enter when you have finished.

Snippets can also be selected from a drop-down menu which appears when you right-click and select ‘insert snippet’...

And, optionally, the snippet shortcuts can also be shown in the code completion lists:

You can tailor the options for snippets in Tools, Options, Text Editor. Select either ActionScript, IntelliSense or MXML, IntelliSense. Here you can enable or disable the display of snippets in completion lists and the auto-expansion of snippets by the Tab character:

We support different ‘context sensitive’ sets of snippets for ActionScript and MXML. When you are editing ActionScript code, one set of snippets appears; when you are editing MXML code, a different set of snippets appears...

As well as simply expanding, some snippets can also auto-enclose a marked block of text. For example, if you mark a block and right click to insert the ‘try’ snippet...

...the marked code will be placed between the ‘try’ brackets when the snippet is expanded:

Currently a small number of ‘demo’ snippets are supplied with Amethyst (more will be added later). It is quite simple to create your own, however. Load Sniped!, the SapphireSteel snippet editor from the Amethyst menu:

The first thing you may want to do is set the default directory in which its snippets will be saved. Do this from the Sniped! Tools/Configure menu. Browse to a snippets directory (the supplied snippets are stored beneath \Program Files but Windows may not allow you to save new files there so choose somewhere else). Then add your name or company name to identify the snippet author and check ‘show tooltips’ if you would like tooltip help hints to be displayed by Sniped!. Then click OK.

For each interactive ‘edit point’, you need to create a new ID...

If you want to make this snippet surround marked text (like our ‘try’ snippet) be sure to check the ‘SurroundsWith’ box in addition to ‘Expansion’...

You can create the snippet itself by entering the code plus any IDs to indicate edit points. IDs can be selected from a right-click menu. To mark the place where any selected code will be placed, choose ‘selected’ from the right-click menu. To mark the spot where the cursor will be placed when the user presses Enter to end snippet editing, select ‘end’ from the menu. Then save the snippet and it is ready to use.

You can let Visual Studio find snippets in your your snippet directory by selecting the Visual Studio Tools menu then ‘Code Snippets Manager’. Click ‘Add’ to browse to your snippet directory.

Sniped! was originally developed for our Ruby On Rails IDE, Ruby In Steel. The version supplied with Amethyst supports the creation of Ruby, Rails, VB and C# snippets in addition to ActionScript and MXML. Be sure to select the snippet language before saving your snippets. Sniped! comes with a comprehensive PDF manual (currently this refers specifically to Ruby but all the same features are available for MXML and ActionScript). View the manual by selecting ‘User Guide’ from the Sniped! Help menu...

Bookmark and Share   Keywords:  Amethyst  tutorial
© SapphireSteel Software 2014