ActionScript Smart Tags
Normally, in IntelliSense, you can get information when an ‘event’ like typing a ‘.’ or an opening parenthesis occurs. However, when you are refactoring – for example, encapsulating a field – you normally have to select the field, right click, and choose ‘Encapsulate Field’ from the context menu. But there’s a better way: a Smart Tag.
Smart Tags have been around for some time. They usually occur in Office documents and, it has to be said, they are usually insanely irritating: “did you really want to split that infinitive, Stupid?”. These Smart Tags occur as areas in a document that pop up and bite you as you hover over them with a mouse.
In Visual Studio, they work somewhat differently and are a whole lot more useful. For example, if you have a statement like this :
var v:int = 1;
and you change if to this:
var vv:int = 1;
then you’ll get a little red oblong underneath the modified variable like this: Hovering over this with a mouse displays a small icon: and clicking on this gives the context menu: from which you can do a global rename – either with a preview or without.
I’ve implemented two other Smart tags. First, an ‘import’ Smart Tag. If I type a statement like this the Smart Tag appears at the end, and if I hover and click, I get this: If I click the menu item, the correct import statement is generated. Now, you can argue that import statements should be automatically inserted here, but that’s not my preference (though I may include as an option later on). But the real reason is that you might have more than one import that matches: and now you can choose the one you really want.
The final Smart Tag is the one I like best! If you type a statement like the smart Tag menu displayed is: and you can encapsulate the field (add a get and set) to get this: It saves a lot of typing!
It’s taken me some time to build the Smart Tag technology into Amethyst – there’s just about zero documentation on how to do it. But having do so, I can see a whole new field of adding additional information and error checking to ActionScript documents. I’ll try and avoid anything too irritating, though.