Loading Variables From Query String Into Flash
Thursday, November 29th, 2007Categories: Adobe Flash
RSS Comment Feed
Trackback
The title says it all; I will go over loading variables from your query string (located in the URL address bar) into Adobe Flash. This can serve many purposes. For example, you can set a language toggle via query string. This way, you can avoid a language splash screen and avoid having 4 different files to go through and update each file individually. Of course, there are many other uses, but that’s just one that I thought of.
Basics
- A query string is located after the file name. I bolded it in the following example:
www.pat-burt.com/index.php?variableName=variableValue - Use SWFObject. I can’t emphasize it enough, SWFObject gives you many freedoms and options. To top it off, it’s simple to use. Another reason to use SWFObject is that this example uses SWFObject.
In Your PHP/ASP File
On the page containing SWFObject, make sure you have a valid file extension for the language you’ll be using.
You’ll have a line that looks similar to this:
<script type=”text/javascript”>
var so = new SWFObject(”flashFile.swf”, “Title”, “550″, “400″, “8″, “#ffffff”);
so.write(”flash”);
</script>
Before the so.write(”flash”);, copy and paste this line:
ASP
so.addVariable(”varInFlash”, “<%=request.querystring(”variableName”)%>”);
PHP
so.addVariable(”varInFlash”, “<?=$_GET[”variableName”]?>”);
Now what we’ve got is SWFObject passing the variable into Flash. Easy as pie.
Notes
- We have not done any treatment to the query string we’ve pulled from the address bar, I strongly suggest treating the variable before you post it in addVariable to avoid errors.
- SWFObject also uses the following line:
so.addVariable(”varInFlash”, getQueryParamValue(”variableName”));
Unfortunately, this doesn’t allow you to process the variable to avoid errors. You’ll have to take care of that in Flash. And if you’re Flash file is anything like mine, there’s a lot more room for ASP/PHP then there is for Actionscript
Using the Variable in Flash
As soon as you’ve done that, your variable is ready to use in Flash.
To check that the variable came in properly, create a Dynamic Text Box on your canvas and give it the instance name: textBox. On your first frame, type the following Actionscript:
textBox.text = varInFlash;
Run it, and voila, it works!
Hope that helped. Good luck. ![]()

Related Posts
- What You Need To Know About SQL Injection
- How To Send Data From Flash To ASP/PHP Without A Page Refresh
- Basic Actionscript Code Beginners Need To Know


