Posts Tagged ‘actionscript’

Instance names and code hinting – Tips & Tricks

Monday, March 2nd, 2009

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 popup (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

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

Make a button from a MovieClip – Tips & Tricks

Tuesday, February 24th, 2009

movieclipbtnIn the first meeting of A-SFUG I showed a tip about creating the up, over and down states of a button using a movie clip. I thought that I should put it up here as a reference.

An easy way of creating a button from a movie clip is to give the names of the frames with the different states of the button "_up", "_over" and "_down".

Add a stop(); frame on frame 1 of the movie clip. Then out on the main timeline, open the actions panel and write:

myButton_btn.buttonMode = true;

Just change myButton_btn to the instance name of your movieclip.

Now test the movie and roll over the button and It will now go to the over state. Press down on it and it will go to the down state.

So you do not need to write the code for on roll over, on mouse down and on roll out. Flash will automatically detect what you are wanting to do and do it for you.

Now you may be asking "Why should I do it this way? Why can't I just make it as a regular button?" Well you can still do it that way if you like, however the benefit of doing it this way is that a movie clip is more light weight then a button. This means that flash can run a bit faster.


Forget 25 lines. Try 140 Characters

Thursday, February 19th, 2009

A while ago I talked about the 25 lines competition which is a contest to see who can make the most spectacular thing with only 25 lines of code. Today Grant Skinner has announced on his blog a competition called #tweetcoding. Basically the contest is to create the coolest thing you can in AS3, with  only using 140 characters of code. If you enter you stand to win a copy of Flash CS4!

Details can be found here:

25lines finalists

Wednesday, December 17th, 2008

Here are the finalists of the recent 25 lines competition.

They are really impressive. You are able to view the code for each entry as well.