A while back I wrote a tutorial that explained how to get flash to interact with a webpage using PHP to exchange variables - however not everyone is fluent in PHP and might think its a bit of a long method just for something so simple. Therefore I am going to teach you about Query Strings.
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:
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:
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 scriptYou can take this even further if you so wish and use PHP, ASP, JSP or Javascript to pass in variables to the query string. If you are familiar with these languages then it should be a doddle. An example of this can be found here:
http://x2i4eva.com/flatest/?var1=hello&var2=world