Browsing the topic Coding
I just discovered a really nice thing (thanks to Pernilla) using multiple conditions (&&, ||) in the if…else conditional statement in Actionscript. The thing I did not know (you probably did) is that the statement do not check the remaining conditions when a condition is not fulfilled. If you look at the image below you can see that we get a crash on line 32 but not on line 28. This is because we add a check to see if _userVO exists before we check the contents. We also get a crash on line 38 because we check the conditions in the wrong order.

This little tip will help me save some lines of code.
I got some xml text line break issues in my latest project. The texts look good viewing them locally, but when uploading the project to the customer server I get a lot of extra line breaks. I am not really sure why this problem occurs but I guess it has to do with the server platform. I tried to save the xml with a different encoding but with no luck so I wrote this simple method. It works.
public function fixLineBreakIssues(value : String) : String { return value.split("\r").join(""); } // usage txtField.htmlText = fixLineBreakIssues(xmlText);
Commas or spaces can be used to make reading numbers a little easier. They are placed every 3 decimal places for numbers comprising 4 digits or more. I wrote a AS3 method that returns the nicer format.
$1000000
$1 000 000
public static function separateByThousand(valueNumber : Number, splitter : String = " ") : String { var valueString : String = ""; var valueLength : Number = valueNumber.toString().length; for (var i : int = 0; i < valueLength ; i++) { if ((valueLength-i)%3 == 0 && i != 0) valueString += splitter; valueString += valueNumber.toString().charAt(i); } return valueString; }
separateByThousand(1000) //1 000
separateByThousand(100000) //100 000
separateByThousand(1000000) //1 000 000
separateByThousand(1000000,”,”) //1,000,000
It is hard to remember the whole ASCII key list when listening to keyboard events in Flash Actionscript.
Example:
I usually use the Keyboard Class (flash.ui.Keyboard) when tracking keyboard inputs but it does not contain all the keys you may want to use. Instead of googling tables with Keyboard keycodes I made this SWF to get quick access to the codes via the KeyboardEvent (flash.events.KeyboardEvent) class.

The latest release of Motor2 is using the Vectors class which means you have to compile your files for Flash player 10. If you for some reason don’t want to change to FP10, Michael (developer of Motor2) has the solution:
replace all Vector occurrences with Arrays
http://groups.google.com/group/motor2/browse_thread/thread/182291562d7dfd9a
I have been reading some blog posts on how to use a Finite State Machine (FSM) in game development. According to Wikipedia, a FSM is a model of behavior composed of a finite number of states, transitions between those states, and actions. Richard Lord wrote a post about FSM in Actionscript and I am thinking of trying it out in my next game. I usually use a control class for the methods controlling a character but in complex games they attend to grow and become hard to keep track of. Using a FSM might (will) solve my problem and may even generate some good reusable states.
What the hell, I will try it out! I´ll keep you posted about the progress.
Motor2 version 0.9 is released and can be downloaded here:
http://code.google.com/p/motor2/downloads/list
Take a look at the changelog:
http://code.google.com/p/motor2/wiki/Changelog
I have been working on a skateboard game at work using the Motor2 physics engine. I am looking forward to the feature where you can change the groupIndex (used for collisions) runtime to be able to use the rails I have set up in the world. Michael who develops the Motor2 engine says he will soon release a new version. Really great. Eventually I´ll share some code and screenshots from the game.
One problem when exporting scripted animations to video is that the overall animation is not finished at the last keyframe in main timeline. This could result in a video where the animation is cut before it is finished. I found out you can export your animation based on time rather than timeline frames.
This video tutorial from Layer Magazine explains how to export a scripted animation to Quicktime format (mov) directly from Adobe Flash CS. I don’t understand why they made such a long video tutorial because the only important thing is the export settings.

Stop exporting “After time elapsed [time]“.
(I used Adobe Flash CS4 for this example but it works just as well in CS3).



