0

I have a problem with loading data from my PHP server. I can access it simply by link but in actionscript when I'm trying to load it just like in this thread: Get and parse JSON in Actionscript it is not working.

It just throws an event

[SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"].

What should I do? I've read something about cross-domain-policy so I have added file crossdomain.xml to PHP server like this:

<cross-domain-policy>
     <site-control permitted-cross-domain-policies="all"/>
     <allow-access-from domain="*"/>
     <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

I tried adding this file almost everywhere. Can I do something more?

Code responsible for loading this data:

private function getURL():void
    {
        var request:URLRequest=new URLRequest("http://Journey.pe.hu/Journey/Users/");
        ExternalInterface.call("console.log", request.url);
        request.requestHeaders=[new URLRequestHeader("Content-Type", "application/json")];
        request.method=URLRequestMethod.GET;
        var loader:URLLoader=new URLLoader();
        loader.addEventListener(Event.COMPLETE, receive);
        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, notAllowed);
        loader.addEventListener(IOErrorEvent.IO_ERROR, notFound);
        loader.load(request);   
        ExternalInterface.call("console.log", "l1");
    }

    protected function notAllowed(event:SecurityErrorEvent):void
    {
        ExternalInterface.call("console.log", event.toString());            
    }

    protected function notFound(event:IOErrorEvent):void
    {
        ExternalInterface.call("console.log", "NOT FOUND");
    }

    protected function receive(event:Event):void
    {

        ExternalInterface.call("console.log", "Nameldasodoad");
        var loader:URLLoader = URLLoader(event.target);
        var jsonArray:Array = com.adobe.serialization.json.JSON.decode(loader.data);

        //ExternalInterface.call("console.log", "Name " + jsonArray[0].Name);
        //var jsonArray:Array = com.adobe.serialization.JSON.decode(loader.data);
    }
vimuth
  • 5,064
  • 33
  • 79
  • 116
borkowij
  • 182
  • 1
  • 3
  • 11
  • It's a security sandbox violation error which you can avoid for your local test by adding your swf to the list of trusted location, for that take a look in [my answer of this question](http://stackoverflow.com/a/28719316/2256820), and when testing online, you have to add a crossdomain.xml file ( which does not exist in your site ), for that take a look on my answer [here](http://stackoverflow.com/a/27581656/2256820). – akmozo Sep 02 '15 at 23:44

1 Answers1

1

Where did you add crossdomain.xml? Basically, it should add at root directory.
In this case

http://journey.pe.hu/crossdomain.xml

By default, flash loads crossdomain.xml from root automatically.

If you can't add there, add here

http://Journey.pe.hu/Journey/crossdomain.xml

and load manually.

private function getURL():void
{
    // load crossdomain.xml manually.
    Security.loadPolicyFile("http://Journey.pe.hu/Journey/crossdomain.xml");

    var request:URLRequest=new URLRequest("http://Journey.pe.hu/Journey/Users/");
    ExternalInterface.call("console.log", request.url);
    request.requestHeaders=[new URLRequestHeader("Content-Type", "application/json")];
    request.method=URLRequestMethod.GET;
    var loader:URLLoader=new URLLoader();
    loader.addEventListener(Event.COMPLETE, receive);
    loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, notAllowed);
    loader.addEventListener(IOErrorEvent.IO_ERROR, notFound);
    loader.load(request);   
    ExternalInterface.call("console.log", "l1");
}
Yasuyuki Uno
  • 2,417
  • 3
  • 18
  • 22
  • @bonio It seems that you added crossdomain.xml and I tested, but didn't work. I guess it caused by the settings of crossdomain.xml. Could you delete tag? Some settings are wrong. – Yasuyuki Uno Sep 03 '15 at 08:53