1

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
}

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Do you know how I could get a copy of the FLA for this example, just so I can see what is going on in the flash file? Can the "<input type="button" onclick="play();" value="PLAY" />" also pass along the name of an MP3 file to the player (to an audio player), so that in one click you can say "play this audio file inside the audio player" from a bunch of different links on a page? I still have to find or figure out how to build an audio player that contains a variable for the audio file, instead of a fixed file name. The player would not show on the page, just there to play each file.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.