Notes
Notes: Loop Optimizations 2
This is kind of an extension of my previous loop tests I did. I ran into this while making improvements to Orion. I was really surprised there was this much of a difference in speed. The discovery I made after looking into BetweenAS3 and the efforts of Joa Ebert on his AS3 particles I noticed they were using LinkedLists to manage large numbers of objects. LinkedLists are only good if the you don’t have to remove items from the list as that can be a painful experience. But adding to and iterating through the list is blazing fast as denoted below.
Notes: Positioning Optimizations
This page sort of expands upon the previous post I made on loop optimizations. I’m going to use this post in the future as a catchall for any other optimizations I run across. So for now I just have one to list, but hopefully in the future I’ll add some more.
Edit: (Sept 8th 2009) Ok I was kidding, I think I’m going to make separate posts each time. That way it shows up as a new post and people actually notice it. The “optimization” tag can be used to filter out just these posts.
Modifying a DisplayObject
Using a Matrix to modify a DisplayObject is faster than editing the individual properties.
// 1 Million runs 2578ms, 2583ms, 2572ms spr.transform.matrix = new Matrix(spr.scaleX * 0.98, spr.scaleY * 0.98, 0, 0, spr.x + pt.x, spr.y + pt.y);
is faster than
// 1 Million runs 3597ms, 3609ms, 3569ms spr.scaleX *= 0.98; spr.scaleY *= 0.98; spr.x += pt.x; spr.y += pt.y;
Notes: AIR
Some notes I’ve gathered over time in regards to AIR. As per usual, just posted up here for future reference.
Multiple Monitors
When building an app for multiple monitors, be sure to make use of the flash.display.Screen class. This class lets you iterate through all of the monitors available with access to the size and resolution of each. It also can tell you which is the primary monitor. Below is a useful function to grab the current screen.
private function getCurrentScreen():Screen {
return Screen.getScreensForRectangle(stage.nativeWindow.bounds)[0];
}
Notes: Loop Optimizations
Here is some testing I did to determine the best kind of loop to use in AS3. In the end the fastest I determined was a simple reverse while loop. Below is the results with the code for my testing beneath that. Where I could, I tried to run 1 million items in the collection. If I was unable to do that (the program would crash) I would run 500k items. From what I have learned, using the Array.forEach() is kinda expensive for what it does. Standard for() loops aren’t too bad, but the for…in() loops are even worse than the Array.forEach(). If you know of anything faster methods or maybe I tested incorrectly please let me know!
› Continue reading
Notes: CSS StyleSheets
Note: A text field with a style sheet is not editable. In other words, a text field with the type property set to TextFieldType.INPUT applies the StyleSheet to the default text for the text field, but the content will no longer be editable by the user. Consider using the TextFormat class to assign styles to input text fields.
Flash Player supports a subset of properties in the original CSS1 specification (www.w3.org/TR/REC-CSS1). The following table shows the supported Cascading Style Sheet (CSS) properties and values, as well as their corresponding ActionScript property names. (Each ActionScript property name is derived from the corresponding CSS property name; if the name contains a hyphen, the hyphen is omitted and the subsequent character is capitalized.)