What is a Query String?
A query string is basically a line of variables along with their values in one big string. The idea is that you embed the variables in the HTML code and then flash will read them.
Let me explain by code - the following is the code used to import an .swf into a web page:
- Code: Select all
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/" width="250" height="300" id="flashMov1">
<param name="movie" value="flashMov1.swf?var1=hello&var2=world">
<param name="quality" value=high>
<param name="bgcolor" value=#FFFFFF>
quality="high" bgcolor="#FFFFFF" width="250" height="250" name="flashMov1"
Pay particular attention to this line "flashMov1.swf?var1=hello&var2=world". This is a query string. From this line we are telling the browser to display the 'flashMov1.swf' movie and pass in two variables - var1 which holds the value of 'hello' and var2 which holds 'world'.
A query string can have as many variables as you like in, however each must be seperated by an ampersand(&).
Now lets get flash to read in these variables. Flash will automatically do it for you and will assign the variables to either the _root or _level0. Therefore calling for the variable is as simple as this:
- Code: Select all
trace(_root.var1 + " " _root.var2);
This will return "hello world".
Hints and tips
- Do not use this to transfer sensitive data (such as passwords) as people will be able to view that data as it appears in either the html source code, the url or the headers.
- Spaces must be written as a + sign. For example if var1 was to contain the value 'dan wheeler', you would write 'var1=dan+wheeler'.
- Variables must not start with a number but can contain numbers after, they must also not contain spaces - instead you may use an underscore(_).
- If you wish the variable value to contain a full stop(.) then use %2E. For example the value 'dan.wheeler' would be written like so 'var1=dan%2Ewheeler'
- If you wish the variable value to contain a backslash(/) then use %2F. For example the value 'dan/wheeler' would be written like so 'var1=dan%2Fwheeler'
Extending the script