BIT-101 [2003-2017]

Simulating Flash Vars in the IDE


I do a lot of work with on-line apps that are customized at run time through Flash Vars. So I’ve devised a lot of different ways to fake them while testing in the IDE. At the end of the day, a Flash Var is simply a variable defined on _root.

Thus, the simplest way to simulate them is to create a variable on the main time line:

user_id = 1;

The problem is that I often have a bunch of these and when it comes time to deliver the final swf, these variables will overwrite the actual Flash Vars coming in. So they have to be commented out, or otherwise disabled. One thing I was doing for a while is this:

if(user_id == undefined)
{
   user_id = 1;
}

This has the added benefit of giving you a default value if no actual Flash Var is provided. Still, sometimes you don’t want a default value. And I hated going back and forth from my editor to the IDE timeline actions panel.

My second attempt was to just move the Flash Var declarations into the class itself, in an init function, or a setFlashVars function:

// in class:
_root.user_id = 1;

It took some gritting of teeth to get over the fact that I was writing “_root” within a class, but the use of Flash Vars is probably the one case where I consider it acceptable.

I still didn’t like mixing this stuff into my application class though. It’s not really part of what the class is responsible for. So I moved it into its own FlashVars class, which looks something like this:

class com.whatever.FlashVars
{
	public static function simulate()
	{
 		makeTest01();
// 		makeTest02();
// 		makeTest03();
	}

	private static function makeTest01(Void):Void
	{
  		_root.user_id = 8;
 		_root.section_id = 31;
	}
	private static function makeTest02(Void):Void
	{
  		_root.user_id = 9;
 		_root.section_id = 11;
	}
	private static function makeTest03(Void):Void
	{
  		_root.user_id = 85;
 		_root.section_id = 341;
	}
}

And in my class I just say:

com.whatever.FlashVars.simulate();

This allows me to create as many different configurations as I want, and easily test any one of them. And in the final run, I just comment that one line out of my class and publish.

« Previous Post
Next Post »