Problems with playing a sound in AS3 from a page that is not in the same directory as the SWF?
Hey Overflow. Long time listener, first time caller.
So here's what I've got: I'm trying to create a sound player in Flash/AS3 that will take an external MP3, load it in, and play it with Sound(). Your typical music player, nothing super fancy. The problem is that it works and everything, 开发者_开发百科just fine, throws no errors... until I link it from a different part of the site.
I'm keep the swf itself in mydomain.com/projects/fsp. I've got an MP3 I keep in a subdirectory of that directory at mydomain.com/projects/fsp/music/song.mp3 and the embed takes the mp3 location as a flashvar param: fsp.swf?file=music/song.mp3
If I test it out from mydomain.com/projects/fsp/index.html, it works just fine. The swf loads up, loads the mp3, everything works without a hitch.
However, if I instead embed the swf from any other location, for instance mydomain.com/blog, suddenly we're dead in the water. The swf loads, but the mp3 does not.
I'm puzzled as heck. The swf loads fine in both instances, it's just the second step of loading the mp3 that causes issues. Even though we're referring to the same sound file both times, and the actual swf is in the same location. This occurs when I embed both using absolute and relative (../projects/fsp.swf?file=music/song.mp3) references.
Any clues?
Depending on the way you are building your path to load the mp3, you may have an issue. The first thing I would do is use an http proxy like Fiddler, Charles or the built in proxy in Firebug. Look to see where the file is being loaded from. My hunch is that you are trying to load the file /blog/music/song.mp3, which probably does not exist.
You might be getting caught up by the crossdomain security stuff.
Do you have a working crossdomain.xml in the web root?
EDIT: Belay that. You need to specify the path of the mp3 file relative to the current page.
精彩评论