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.
Related
I have been search for a few days now for a way to work on this.
Basically I could like to send flashvars to my swf file using some backend language like PHP or Python, then execute it and capture the output.
I looked up to Ming but it seems that this is only a lib for create SWF file, not much on manipulate already created file.
Thank you!
If you need to do it 'on load basis', you can simply provide flash vars (for example put some flashvars depending on situation and embed the swf into html).
But if you need to have almost real time control over the flash, you have a few options:
socket connections - very hard (not to say impossible) to implement with php, and a kind of complex job
make the swf make a call to php, and get some information; then execute what you need depending on that information
I would advise you to use the second option - chose the action depending on situation, and let the swf client get it itself (either save it in file, db or calculate it realtime - it's up to you; the important is that you don't pass it to client, client makes query to get it).
I have a properly coded HTML page that I can display in my app.
The file is embedded locally inside the app, but it pulls in data from an API.
It is a Rest API that works with PHP.
So my question now is - is it possible to have NSString inject it's value into the php file so that it can display the required result, or are PHP and Objective-c not designed to do that??
If you are looking to actually parse and execute PHP in your iOS app, I am afraid you are probably out of luck.
If you simply want to dynamically update certain elements on a static HTML page and leverage a PHP service to do it, your best bet is probably to use javascript and AJAX to put the dynamic content from the service.
Alternatively, you can treat the HTML file like a template, make a call to the PHP service to get the dynamic content; merge that content into the template and display the template.
I guess what is most appropriate in your case, will ultimately depend on your desired user experience.
I need to pass private data from MySQL to a flash file securely. I have a PHP script that is assigning variables on the server side - how do I pass this to flash without being available publically? I assume XML and an HTTP query string are out of the question because of security. What's the most secure way of doing this?
Thanks!
Basically I have some file paths that I need to load into a music player - however, I don't want these URLs to be publicly known. I was hoping I could pass data directly to flash securely somehow.
Alternatively, should I be storing these documents as local file for flash rather than URLs?
If you pass "private" data to the client, he'll be able to read/decrypt it no matter what you do.
use htaccess and mod rewrite to dynamically create the filename based on something random that the flash can pass to your server
or
create a PHP session for the user and echo the file contents using PHP, if the session doesn't exist then PHP can just exit
How can you bring in a path as a variable from php? I have hundreds of mp3 file names stored in a My SQL database and I want to call the name, load it into a variable and then have it replace the URL in the call to the sound file. I am all set with the PHP and database side of things, but I have been frustrated with the Flash part. I think it would just involve passing a variable from php to flash. The web pages we are building would eventually have 10 - 15 files per page and each one would have a different sound file and a different image that you could click to trigger the sound. First click would start the file and the second would stop the sound. The images and sound files are all stored in the database.
I found this code on another post and it is basically what I want to do. Still missing the button part, but if I can figure out the variable from PHP I think it will open up a bunch of new options.
var soundRequest:URLRequest = "path/to/file.mp3"; //the path would be a variable passed from the database to php and then to the actionscript
var s:Sound = new Sound(soundRequest);
var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible number to flash.
//Above starts the sound immediatly (Streaming);
//Now to wait for completion instead, pretend we didnt start it before.
s.addEventLister(Event.SOUND_COMPLETE, onSComplete, false, 0, true);
function onSComplete(e:Event):void
{
var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible
}
If you have a click to trigger on the page then you should use Javascript to Flash communication on the page. One flash file and a communication to flash which file to play. With anything flash these days you've probably heard of SWFobject and with Javascript you've probably heard of jQuery. Well what you need is very well documented in the jQuery SWFObject
plugin.
There is a standalone example here.
http://jquery.thewikies.com/swfobject/example_flashInteract.html
It would make sense to send all the file names from PHP to AS3 and store them in an Array, after that everything can be handled on the client side.
You need to check for Flash / PHP communication , there are loads of tutorials available on the net. Here's an example.
Output mySQL data as XML with PHP
The basic idea is to call a PHP script which should return your mp3 information as XML or JSON. I personally favor JSON but you will need to download a library.
as3 corelib
After the data has been retrieved , you can create ValueObjects
Populating Value Objects with web service XML
You should end up with an Array of ValueObjects which can then assign to your various images.
You could create a specific class for each image that would take as parameter a ValueObject.
For more info on AS3 , go here
My flex 3.5 application has an audio player whose content is accessed by calling an AMF service to get the mp3 data. As far as I can tell, flash.media.Sound is initialized with a URLRequest, so it's not clear to me how I can provide it with data using my RemoteObject.
I want to do one of the following things:
Provide data to the Sound object's load method from a RemoteObject service call.
Create a URLRequest object that will perform the requisite AMF wrapping so that my service implementation will look exactly like any other service call if at all possible.
Any alternative that allows me to invoke a PHP4 AMF service and play the audio it returns in a Flash audio player.
If you absolutely have to use AMF to serve the sound, you have 2 options. The first is to wrap the MP3 in a swf, send it back as a ByteArray and use the loadBytes method on Loader to load it back in. The second option is to convert it to a wav, send it as a ByteArray, and then parse the audio file and feed the data to a sound using the sampleData event (Flash Player 10 only). I would probably recommend the first option, as it's a lot easier and faster than the second, but both aren't particularly easy.
If I had to authenticate through AMF to load sound, I would return a session cookie of some type and set up a simple PHP service that would serve MP3s with the proper session cookie.
You need to load the Sound from a ByteArray which is done here:
http://www.flexiblefactory.co.uk/flexible/?p=46
Why not use the Sound object with a URL parameter?
No need to write code to manually retrieve your URL. If you prefer to do some back end processing before returning the file, you can just set the return mimetype and 'dump' the data bytes of the mp3 file into the output stream.
With ColdFusion, this is easy using the cfcontent tag. I assume PHP offers some parallel, however I don't know what it is.