October, 2007


27
Oct 07

Wobbly springy physics

I recently needed to create something where a chain of spring dynamics points is connected with one smooth, seamless curve. After much mathematical wrangling, here’s the result of my efforts…


14
Oct 07

Flash 10 sneak peek

Adobe shows off some of the eagerly-awaited new features of Flash 10 – coded-named Astro:


13
Oct 07

Flash performance tips

Here are a few simple tricks that may help the performance of your code/graphics intensive Flash movies. This is not an exhaustive list, by any means, rather some of the more effective performance tweaks to try out on your projects. There are the usual sensible coding tricks, like using local variables for oft-used references within functions, or planning your code loops carefully and breaking out of loops whenever feasible - but you should be doing these already. I'll be adding to this post as and when I feel necessary, but will generally avoid the more granular tricks, such as bytecode optimisation. Some of those methods are too complex to explain in simple terms here and generally have a low effort-to-benefit ratio anyway:

Use scrollRect in conjunction with cacheAsBitmap. The cacheAsBitmap parameter of a movieclip can improve performance dramatically, but will cause problems if the render area of the movieclip gets too large (e.g. larger than 2880 in width or height), regardless of whether it is cropped by the viewable area of the Flash Player. The solution is to use scrollRect to constrain the rendering area to desired limits, in this example, the stage width/height:

import flash.geom.Rectangle;
scrollRect = new Rectangle(0, 0, Stage.width, Stage.height);
cacheAsBitmap = true;

Create bitmap snapshots of complex movieclips. Where you may have a movieclip full of layered graphical effects that isn't animated, you can save a lot of rendering time by creating a snapshot of the movie. Similar to the cacheAsBitmap parameter, but will improve performance further if your movieclip comprises many lines or alphas. The following function shows a quick and dirty way of duplicating a movieclip as a snapshot of the original:

import flash.geom.*;
function createSnapshot (base:MovieClip, mc:MovieClip):MovieClip {
var bounds = mc.getBounds(base);
var bmpWidth = bounds.xMax-bounds.xMin;
var bmpHeight = bounds.yMax-bounds.yMin;
var bmp1 = new BitmapData(bmpWidth, bmpHeight, true, 0x00000000);
var snapshot = base.createEmptyMovieClip("snapshot"+base.getNextHighestDepth(), base.getNextHighestDepth());
snapshot._x = mc._x;
snapshot._y = mc._y;
var rect = new Rectangle(0, 0, bmpWidth, bmpHeight);
var pos = new Point(0, 0);
bmp1.draw(mc, new Matrix(mc._xscale/100, 0, 0, mc._yscale/100, mc._x-bounds.xMin, mc._y-bounds.yMin));
snapshot.attachBitmap(bmp1, 1, "auto", true);
snapshot._x = bounds.xMin;
snapshot._y = bounds.yMin;
mc.unloadMovie();
return snapshot;
}

Use the opaque window mode trick - sparingly! Setting the wmode=opaque HTML parameter of your Flash object can improve rendering performance, but at a potential cost. Not only does it make the rendering order of movieclips and frames more 'lazy', but will effect keyboard interaction adversely in some browsers (especially FireFox). Use with caution.

I'll be updating and tracking back to this post occasionally, so stay tuned...


11
Oct 07

Wells and Bath, Somerset

Bath Spa cathedralI went to see my mum in Wells at the weekend, picked blackberries to make a crumble, tormented the dog and generally chilled out. It's the smallest city in England and where they filmed Hot Fuzz.

I took the train to Bath Spa, so there's a couple of snaps from there too.


11
Oct 07

Fun with noisy filters

I've been playing with animating perlin noise and using it at a displacement map. Here's a little example of what I mean (source).


10
Oct 07

Colin Moock’s intro to AS3

Here's a video for those of you looking to start on the ActionScript 3.0 path. Colin Moock will also be doing a free AS3 tour, look out for the dates here.


9
Oct 07

Webcam motion detection in AS3

I converted the old webcam motion detection thing to AS3 today. Not that it improves the performance much, just wanted to play around with it (source).


3
Oct 07

Some light reading

Advanced ActionScript 3.0 With Design PatternsJust finished ActionScript 3.0 With Design Patterns, recommended to me by Jo Rufian. It introduces ActionScript 3.0 nicely, while pointing out the best practices and common pitfalls. It covers the more popular and useful design patterns and will change the way you code.

However, it had quite a few code typos - most are easy to spot and may be corrected in the next edition anyway - but you will need a sound knowledge of ActionScript already to find this book useful. Despite that, well structured and highly recommended.