Actionscript3 SecurityError#2048

时间:2015-09-02 22:02:47

标签: php actionscript-3 url

我从PHP服务器加载数据时遇到问题。我可以简单地通过链接访问它,但是当我尝试加载它时就像在这个帖子中一样加载它:Get and parse JSON in Actionscript它不起作用。

它只是抛出一个事件

  

[SecurityErrorEvent type =“securityError”bubbles = false   cancelable = false eventPhase = 2 text =“错误#2048”]。

我该怎么办? 我已经阅读了有关跨域策略的内容,所以我将文件crossdomain.xml添加到PHP服务器,如下所示:

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

我尝试在几乎所有地方添加此文件。我可以做些什么吗?

负责加载此数据的代码:

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);
    }

1 个答案:

答案 0 :(得分:1)

你在哪里添加了crossdomain.xml? 基本上,它应该添加到根目录 在这种情况下

  

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

默认情况下,flash会自动从root加载crossdomain.xml。

如果您无法添加,请在此处添加

  

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

并手动加载。

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");
}