My as3 code to load external sound:
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, onSoundLoaded);
var req:URLRequest = new URLRequest("getfile.php");
s.load(req);
function onSoundLoaded(event:Event):void
{
var localSound:Sound = event.target as Sound;
localSound.play();
}
Then my php code to return the file:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
In onSoundLoaded event, how do i get the actual filename return from the php response?
They way to solve the problem is to use URLLoader http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html to load the data instead of using the Sound class. This is because you can listen to the HTTPStatusEvent.HTTP_RESPONSE_STATUS – http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html#event:httpResponseStatus event that wraps the response headers (which include the filename). The listener for event complete can be used unmodified as in your code because it returns the same data.
The solution is not exactly what you want (finding the file name in onSoundLoaded function), but I think it is the best way to go. Hope it helps