0

Trying to load Soundmanager2's SWF file from our CDN. I assume I'm running into cross domain flash issues. has anybody done this? it is even possible?

here's what I'm trying...

var allowxdomainscripting = true;
var xdomain = "*";
soundManager.url = 'http://cdn.mycompany.com/inc/soundmanager2.swf';

there's a very obscure reference to this in the documentation, but it's pretty vague...

http://www.schillmania.com/projects/soundmanager2/doc/generated/src/SoundManager2_AS3.html

any help is appreciated.

ditman
  • 55
  • 7
lyndonr
  • 15
  • 3
  • Where you are using those 2 vars: _allowxdomainscripting_ and _xdomain_ ? – Marcelo Assis May 09 '12 at 16:03
  • I assumed soundManger2 was listening for them.. although I just searched inside soundmanger2.min.js for that string and it's not mentioned, so I looked a little closer at the above link and it seems if those two vars are true then this paramater is set "Security.allowDomain(xdomain)".. at that point I'm a bit stuck. – lyndonr May 09 '12 at 16:48
  • I thougth that code was ActionScript. Is it JS? – Marcelo Assis May 09 '12 at 16:54
  • 1
    indeed it is.. calling a Flash file to play sound. – lyndonr May 09 '12 at 18:57
  • that is action script 3, i think you need to recompile the .swf file after adding in your extra domains. I am working on something similar, trying to add sound on ebay listings! – Treemonkey May 22 '12 at 11:03

2 Answers2

3

I ran into this as well at one point. SoundManager2 now comes with cross-domain versions of the swf files.

They are zipped up in swf/soundmanager2_flash_xdomain.zip

https://github.com/scottschiller/SoundManager2/tree/master/swf

Simply unzip and replace with the standard .swf files provided with SoundManager2 and your problem should go away.

amlutz160
  • 448
  • 5
  • 18
  • I tried this solution but got error aSound: Failed to load?... Is there any issue with SSL? I want to load a cross domain file with SSL so my URL is like "https:test.com/play.php?file=play.wav" – Mayank Pandya Mar 01 '13 at 00:05
  • there's shouldn't be any problems w/ SSL over x-domain. also, the url example you show is invalid (eg. https:test.com should be https://test.com – amlutz160 May 21 '13 at 22:33
  • I didn't really understand what was going on with my script but this was the solution. Thanks a lot! – Eugen Timm Jul 24 '14 at 11:52
3

THANK YOU VERY MUCH!

I stumbled upon this answer by total chance after wasting a couple of hours trying to get SM2 SWF embed to work.

I'm going to "revive" this to add a few keywords so Google indexes this answer... Maybe the next person trying to embed SoundManager2 SWF in a cross-domain environment gets it done a little quicker than I did :)

The error I was getting upon flash initialization was: Error calling method on NPObject

On the JS side, this was the code that broke everything:

// attempt to talk to Flash
flash._externalInterfaceTest(false);     <- KABOOM!

NPObject errors might have many meanings, but more often than not (in our environment) it means: You're trying to call the ExternalInterface through JS on a flash movie hosted on a different domain.

After a while I popped open SoundManager2 ActionScript 3 code and saw this:

public var allow_xdomain_scripting:Boolean = false;
public var xdomain:String = "*";

[... other stuff ...]

if (allow_xdomain_scripting && xdomain) {
    Security.allowDomain(xdomain);
    version_as += ' - cross-domain enabled';
}

Of course that means that the movie that you might be using (no matter if it's debug or not) will not be accessible from a different domain (a CDN, or whatever).

The solution was –as stated in @amlutz160's answer– to use the files contained in swf/soundmanager2_flash_xdomain.zip, which are compiled with allow_xdomain_scripting = true.

Posting this is quite embarrassing, and the solution is obvious, but I lost quite a bit of time with this and AFAIK the contents of that mysterious zip file are not documented anywhere (I found a tangential mention on SM2 forums).

PS: I'm forwarding this answer to Scott Schiller so maybe he can update SoundManager2 docs a little bit :P

Regards!

ditman
  • 55
  • 7
  • 1
    Added support request: [Improve documentation regarding cross-domain usage of SM2](https://getsatisfaction.com/schillmania/topics/improve_documentation_regarding_cross_domain_usage_of_sm2) – ditman May 31 '13 at 12:02