AS3 + HTTP GET doesn't work

前端 未结 2 1572
滥情空心
滥情空心 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).

提交回复
热议问题