5

Hii, I'm tring to load swf file to my flash application from a different server. When i try to load it on flash IDE (crl+enter) everything is working fine, but when i run the swf as an independent swf file or by debugging it, i'm getting this error:

SecurityError: Error #2121: Security sandbox violation: LoaderInfo.content: file:///C|/Users/something/Desktop/blablabla/myplayer.swf cannot access http://www.somedomain.com/blablabla/lalalala/abc.swf. This may be worked around by calling Security.allowDomain.
at flash.display::LoaderInfo/get content()
at wallplayer_fla::MainTimeline/swfLoaded()[wallplayer_fla.MainTimeline::frame1:216]
Cannot display source code at this location.

I have the crossdomain.xml file in the root of my server:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <allow-access-from domain="*" />
</cross-domain-policy>

In "myplayer.swf" I have:

Security.allowDomain("*");
Security.allowInsecureDomain("*");
...
...
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.checkPolicyFile = true;
loaderContext.allowCodeImport = true;

ldr = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
ldr.load(new URLRequest(graySwfFilename), loaderContext);
...
...
var mcExt;
var ldr:Loader;
function swfLoaded(e:Event):void {
    mcExt = MovieClip(ldr.contentLoaderInfo.content);
    ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, swfLoaded);
    mcExt.x = 0;
    mcExt.y = 0;
    addChild(mcExt);
}

I don't really know what to do... Please HELP?

hdmi3killer
  • 89
  • 1
  • 1
  • 12

3 Answers3

9

Solution: for Flex 4.x (Currently 4.6) and AS3 in Flash Builder:

    import flash.system.SecurityDomain;
    import flash.system.ApplicationDomain;
    import flash.system.LoaderContext;
    var loaderContext:LoaderContext = new LoaderContext();
    loaderContext.applicationDomain = ApplicationDomain.currentDomain;
    loaderContext.securityDomain = SecurityDomain.currentDomain; // Sets the security 

context to resolve Error # 2121

... now load your SWF with

loader.load(new URLRequest(webServerWebURL),loaderContext);
Fans
  • 79
  • 1
  • 9
user1243531
  • 106
  • 1
  • 3
1

Add your working folder in the Global Security Settings panel. This allows you to load external files from a single SWF in your file system. Its the same if you want a.swf to load b.swf even if they is located in the same folder.

This will allow your SWF to read external files.

This should not be a problem if you upload you SWF to a server though.

Mattias
  • 3,907
  • 4
  • 28
  • 50
  • WOW! Thanks man! But Its going to fix the problem only on my computer. If I'm going to upload this player to some site over the internet, its not going to fix it... doesn't it? – hdmi3killer Apr 08 '11 at 12:51
  • Can i achieve the same results when implementing myplayer.swf in a website? – hdmi3killer Apr 08 '11 at 14:24
  • @hdmi3killer swf's have local to global loading restrictions. Once on a server these restrictions don't affect loading – jolyonruss Apr 08 '11 at 14:46
  • the solution you gave me succeed when i run it on my computer in the exact folder i specified, but as i tried to run it as an embedded on facebook (when its on my server), it fails to fetch the abc.swf. Do you have any ideas? – hdmi3killer Apr 08 '11 at 16:18
  • OK.. i figure it out! I just had to put allowDomain in the loaded swf instead of the loading swf!!! – hdmi3killer Apr 09 '11 at 16:31
0

Your error is from the external location not having a cross domain file, not you. Check out this tutorial on using a bridge file to communicate with an external api. I used as3 and php in this example. The trick is to maintain control of the cross domain file on your domain.Then let your server communicate with the api.

Aditya
  • 2,876
  • 4
  • 34
  • 30