views:

172

answers:

2

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?

A: 

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.

Anon.
Definitely not crossdomain, it's on the same server, same domain, and I never use www. so there's no mixup there. As for the specified path relative to the page and not the swf, I just ran into that same info over here, so there's consensus: http://stackoverflow.com/questions/108276/how-to-play-a-sound-in-actionscript-3-that-is-not-in-the-same-directory-as-the-swWeird behavior, odd choice on the part of Adobe, I must say... ...but that said, it still doesn't work. I should be able to link an absolute path, right? as in: **fsp.swf?file=http://mydomain.com/projects/fsp/music/song.mp3**
WittyBanter
Belay THAT! Got it working, I a kink left in the code from adding all kinds of double-checkers in the past couple hours as I was wracking my brain trying to get this thing to work. AS you said, it was that the link has to be relative to the embedding html page, and not the embedded swf. Anyone running across this page in the future, please refer to Brian Hodge's comment here: http://stackoverflow.com/questions/108276/how-to-play-a-sound-in-actionscript-3-that-is-not-in-the-same-directory-as-the-sw
WittyBanter
A: 

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.

sberry2A
Thanks, that was indeed it. For anyone reading this page in the future, also refer to Brian Hodge's comment here: http://stackoverflow.com/questions/108276/how-to-play-a-sound-in-actionscript-3-that-is-not-in-the-same-directory-as-the-sw"All external assets called from the SWF are relative to the html file loading them when loaded on the web, not the SWF. The only exception, and this is something that started with AS3, FLV's are relative to the SWF, not the HTML document loading the SWF like every other asset. "
WittyBanter
If my answer was correct, you should mark it as accepted by checking it off. Happy to help.
sberry2A
Whoops! Done. New here, as I said. Regards. :)
WittyBanter