Wednesday, June 04, 2008

query variables in haXe




This one took me quite some time to research:

What I wanted to do was to have a way to pass a variable in a haXe script that I'm compiling down to Flash 9. There are a bunch of ways to do it, but the one that fit my needs the best was FlashVars.

To pass in a variable into your haXe/Flash script, you just need to either embed the parameters at the end of the URL, like this:


<embed src="testpassvariables.swf?test1=la">


Or use the FlashVars variable name, like this:


<embed src="testpassvariables.swf"
FlashVars="test1=la">


You then access this variable in your haXe/Flash script with:


trace("p=" + flash.Lib.current.loaderInfo.parameters.test1);


If you are running in the standalone Flash player, it doesn't look like you can pass in FlashVars, so you need to do something like:


if (flash.Lib.current.loaderInfo.parameters.test1 == null) {
trace("standalone and undefined");
}