How on earth do I get the parameters out of the querystring?

  • meyersas
  • Newbie
  • Newbie
  • meyersas
  • Posts: 5

Post 3+ Months Ago

I have been working on this issue for an embarrassing amount of time.

I am trying to figure out how to get flash to read parameters that are passed through a url as a query string.

For example, I may send an email to a client with a link such as:
<a href="http://www.yourdomian.com?id=20034"> so that they can view a particular product on my flash website.

When the user clicks the link, the url is correctly displaying the querystring above. But, I cannot get the flash file to get the parameter.

What code do I need to put into flash in order to be able to capture the id=20034 ?

Please save me :oops:
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Welcome to Ozzu Meyersas :D

First please take a moment to edit your post,(if you havent by the time i post this) the link is capturing the entire paragraph.

To capture querystrings in flash you need to declare that a variable with the same name of the var your going to pass with the querystring.
so if you need movie.swf?id=1234
In the main timeline you would put,
Code: [ Select ]
var id; //must be declared with var.

Best that any querystring variables are declared first and foremost. You can then use id as a variable in flash.

I dont know if this applies to many people anymore but this link may help. (macromedia tech note, "problem passing QsVars locally")
http://www.macromedia.com/support/flash ... _query.htm
  • meyersas
  • Newbie
  • Newbie
  • meyersas
  • Posts: 5

Post 3+ Months Ago

Thank you so much for your quick reply.

Even when I declare the variable that I am passing, I get an "undefined" instead of the parameter that I am trying to pass.

Help!
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

//edit, nevermind the actionscript i missed the ahref part before.

what is that id link going to? a default.php page, index.asp page, the swf directly ?
  • meyersas
  • Newbie
  • Newbie
  • meyersas
  • Posts: 5

Post 3+ Months Ago

For a simple test, I have a dynamic text box on the stage named myText_txt.


The actionscript is simply (test.fla):

var id;
myText_txt.text = id;

The html is:
Code: [ Select ]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<a href="test.html?id=20034"><img src="link.gif" width="450" height="45" border="0"></a>
</body>
</html>
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. </head>
  7. <body>
  8. <a href="test.html?id=20034"><img src="link.gif" width="450" height="45" border="0"></a>
  9. </body>
  10. </html>

Thank you, thank you, thank you!
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

you are going to need to have that page write the value of the querystring to the object/embed tags of the swf before it gets sent to the client.
index.asp wrote:
<PARAM NAME=movie VALUE="movie.swf?id=<%=Request.QueryString("id") %>">
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

hmmm, test.html has the OBJECT/EMBED tags for the SWF doesnt it ?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

If you have no ability to use ASP Or PHP or any other server side scripting then your limited to using Javascript to tear the url appart an build a querystring from it, then using the javascript to write that variable into the object/embed tags.

This link explains parsing a querystring with javascript,
http://www.eggheadcafe.com/articles/20020107.asp
  • meyersas
  • Newbie
  • Newbie
  • meyersas
  • Posts: 5

Post 3+ Months Ago

Have I thanked you yet?

I am confused, because even if I hard code the param tags into the html as follows:
Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
</head>
<body bgcolor="#ffffff">
<!--url's used in the movie-->
<!--text used in the movie-->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="550" height="400" id="test" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="test.swf" />
<param name="id" value="20034" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="test.swf" FlashVars="id=200034" quality="high" bgcolor="#ffffff" width="550" height="400" name="test" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>test</title>
  6. </head>
  7. <body bgcolor="#ffffff">
  8. <!--url's used in the movie-->
  9. <!--text used in the movie-->
  10. <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="550" height="400" id="test" align="middle">
  11. <param name="allowScriptAccess" value="sameDomain" />
  12. <param name="movie" value="test.swf" />
  13. <param name="id" value="20034" />
  14. <param name="quality" value="high" />
  15. <param name="bgcolor" value="#ffffff" />
  16. <embed src="test.swf" FlashVars="id=200034" quality="high" bgcolor="#ffffff" width="550" height="400" name="test" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
  17. </object>
  18. </body>
  19. </html>

I still receive an undefined value in the flash file.

What am I missing?

Also, you mention using PHP. How would I use PHP in this instance using an a href?

Thank you again!
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

meyersas, when posting code please remember to wrap it in [b]
Code: [ Select ]

[/b] or [b]
PHP Code: [ Select ]
 
[/b] tags, they result in easier read code than disabling BBCode & HTML :wink:
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Ok now back to the problem :D

Code: [ Select ]
<param name="id" value="20034" />

&
Code: [ Select ]
<embed src="test.swf" FlashVars="id=200034"

Need to be,
Code: [ Select ]
Object Tag Example:

<PARAM NAME=FlashVars VALUE="foo=Hello%20World¶graph=first+line%0Dsecond+line">

Embed Tag Example:

<EMBED src="display.swf" FlashVars="foo=Hello%20World¶graph=first+line%0Dsecond+line" ... (other parameters)> </EMBED>
  1. Object Tag Example:
  2. <PARAM NAME=FlashVars VALUE="foo=Hello%20World¶graph=first+line%0Dsecond+line">
  3. Embed Tag Example:
  4. <EMBED src="display.swf" FlashVars="foo=Hello%20World¶graph=first+line%0Dsecond+line" ... (other parameters)> </EMBED>

So the embed tag is right. (Tested in IE perhaps?)

As for the php part,
If you are able to use PHP (I'm guessing you are) then save that page as a .php page for the AHREF to link to and replace the foo=Hello in the flash vars with a php variable,
Code: [ Select ]
Object Tag Example:
<PARAM NAME=FlashVars VALUE="id=<?PHP $_GET[id] ?>">

EMBED Tag:
<EMBED src="display.swf" FlashVars="id=<?PHP $_GET[id] ?>"></embed>
  1. Object Tag Example:
  2. <PARAM NAME=FlashVars VALUE="id=<?PHP $_GET[id] ?>">
  3. EMBED Tag:
  4. <EMBED src="display.swf" FlashVars="id=<?PHP $_GET[id] ?>"></embed>

I'm not an sure if that's the exact PHP code(I know more about ASP) to do it with but hopefully it gives you the genneral idea.

Macromedia on flashVars,
http://www.macromedia.com/support/flash ... shvars.htm
  • meyersas
  • Newbie
  • Newbie
  • meyersas
  • Posts: 5

Post 3+ Months Ago

Thank you so much for taking the time to explain the steps to me. I will try working on this now. :D
  • sketch
  • Born
  • Born
  • sketch
  • Posts: 1

Post 3+ Months Ago

hi joebert

i was going through this thread, it's very useful..

for loading var in to flash.

still though i am facing additional problem to this...

i am having a "flash form application" flash file means in screen base structure.

in this file i am unable to load the var and it shows me as "undefined"

can u please explian me what's shd i do to work this out..

thanks

sketch
  • ShawnJC
  • Newbie
  • Newbie
  • User avatar
  • Posts: 5

Post 3+ Months Ago

Hey, just skimming this thread as it came up in an internet search where I was looking for compatibility of this procedure on the mac....
Anyway, it seems that people have explained how to pass the variables to the html via a server side scripting langauge very well, however the initual problem of undefined variable with the hard-coded string still seems to be an issue. I'll try my hand at it.
I think the problems is either caused by:
The variable trying to be used before it is received.
The textfield in the above example created at a wrong timing with the variable send.

First try to use trace(variablename) on the variable before attempting to send the information to a textField to avoid the second problem. Another suggestion is to try and set the trace on frame 10 or something of the movie to see if perhaps the variable hasn't been received yet before you are trying to call it. I know if you load variables from a textfile for example, you will need to wait an unspecified amount of time before they are available for use and this might be the same thing we are running to on this.
I've had scripts on a couple timeline layers that are both on the same frame, but functions in one layer aren't available the instant the movie is loaded. It's best to wait a couple frames whenever possible before coding to make sure the flash movie is loaded first.
  • contstrictor
  • Novice
  • Novice
  • contstrictor
  • Posts: 26

Post 3+ Months Ago

Following from ShawnJC's post, i believe that there's even an easier way of sorting out the variable loading problem. That is by using the LoadVars method. Because then you can use onLoad to check and see if your variables are all there and if they are you can the set the textfield to display the values.

As for passing variables into flash via the URL i always use PHP for that. with the GET method (provided it's not a password or something). I then get PHP to echo(or print) something flash can understand like
Code: [ Select ]
print "&id = yada yada yada&"

I then load the php file into flash using my good old LoadVars you really can't go wrong on that.

Hope this helps anyone reading. and if you want me to explain further well PM me or go to mysite and contact me or something.
  • ShawnJC
  • Newbie
  • Newbie
  • User avatar
  • Posts: 5

Post 3+ Months Ago

Constrictor. I'm a little confused on how your method works. You are saying that first you post variables via the URL query string (In the address bar, not in the flash HTML tag) and then receive that variable in PHP. Is the flash movie embedded in this php page that is receiving variables from the query string?
Then you said that you use php to echo something back to the page. Will this be visible by the users?
I am just curious as I have never seen a method of sending variables to php then to flash with GET and then loadVars. The only way I knew of doing it (with full compatibility) is to send it to a php page in the URL query string, then use php to echo the variables into the flash MOVIE= tag as query string variables.
  • contstrictor
  • Novice
  • Novice
  • contstrictor
  • Posts: 26

Post 3+ Months Ago

Nope it's not, my suggestion is this.
You have a flash movie with the variables you wanna work with use the LoadVars Method and load it to a different php script you have written to work with the variables. eg
Code: [ Select ]
var varsOut:LoadVars = new LoadVars();
var varsIn:LoadVars = new LoadVars();
//varsIn is there if you want to use anything php returns
varsIn.onLoad = function(success){
if(success){
trace(varsIn.phpvariable);
}else{
trace("error loading from php");
}
}
/*Then this is where you send the variables to php and collect whatever php spits out whether its from a MySQL database or encryption or whatever....*/
varsOut.sendAndLoad("pathToPHPScript",varsIn,"POST");
  1. var varsOut:LoadVars = new LoadVars();
  2. var varsIn:LoadVars = new LoadVars();
  3. //varsIn is there if you want to use anything php returns
  4. varsIn.onLoad = function(success){
  5. if(success){
  6. trace(varsIn.phpvariable);
  7. }else{
  8. trace("error loading from php");
  9. }
  10. }
  11. /*Then this is where you send the variables to php and collect whatever php spits out whether its from a MySQL database or encryption or whatever....*/
  12. varsOut.sendAndLoad("pathToPHPScript",varsIn,"POST");

and that's it.
  • ShawnJC
  • Newbie
  • Newbie
  • User avatar
  • Posts: 5

Post 3+ Months Ago

Ok, yes I understand that, however I think this question is regarding getting the variables from the query string. In order to do that I think the only way is to write the query string variables from the URL into the flash movie tag from which there flash will receive the variables. For instance if you have a flash movie that displays a different image depending on which link you click on a PREVIOUS page you might find this way easier to post some variables in the query string like "test.com?image=1" from the link on the previous page. Then the flash movie tag could have
<param name="movie" value="somefilename.swf?image="<?=$imageName?>>
in which the $imageName variable is taken from the url query string in the server side language of your choosing. Flash will then have the image variable with the value selected in the _root of the movie. This would of course have to be done with the embed tag as well as the object tag.
  • contstrictor
  • Novice
  • Novice
  • contstrictor
  • Posts: 26

Post 3+ Months Ago

Well i haven't fully explored that area yet. So yes maybe you're right about that, it makes sense. I was simply suggesting a method that has worked for me and i prefer it because i can work with such variables however i like eg: Letting the user know what is loading where etc etc.

Post Information

  • Total Posts in this topic: 19 posts
  • Users browsing this forum: No registered users and 9 guests
  • 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.