AS3 + HTTP GET doesn't work

前端 未结 2 1556
滥情空心
滥情空心 2020-12-02 03:24

I have a project in Flash and I use a webserver with some data. I read that information (json) with:

var url:String = \"URL REQUEST\";
var request:URLRequest         


        
相关标签:
2条回答
  • 2020-12-02 03:35

    Most likely you are receiving a security error. Here are some steps you can take:

    1. Make sure to add the appropriate listeners to your loaders so you can properly handle errors.

      loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandlerFunction);
      loader.addEventListener(IOErrorEvent.NETWORK_ERROR, ioErrorHandlerFunction);
      loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandlerFunction);
      
    2. Make sure you are publishing with the correct security sandbox setting.

      Go to your publish settings file -> publish settings.

      You'll see a drop down labelled Local playback security. Ensure this is set to access network only and not the default access local only.

    If you handle your errors, you'll at least know what the problem is. If this doesn't solve your problem, add a global error handler and share what is being thrown (if anything).

    You can do that with the following on your main timeline or document class:

    loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
    
    function uncaughtErrorHandler(event:UncaughtErrorEvent):void {
        if (event.error is Error) {
            var error:Error = event.error as Error;
            trace(error);
        }
        else if (event.error is ErrorEvent){
            var errorEvent:ErrorEvent = event.error as ErrorEvent;
            trace(errorEvent);
        }
    }
    

    EDIT

    From reading your updates, it looks like you could easily resolve this by dishing out your swf from the Pi Node JS Server in the browser. (Publish with html then copy to the server then access it in your web browser).

    0 讨论(0)
  • 2020-12-02 03:38

    This is a classic security error which is fired when an swf try to load content in another domain other than its own and didn't has authorization to do that. So to avoid this type of security error, you have to create a crossdomain.xml file at the root of the server from where you want to load data. To more understand things, take a look on this schema ( taken, and edited, from Adobe Cross Domain Policy File) :

    enter image description here So in this case, to allow an swf file in a.com to load data from b.com, we have to add a crossdomain.xml file in the root of b.com, so we can access to it using b.com/crossdomain.com. For the content of this file and more details about it, you can see the link above of the crossdomain specification. It can be like this :

    <?xml version="1.0"?>
    <cross-domain-policy>
        <!-- if used alone, allow only all a.com requests but not its sub-domains -->
        <allow-access-from domain="a.com"/>
        <!-- if used alone, allow all a.com sub-domains and a.com requests -->
        <allow-access-from domain="*.a.com"/>
        <!-- if used alone, allow only b.a.com sub-domain requests -->
        <allow-access-from domain="b.a.com"/>
    </cross-domain-policy>
    

    I hope all this can help you to resolve your problem.

    0 讨论(0)
提交回复
热议问题