Retrieving GET variable via PHP, send to SWF on same script?
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!
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.
<object data=file.swf>
<param name=flashvars value="name=<?php echo $_GET['john'];?>">
</object>
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.
精彩评论