0

I found an issue in my AS3 application. On my local machine everything is good, but when I sent it to my friend, he wasn't able to open it on his computer, because he got

Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: cannot load data from data.json

The same error happens when I upload my application to web. I can't play it and get the same error.

Here is my code:

var myTextLoader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("data.json");
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
myTextLoader.load(request);

...

private function onLoaded(e:Event):void 
{
            var loader:URLLoader = URLLoader(e.target);
            var myObject:Object = JSON.parse(loader.data);
}

How can I fix it? Please, help me if you can :)

bugs
  • 14,631
  • 5
  • 48
  • 52
  • I think that you have just to add your SWF to the trusted locations of Flash Player, for that, take a look on [my answer of this question](http://stackoverflow.com/a/28719316/2256820) ... – akmozo Nov 27 '15 at 01:10

1 Answers1

0

Local SWFs cannot get local filesystem access.

Online SWFs can access resources according to the same origin policy, or further if a crossdomain.xml is set.

You cannot fix this for local, but online SWFs should be able to do this.

Try:

var request:URLRequest = new URLRequest("./data.json");

Which means if a SWF is hosted at:

https://www.example.com/foo/flash.swf

It can access:

https://www.example.com/foo/data.json

apscience
  • 7,033
  • 11
  • 55
  • 89