views:

1034

answers:

4

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!

+4  A: 

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.

Ron DeVera
Ok. Is it possible to control the ActionScript 3 publish settings in code then?Thank you for your response!
Tom the Junglist
+2  A: 

A good idea is to use a visual hint when your in debugging mode. When the DEBUG flag is set, display a TextField with 'debug mode' and maybe version number, or something like that, in one of the corners of the screen.

When your doing your final tests before sending it to a client, you will see you've forget to disable DEBUG mode.

It surely depends on how you structure your project. As described in another answer, it's good to store the flag in a high level 'global' class accessible through the whole application.

Sander Versluys
+7  A: 

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.

Lillemanden
Awesome! Though, it would seem this sort of thing is not available in CS3, right?
Tom the Junglist
Yes, I'm pretty sure it's a new feature in CS4. But I'm not 100% sure.
Lillemanden
A: 

I use a flashvar called "TestingEnvironment". On application start, I check in loaderInfo.parameters to see if it's set to 'true' (a string literal, not a boolean), and if it is, I set a public static var debugMode on a global Environment class instance to true. Then all my classes can see that we are in a testing environment, and will act accordingly.

Also, since I use different page code to embed for testing and production, I expect the flashvar never to end up in the production page embed. And if it does, it's simple to turn off, no recompile needed.