views:

109

answers:

3

Is it possible to retrieve a GET variable within a PHP script and subsequently send the variable data to an SWF on the same script/document?

I want the user to select an item on a PHP document and then use a Flash application I am developing to manipulate that data.

I know how to load data from a PHP script into an SWF via URLLoader, but only by initiating the loading process from within the SWF. So, I am asking if it's possible to send the PHP data to the SWF from external source. Would the SWF need to listen in some manner? Is Javascript necessary here?

Any advice is greatly appreciated!

+1  A: 

i believe you're looking for flashvars. its basically a parameter for the object/embed tag that you put what looks like a querystring into. the querystring is then accessible through the flash object.

check out this tutorial for a more in depth explanation.

nathan gonzalez
@nathan Thanks, the tutorial seems well-written, but I cannot get it to work. `var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;` works fine, but `paramObj['filename']` returns null when flashvars is set like this: `<param name="FlashVars" value="filename=somename.jpg">`. I am testing this in the browser. Any idea why it is not working?
letseatfood
do you have a test page i can look at?
nathan gonzalez
Yes, here it is: http://www.miketmoore.com/flash_image_cropping_app_01/
letseatfood
(the file is `index.php`)
letseatfood
you've got the proper html, its just in the noscript block. move it into the main html and you should have it working.
nathan gonzalez
@nathan Thanks. I ended up needing to remove the javascript that Dreamweaver drops in for flash, as well. Works now though!
letseatfood
+2  A: 
<object data=file.swf>
<param name=flashvars value="name=<?php echo $_GET['john'];?>">
</object>
meder
this is how its done... have done this many times with php pages with flash embeded.
David Morrow
A: 

If you're looking to load information from PHP after the SWF object has already been loaded then I would suggest you use XML or JSON to send/request information from the server. JSON is probably easier as you can just call json_encode and json_decode on the PHP side. Here is some information about parsing JSON on the flash side. http://www.cakesgood.com/2009/04/flash-cs3-actionscript-30-json-keep-it_3277.html

If you're just looking to pass data from PHP to the SWF file once on load then using flashvars as mentioned in the two previous answers would likely be your best bet.

Also, if you're trying to have the server directly communicate with the flash SWF file then you can either use flash to poll the server for new data every X milliseconds.

AWinter
Thanks @AWinter. I am still trying to get FlashVars to work after reading the tutorial in @nathan's answer. I am now looking into JSON, since I haven't used it before.
letseatfood