Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Release/Debug Configurations with Flash + AS3

I recently ran into an embarrassing situation with some Flash coding where I had to accidentally sent clients a build where not all my debugging flags and variables were unset. (It was sending requests to the debug instead of release server, etc...)

Part of this was poor code organization on my part; I've resolved that.

However, Flash doesn't seem to allow one to set different build configurations, and the Actionscript Compile settings hosts a variety of switches arranged in such a fashion that forgetting to check/uncheck something (OMG, I forgot to disable debugger support!) might just happen, as it did with me. In any case, I find that manually jumping between my release config and debug config to be easy to screw up.

So, other developers, what techniques do you use to error-proof jumping between your testing config, and the build config that you issue to your boss/clients/whoever?

I know I should probably slow down but I would much prefer setting up something to where I could just flip a switch. I'm just jumping back into Flash after a long hiatus (Flash MX + a bit of 2004).

Oh, and I'm aware of the futility of disabling debug support and setting import passwords and all that, my goal is to simply keep the script kiddies out of my project. Decompilers trump all that so.....

Anyways, Thanks!

like image 989
Tom Corelis Avatar asked Mar 28 '09 00:03

Tom Corelis


2 Answers

If you're using Flash CS4 you can use config constants. You'll find them under Publish Settings|ActionScript3.0 Settings...|Config Constants

If you added DEBUG::PLAYER then you can use code like this:

config namespace DEBUG;

//... code here ...

DEBUG::PLAYER
{
    trace("Player state here");
}

Now you can just switch the constant between true and false.

like image 137
Jacob Poul Richardt Avatar answered Sep 24 '22 01:09

Jacob Poul Richardt


I use an environment class, like this:

public class MyEnvironment {
  public static const DEBUG:Boolean = true;
  public static const SERVER:String = 'localhost';
  // More here
}

Import this into your main ActionScript class, and make sure all of your helper functions reference it. For instance, your debugger functions should only run if MyEnvironment.DEBUG is true, and your network functions should send requests to MyEnvironment.SERVER.

In my setup, I'd save this as MyEnvironment.as. (Obviously, the class name would be different in real life.) I'd also save copies as MyEnvironment.as-debug and MyEnvironment.as-release; the latter would have different settings. Then, if I need a release build, my build script would copy MyEnvironment.as-release to MyEnvironment.as (overwriting the original), and recompile. That'll load all of my release settings into my main ActionScript class; opposite if I run the script for a debug build.

like image 26
Ron DeVera Avatar answered Sep 21 '22 01:09

Ron DeVera