Hints and tips

Flash CS4 to Flex Builder 3 migration for ActionScript 3.0 (AS3)

Thursday, June 18th, 2009

We have been working for five months on a medium-scale app for a large multi-national company. As we approached the beta phase, requests for new functionality started coming, but with 25,000 lines of ActionScript, it was already taking over 45 seconds for the app to compile from the Flash IDE. I made the call to migrate the project over to Flex, and this will be the basis of the discussion as to why every ActionScripter still using Flash as their compiler and IDE should move to Flex Builder.

Over a short series of articles, I hope to shed some light on the reasons. To sum them up:

  1. Every time you save a class, your app compiles in the background – meaning you NEVER need to wait for that “Exporting SWF Movie” dialogue box ever again. This alone is enough once you get into a big app…
  2. SVN support – in layman’s terms, great version control. You work on a class, and when you are happy, you save (”commit”) a new revised version with comments as to what you’ve done. When your app reaches a stable state, you can save it all as a safe working version and press on. You can always compare old versions and retrieve them if need be.
  3. Profiling your apps – if you’ve been used to relying on “trace” statements to debug your apps, you will not believe the precision with which you can dig into the performance of your apps. As well as realtime memory graphs, there are many excellent tools available. For example – loitering objects – take two snapshots of your app’s memory usage over time as it runs, and you can compare the two, seeing not only what objects are still hanging around, but where they came from in the first place – astonishing!
  4. Testing in the browser – you get a much better feel for how things will really work
  5. Creating Flex libraries – for many Flash devs, this is a bit of a nightmare at the beginning, as we’ve been used to setting one preference to give all projects access to whatever classes we like. Its a bit more complex in Flex, but once you’ve compiled your most useful classes, its a breeze to export and use them, and all makes sense

The aforementioned app is built in PureMVC, and is due pretty soon, so I don’t imagine I’ll have a chance to publish anything before then… but I do hope it will help people through the “banging head off wall” phase that I went through on the early days of trying to make the app work in Flex Builder.

Ultra-compact crossfades with TweenLite

Tuesday, March 10th, 2009

I love TweenLite, Jack Doyle’s lightweight tweening engine. Its a bit of a cheat, but we’ve all got to have our little tricks and time-saving moves when deadlines are looming and your fingertips are melting.

I’ve just been coding up a short script to crossfade video stills as you flick through using a navigator. I won’t go into the full code, but let’s suppose you have an array of display classes that hold images, and you are just looping through them. If you have a function called say 'showImage' with one parameter 'state' which is set to true or false – depending on whether you want to show or hide the image – then with TweenLite, you can do this:

public function showImage(state:Boolean) : void
{
  TweenLite.to(this, state?0.5:1, {alpha:Number(state), visible:state});
}

And that’s it. What that means is that if you call 'showImage(true)' on one of your objects, it will have its 'visible' property set to true, and fade to full visibility in 0.5 seconds. If you call 'showImage(false)' on one of your objects, it will fade to alpha zero in 1 second (causing a nice overlap), then have its 'visible' property set to false on completion. Nice one, Jack.

If you haven’t that many objects, and don’t want to have to load up your server with a stack of calls to reload images, this is a cool little routine. If you want source code, just comment… I’ll see what I can do.

Edit: following a comment by @Justin Flash I’ve found there is an even quicker way…

public function showImage(state:Boolean) : void
{
  TweenLite.to(this, state?0.5:1, {autoAlpha:Number(state)});
}

This assumes the “autoAlpha plugin” is activated in your TweenLite constructor.

Quicktime and a decompressor are needed to view this picture

Sunday, May 18th, 2008

I have found a solution for Mac users with Safari… Drag the image directly from the browser and drop on the Illustrator icon in the dock – and IT OPENS!!!

(Ben pointed out that this does not work on Firefox… strange)

A short post for Tweeners

Monday, April 28th, 2008

Forget Adobe’s Tween class.

Get thy ass over to Greensock and get TweenLite. I simply can’t believe how much it improved the performance of my stuff.

iPhone and SWFObject

Tuesday, January 15th, 2008

I noticed that although SWFObject (javascript for displaying Flash with a reasonably graceful HTML fallback) works on iPhones from a javascript point of view, the Flash content itself fails. So iPhone users are left looking at a blank screen… hardly particularly cool, eh? Solution (uses PHP) follows…

(more…)