I had a conversation yesterday with a friend and colleague about how his company should standardise their development environment for all Flashers – be they contract or perm, junior to senior.
Category Archives: AS3
Posts related to ActionScript 3.0
Fastest way to add multiple elements to an Array / Vector in AS3
In a simple situation, where you wish to add many elements to an Array or Vector, you might just do:
var input:Array; var output:Array; while (input.length) output.push(input.shift());
However, the sizes of both Arrays are manipulated for each loop, which will have an adverse impact on speed and memory usage. So, we could cache the length of the input Array and not manipulate it:
var input:Array; var output:Array; var inputLength:uint = input.length; for (var i:int = 0; i < inputLength; i++) output.push(input[i]);
But we’re still growing the size of the output Array incrementally, which is very bad. Since we know input.length in advance, we could grow the output Array to its new size just once, before the loop:
var input:Array; var inputLength:uint = input.length; var output:Array; var outputLength:uint = output.length; var newOutputLength:uint = outputLength + inputLength; output.length = newOutputLength; for (var i:int = 0; i < inputLength; i++) output[i + outputLength] = input[i]);
This is OK, but still involves a loop. If only we could push multiple elements into the push method in one go. Well, we can – enter the apply method. Since Array.push accepts multiple arguments (something rarely used) and apply allows us to pass an Array of arguments to any Function, one line and we’re done:
var input:Array; var output:Array; output.push.apply(null, input);
This works out faster and more memory efficient than the other methods. It works nicely for Vectors, too. If anyone has a faster method of doing this, do let me know.
SWFIdle – simple flash idling utility
If you’re still churning out Flash banners, please use this!
I created this simple utility, called SWFIdle, to enable the Flash Player to lower its CPU usage while the user is not interacting with it. Since it’s possible to have multiple Flash instances embedded in one page (for example, a game and a couple of banners), I recommend using this in your projects, so that Flash instances needn’t fight for CPU and give Flash a worse name than it has already π
I know there’s the hasPriority embed attribute now. But:
- That assumes you have access to the HTML that embeds your SWF
- If no other players are present, it has no effect
- There’s still usually little reason to be running your SWF at a high framerate if the user isn’t interacting with it
- Flash banners with wastefully unoptimised drawing routines are probably one of the key reasons that Flash got poo-pooed off of mobile platforms and disabled on everyone’s laptops – CPU usage = battery usage!
ScratchPad – BlackBerry app
My ScratchPad app for Blackberry Playbook is now live. It’s a simple drawing app where you can export your creations to the image gallery. When the BlackBerry Playbook launched, there was nothing like this available, so I created it π If the Playbook does well, I’ll be creating more apps for the platform –Β it’s certainly a nice piece of hardware and BlackBerry OS is easy enough to work with.
You must be logged in to post a comment.