The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 5:43 am

Forum rules


IMPORTANT

This Forum is for Flash related questions ONLY! Do not ask questions about spriting, Game Maker, Photoshop, or anything else not related to Flash.



 [ 4 posts ] 
[Tutorial] Query Strings with Flash 
Author Message
User avatar

Joined: Mon Aug 11, 2008 1:09 pm
Posts: 166
Location: England lol
Gender: Male
Currently Playing: Minecraft
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:

Code:
<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>
  <embed src="flashMov1.swf?var1=hello&var2=world"
    quality="high" bgcolor="#FFFFFF" width="250" height="250" name="flashMov1"
    type="application/x-shockwave-flash"
    pluginspage="http://www.macromedia.com/go/getflashplayer">
  </embed>
</object>


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:
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
You 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


Thu Dec 04, 2008 8:37 pm
WWW
User avatar

Joined: Mon Aug 11, 2008 6:56 am
Posts: 469
Location: not so superhappy fun fun land....
i'm confused, would this be making a blank website pop up and saying "hello world" or just say "hello world" in flash?

_________________
Image

ashante08 wrote:
We argue, we try to understand each of our problems, we argue some more, rinse and repeat


Thu Dec 04, 2008 9:34 pm
User avatar

Joined: Mon Aug 11, 2008 1:09 pm
Posts: 166
Location: England lol
Gender: Male
Currently Playing: Minecraft
johnnyg5646 wrote:
i'm confused, would this be making a blank website pop up and saying "hello world" or just say "hello world" in flash?


It's used to import variables into flash from off a web page.

I'm pretty sure Youtube uses the same concept. When you type a youtube URL, the actual query string in the url tells the flash player to load a particular .flv file, thats how it knows what video to play.


Thu Dec 04, 2008 10:31 pm
WWW
User avatar

Joined: Mon Aug 11, 2008 6:56 am
Posts: 469
Location: not so superhappy fun fun land....
x2i wrote:
johnnyg5646 wrote:
i'm confused, would this be making a blank website pop up and saying "hello world" or just say "hello world" in flash?


It's used to import variables into flash from off a web page.

I'm pretty sure Youtube uses the same concept. When you type a youtube URL, the actual query string in the url tells the flash player to load a particular .flv file, thats how it knows what video to play.

oh, thats useful. thanks for the tutorial.

_________________
Image

ashante08 wrote:
We argue, we try to understand each of our problems, we argue some more, rinse and repeat


Fri Dec 05, 2008 7:42 am
Display posts from previous:  Sort by  
 [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.