It’s the simple things that make me happy. Conditional compilation is one such thing and although it has been available since Flash CS4 those developing for mobile have been unable to take advantage of it. Why? Well to-date mobile developers have been limited to Flash Lite and ActionScript 1/2, whereas conditional compilation is only available when writing ActionScript 3.
This has been a real shame since Flash Lite developers arguably require conditional compilation more than any other Flash developer. Take my GamesFlash project as an example. I targetted over 50 different handsets and also wanted to ensure that it would run within a web browser for demonstration purposes. Considering the varying specifications across my target devices I quite often had to remove features from certain builds – streaming video being a feature that was only supported by the S60 devices. Without conditional compilation doing this can be a side-project in itself.
Sure, there are ways around it. For example, you can write multiple versions of certain classes (a feature rich version of a class for high-end handsets and a more modest version for low-end devices), store them in different folders, then using multiple profiles, point each profile’s class path to the correct folder for the version of the class that’s required. This approach works well for those going down the object oriented route, but for many Flash Lite developers this won’t be the case and including/excluding code from certain builds will suddenly become more difficult.
Thankfully developing iPhone apps using Flash CS5 won’t have these problems since it’s the first time that mobile developers using Flash will be able to take advantage of ActionScript 3. The following snippet of code illustrates just how useful conditional compilation can be:
private function setup() :void { CONFIG::WEB { // Add lots of complex shapes - we've got the CPU. addShapes( new ComplexShape(), 1000 ); } CONFIG::IPHONE_3G { // Add a modest number of simple shapes - we don't have much CPU. addShapes( new SimpleShape(), 50 ); } CONFIG::IPHONE_3GS { // Add lots of simple shapes - we have some more CPU. addShapes( new SimpleShape(), 100 ); } }
The example above expects there to be three config constants set via the Publish Settings panel in Flash: CONFIG::IPHONE_3G
, CONFIG::IPHONE_3GS
and CONFIG::WEB
. Depending on the build I want to make I can set certain constants to true or false, or alternatively create multiple profiles with different configurations for these constants and simply select the desired profile. This should make life so much easier.
So what about Flash Lite developers? Well if you’re developing for any of the current Flash Lite players you’re still going to run into the same frustrating problem. However there is light at the end of the tunnel. Flash Lite 4 and Flash Player 10 for mobile are on the horizon, and with both offering support for ActionScript 3, building for multiple targets will become a whole lot easier.