Passing variables to actionscript from PHP/MySQL to play a audio file - php

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

Related

Control a SWF file using backend programing?

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).

iso - Loading a local php file UIWebView and adding information

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.

Share excel data across real-time?

I have developed a VBA spreadsheet that runs locally and with obtain data from other sources continuously.
I want to find a way to extract / access the data inside this spreadsheet through php and then output some processed data using a browser and these data will update accordingly as the spreadsheet updates itself.
Anyone can show me how to achieve this? Both the spreadsheet and the php will run locally on a windows machine if that is easier...
Thanks very much for your help :)
I just developed an application that does this the idea is to use http requests on_change events in the spreadsheet.
vba code for request in excel
Function httpRequest(ByVal path As String) As String
Set HttpReq = CreateObject("MSXML2.ServerXMLHTTP")
HttpReq.Open "GET", path, False
HttpReq.Send
httpRequest = HttpReq.ResponseText
End Function
On your php side you have to develop the part where the data is mapped in the database. And of course the view of the data. As for realtime you have to go for something more elaborate like a table that holds the latest changes and check for such changes every now and then unless there is some mechanism to do so.
In excel there exist timers to acomplish polled checking for updates
for web you should to use ajax for seamless updates have a look at http://datatables.net/
You can use PHP Excel Reader to display the data quite easily from the spreadsheet - I think this is the simplest of the PHP Excel libraries that will do what you want and simply set the page to refresh on a regular basis.
Using this library is pretty much as simple as this:
<?php echo $data->dump(true,true); ?>
Once you have told it where the file is to display the output pretty much as would be expected to see in an Excel Workbook. (Here is a link to an example that they have up and running online)
This means you won't get any locking issues as the read is done rather quickly (assuming a reasonable file size and users won't really ever be more than a few minutes/seconds behind.
You want PHP to just generate HTML from Excel sheets? Excel supports HTML generation natively.
Try Save as Web Page to test the quality of HTML produced by Excel. If it's OK then all you'll have to do is write a small piece of VBA that will be generating HTML from your spreadsheets automatically.
Sort of CMS build in Excel.

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.

How can I convert my current page to pdf after some content dynamically added via AJAX?

I have found some libraries or web services in PHP that does the job. The problem is that the conversion is done when the page is fully loaded, I would like to convert the page to PDF after some content dynamically added via AJAX in onload event.
Thank you very much,
Omar
You could post back document.getElementsByTagName('html')[0].innerHTML to the server (possibly using AJAX) and generate a PDF from that.
When you add content with AJAX, that's only happening on the client's machine, so the server-side PHP conversion code will not work with it. You'll need to come up with a server-side method of including the dynamic content if you want to do the PDF creation on the server.
You could possibly implement an AJAX call that sent the page content/state back to serverside, after the dynamic contens is added, where it could be rendered as a pdf. You might not need all the page, depending on where this "dynamic content" is going to go.
Seems a bit messy, but without knowing the project it's hard to say whether there could be a cleaner method to do what you're trying to do.
This is a client-side requirement due to the Ajax situation. If they're using a Mac they can simply save as PDF but otherwise you have little control over what they can do.
What you can do however for a server-side implementation is keep a record of the page and all their AJAX requests since loading that page, and construct the HTML and PDF on the server from that record if it is requested. Of course this is not a simple task and quite overkill. You'd probably be better off having a different mechanism to create a server-side PDF report of a page other than turning HTML into PDF.
If your page can be updated solely on the client with no trip to the server, you'll have to post back up to your app. That way you'll have all the content and will not have rebuild, which would not be possible if there are client side only interactions.
Wow, thank you everyone I didn't know that this is comunity is so active. To answer Beepcake about the project:
When the page loads the app retrieves, from more than 40 servers, biological information via AJAX request, then a unique view is displayed where you can manipulate the graphic with many options.
So, the cool thing will be to print when the user makes his own version of the graphic. I think that the best solution is to POST the entire HTML with document.getElementsByTagName('html')[0].innerHTML as RoBorg has said and then generate the PDF with a library such as dompdf

Categories