Wednesday, August 17, 2011

Quick and Dirty Url Parameter Decoding / Debugging in Flash Actionscript Example

Here's a quick and dirty way to parse url parameters and debug without hooking up to a debugger in Flash


//pretend the url is http://rockgrummbler.com/index.html?name=radguy
var urlString:String = ExternalInterface.call('window.location.href.toString');
var parametersString = urlString.substr(urlString.indexOf('?')+1);
var urlVariables:URLVariables = new URLVariables(parametersString);
ExternalInterface.call('alert',urlVariables.name);

What you should see, if this code was implanted in your flash application, is a javascript alert window pop up with name 'radguy' in it. ExternalInterface lets you take advantage of the more then likely presence of javascript in your environment. Using the already present alert functionality in javascript could save considerable time when you can't easily connect your code to a debugger. (Like when trying to debug a kiosk app you can't directly interface with)