Posts RSS Comments RSS 71 Posts and 117 Comments till now

Instance names and code hinting - Tips & Tricks

 

code_hintingWhen coding in actionscript sometimes it can be a pain that you don’t get code hinting with objects that are on stage. A good way of overcoming this is to change the instance names of your objects (Movie Clips, Buttons, etc.) to have an underscore “_” then the abbreviated name of that object at the end of the name.

For example, you may have a movie clip on stage called myMovieClip. Change the instance name to have an _mc at the end (myMovieClip_mc), and now in your actions panel type myMovieClip_mc and press period. You will now see all the code hinting for a movie clip pop up (see image). This can save a whole heap of time when coding.

Here is a list of the different shortcuts that you can use to bring up the code hinting. Some of these are for AS2 but the rest will work with AS3.

Object type Variable suffix
Array _array
Button _btn
Camera _cam
Color _color
ContextMenu _cm
ContextMenuItem _cmi
Date _date
Error _err
LoadVars _lv
LocalConnection _lc
Microphone _mic
MovieClip _mc
MovieClipLoader _mcl
PrintJob _pj
NetConnection _nc
NetStream _ns
SharedObject _so
Sound _sound
String _str
TextField _txt
TextFormat _fmt
Video _video
XML _xml
XMLNode _xmlnode
XMLSocket _xmlsocket

Update: The best method for code hinting for objects that are not on the stage is to use strict data typing. 

For example:
var myArray:Array = new Array();

I find that using this technique saves me a whole heap of time when programming.

6 Responses to “Instance names and code hinting - Tips & Tricks”

  1. on 11 Mar 2009 at 7:33 pmMrSteel

    cool, but you are enough hardcore to switch to some better editor, it’s unrealistic to program in Flash IDE :)
    my choice is still FlashDevelop even FDT is getting more popular
    it will give you all the pleasure of real OOP and hinting and a lot more

    http://livedocs.adobe.com/flash/9.0/UsingFlash/help.html?content=WS3e7c64e37a1d85e1e229110db38dec34-7f9f.html
    ActionsPanel.xml contains code hinting preferances

  2. on 11 Mar 2009 at 10:06 pmShang

    well, this little trick also works in flashdevelop.

  3. on 12 Mar 2009 at 12:16 amEd

    Thanks Shang. Yeah this work in FlashDevelop, doesn’t seem to work in Flex Builder and I’m not sure about FDT (does anyone have FDT to see if it does work?). I’m a big FlashDevelop user as well.

  4. on 17 Mar 2009 at 5:50 pmChris

    Seems that we all go full circle;

    Back when I first started C/C++ I was using EDIT - yes the evil dos editor - and after a short time got into Visual Studio and it’s lovely intellisense (code hinting) and couldn’t look back.

    Now about 4 years on, even with new languages I don’t use hinting any more and even find it annoying; It’s great when you’re getting used to a language during the initial stages but I always feel that the actual documentation plays a much better role than trying to guess which function does what and then trying to read through the arguments of that function — Go find the documentation and some examples and you’ll learn a lot more.

    Given, if you’re just lazy and can’t remember function names or argument layout it’s always nice to have a little help but thankfully I seem to remember most of this stuff to the point that I don’t even think about code hinting any more.

    Most of the open source alternatives (eclipse included) don’t seem to feel as nice as the one in Visual Studio so maybe they’re just not good enough; I did notice VS now pulls in adjacent comments from functions and classes to give you even more detail about the item which seems to help a lot more.

    Second issue that annoys me about the built in editor for flash is what you post above; Why should I name my variables in such a way to help the editor? The editor should just be smart enough to figure it out - reminds me of the good ol’ vb days of ‘btnOkay’ and ‘lblName’, heh. I hated that. :-p

  5. on 17 Mar 2009 at 6:02 pmEd

    Chris I use this code hinting method mainly to speed up development time because it will fill in those extra characters for you. And yes the actions panel in Flash is really bad but if you are doing a quick job like a banner then its a handy tip.

    What you should do if you are not referencing an object on stage (like a movie clip, button or text field) is to give it a data type. ie. var myArray:Array = new Array();
    This will also allow for code hinting in both the actions panel and in external tools like FlashDevelop.

Trackback this post | Feed on Comments to this post

Leave a Reply

For spam filtering purposes, please copy the number 1716 to the field below:

Pingbacks/Trackbacks

  1. [...] Instance names and code hinting – Tips & Tricks [...]