Search code examples
jsonactionscript-3flashsandbox

Flash sandbox not enabling me getting JSON data from server - AS3


i'm setting up a local SWF file that has to display some JSON data retrieved from a remote web server in some dynamic text fields. Code:

Security.allowDomain("api.yourserver.com");

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://api.yourserver.com/yourendpoint");
request.method = URLRequestMethod.GET;
request.contentType = "application/json";

loader.load(request);
loader.addEventListener(Event.COMPLETE, decodeJSON);

function decodeJSON(event:Event):void{
var loader:URLLoader = URLLoader(event.target);
var Info:Object = JSON.parse(loader.data);
cont.textfield1.text = Info.text.field1;
cont.textfield2.text = Info.text.field2;
cont.textfield3.text = Info.text.field3;
}

Control > Test - It works. When run standalone it doesn't. I get the 2028 error (sandbox violation).

What i tried:

  • The LoaderContext method explained here on StackOverflow but i get a 2124 error (Loaded file is an unknown type - seems like the Loader method can only be used with stuff like SWF or medias like JPG etc.);
  • Setting local playback as described always here on StackOverflow but it didn't help;
  • Setting up and exception in the Global Flash Player Trust directory as explained here but got the 2028 again;

Anyone who was able to overcome this and willing to explain how or at least pointing in the right direction?

Thanks in advance!


Solution

  • I think that your current published file has just assess to local files only and not network ones, that's why you got security #2028 error.

    To avoid that, you can change the Local playback security for your published swf from the Publish Settings to Access network only :

    If you still get security errors when testing locally ( like #2048 error ), take a look on my answer of this question to add your local swf file to the trusted locations ...

    Hope that can help.