PDA

View Full Version : URL variable to flash



mikflash
November 13th, 2006, 02:55 AM
Hi guys,

I would like to know how to pass a variable from my URL

EG. index.php?page=something

into Flash using a non-server side script.

Thanks to anyone who can help out.

narcoticFunk
November 13th, 2006, 03:31 AM
Its done using FlashVars. You need to pass values from a querry string into your flash SWF, so the object tag holding your flash file will look like this:

if this is the value you need to pass,
http://www.mydomain.com/display.php?details=mikflash

Code for your <object> tag


<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="770" height="500">
<param name="movie" value="test.swf">
<param name="FlashVars" value="details=<? echo addslashes($_GET['details']); ?>">
<param name="quality" value="high">
<embed src="test.swf" FlashVars="details=<? echo addslashes($_GET['details']); ?>" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="770" height="500"></embed>
</object>

This will send the value 'mikflash' to variable '_root.details' in your swf.

Lemme know if this helps!

Cheers! :beam:

mikflash
November 13th, 2006, 03:45 AM
thanks for your help but unfortunatily our flash code is executed from within a .JS file which wont allow for any execution of server side scripting in our code.

Therefore I would just like a method that will pull a variable from the URL and pass into flash.

Thanks

narcoticFunk
November 13th, 2006, 04:35 AM
u can put this in your .JS file too, wherever your object tag is generated u just need to add an extra variable.

this isnt server side bro, it happens at client side.

Ben H
November 13th, 2006, 05:47 AM
There is a much easier way:

Calling a flash file with URL variables passes the variables to flash.

So file.swf?testvar=hello

would mean that _root.testvar = hello

Hope that helps a bit :)

-Ben

mikflash
November 13th, 2006, 08:58 AM
=<? echo addslashes($_GET['details']); ?>">


u can put this in your .JS file too, wherever your object tag is generated u just need to add an extra variable.


I am pulling the .JS file extrenaly so I can't see how I can execute what's inside the "<? echo addslashes($_GET['details']); ?>" from within my .JS file

?? Am I missing something?

Also Om3ga could you ellaborate a bit on ur post.. I'm not trying to pull a flash file from a URL i'm trying to pass a variable through to execute a MovieClip in my flash file.

Thanks guys

mikflash
November 14th, 2006, 02:41 AM
Does anyone have any ideas?

narcoticFunk
November 14th, 2006, 03:41 AM
aah, my bad. The code will look a lot different if its done using JS. I found a JS object code off the net and modified it a bit to do this. See it working here:

http://www.freakyfolio.com/junk/js_flashvars/test.html?passthis=mikflash

Get the files for this here:

Download ZIP (http://www.freakyfolio.com/junk/js_flashvars.zip)

Lemme know if you have probs figuring it out!

Cheers!

eslacker
November 14th, 2006, 04:50 AM
You'll either need to do it server-side (i.e. the FlashVars method) or have your JS parse the QueryString and send the values using SetVariables.

Here's a sample I found doing a quick Google...

http://www.oddhammer.com/tutorials/firefox_setvariable/

mikflash
November 15th, 2006, 02:24 AM
aah, my bad. The code will look a lot different if its done using JS. I found a JS object code off the net and modified it a bit to do this. See it working here:

http://www.freakyfolio.com/junk/js_f...sthis=mikflash

Get the files for this here:

Download ZIP

Lemme know if you have probs figuring it out!

Cheers!

Hey thanks for your help man.. I think i'm on the right track now.. I'm just gotta get it working in flash.. > hence my other post