Sunday, February 24, 2008

Multiple gotoAndPlay() considered harmful

When you are programming games (or all apps for that matter), one of the most important things is to make sure you maintain the states properly. By that I mean you do not want your game state to be in a state that you don't expect it to be. For instance, if your character is in running state, it shouldn't suddenly switch to hiding state without you knowing it.

Having multiple gotoAndPlay() in your code can corrupt your state very easily. It is like having the ability to modify a global variable anywhere you like, and it can create bugs that are hard to track down. Essentially, that's what gotoAndPlay() is -- it modifies the playhead info, and by using gotoAndPlay in more than one place, you have turned your playhead into a global variable.

It's for this reason that you should try to have only one place where gotoAndPlay() is called by putting it into a centralized function in your engine.

Saturday, February 09, 2008

Simple productivity tips for Flash developers

If you do Flash for a living, chances are that you work on projects that usually takes more than a few days to finish. You may find the following tips helpful:

Flash IDE
1) Edit->Preferences->On Launch, select Last Documents Open.
2) If you switch between workspaces often, you may find it helpful to save your Workspace using the Workspace button right below the timeline panel.

Flash Develop
(I hope you are using this editor, this is simply the best money can buy at the moment, not to mention it's free!)
1) Press F10 (or Tools->Program Settings). Select AS2Context or AS3Context, go to Common Section and set the value for Check Syntax on Save to true. I find this to be a timesaver, knowing that your code is always syntactically correct.

2) This snippet editor is another great tool in Flash Develop (under Tools->General Tools) I use the editor to define commonly-performed tasks such as defining variables, writing trace statements, etc. After you define your set of snippets, simply press Control+B to activate it in FlashDevelop.

e.g. I have defined a shortcut for trace statement:
t -> trace("$(Clipboard): " + $(Clipboard));

Now in FlashDevelop, I copy the variable I want to trace to the clipboard, enter t and press Ctrl+B, voila, the entire trace statement in its gloary. If you know of a faster way than this, let me know!

Tuesday, February 05, 2008

Have you ever wondered where a movieclip asset on stage is located in your library? Many times the folder structure that was there to provide organization ends up being an obstacle to you getting to what you are looking for. A quick way to find out where the asset is is by going to your Properties panel (Ctrl + F3) and click the Swap button. The dialog box that pops up will show you nicely where your movieclip is located in the forest of folders.