background preloader

Flash

Facebook Twitter

AS3 Memory Management. After developing in C++ for several years, I must admit I found the idea of garbage collection in higher-level languages like Java, C#, and ActionScript to be alluring.

AS3 Memory Management

Making sure every "new" was matched by a "delete" was tedious but absolutely necessary. Like any serious C++ programmer, I developed patterns and habits for making sure the code I wrote was clean as I wrote it, because tracking down memory leaks after they've crept in is even more tedious than thinking about "delete" whenever I typed "new". My first experience with a "garbage collected" language was C# (.NET).

After getting deep into development of a new product, I quickly discovered that the garbage collector was really not so magical, and not even really that smart (at least not for a highly memory-intensive application). I learned that I had to think just as much about making sure memory was collected as expected and when needed as I did when writing C++. Now that the background is over, let's set the stage: Conclusion. Blog Archive » AS3 Math Optimization – int is the new floor() UPDATE : The benchmarks on this thread were taken in the Flash 9 Debug player (which includes some crazy bloating) - I've posted an updated set of tests here using the Flash 10 Release player, which should give you a better picture of real-world savings for the majority of web users. In case you missed my earlier post , I've had a raging Flash-on for optimization lately, and today I'm jumping into the Math class. But first! A little warmup with operators. I've often heard that addition is fastest, followed by subtraction and multiplication, with division being the slowest but I'd never seen any proof so I threw together my own test: Way to go subtraction, almost 12% faster than addition!

Alright - the Math class. While a lot of the Math methods are invaluable (Math.atan2 == ♥), there are also a few that aren't as complex and slow your swf down unnecessarily. Or you can replace costly comparison calls with a little logic: (i % 1) ? Further reading : Joa Ebert on optimization. CODE. Utility Classes Here are a pair of loaders I rely on. These guys take the boiler plate work out of loading images and swfs and let you get back to writing real code.

Pic - load, display, and clone images as easily as creating a Sprite. [ post ][ code ][ zip ][ docs ] SWF - load external swfs that behave like local MovieClips. Benchmarking {AS3 speed testing, performance} Here is the code I use to generate my speed benchmarks. mark I mark II Fast Rounding {optimized, Math.round(), int} Using an int-cast instead Math.floor or Math.ceil is an old AS3 trick, but it just occurred to me that you can mod that idea for rounding. Function round ( n: Number ) : int { return int ( n + . 5 ) ; } Suicidal EventHandler {self removing, automatic} I learned this from an old friend and colleague; tuck this little gem into an event handler function and it removes the listener automatically. Function onSomeEvent ( e :Event ) : void { e . target . removeEventListener ( e . type , arguments . callee ) ; // ... } Building Flash Multiplayer Games - Introduction - Player.IO. Player.IO has moved, and is now part of the Yahoo Games Network.

Building Flash Multiplayer Games - Introduction - Player.IO

Don't worry, your games still exist, and your current username and password still works on the new site. More good news - we are listening to your feedback that the current pricing model is complicated, making it difficult for you to predict your costs. We hope you will be happy to hear that on June 1, 2014, we are simplifying it. Here's an overview: If your game has less than 5000 Daily Active Users: No charge.

Read the details of the new Terms of Service.