一个 AS 函数提交 POST 请求到服务器,但是当通过ExternalInterface.addCallback暴露给 JS ,用 JS 调用时,该请求就直接被忽略了,也没有什么错误或者异常出现。
这个是什么原因呢?好奇怪
public function saveFileToServer(data:ByteArray, filename:String, whenDone:Function):void {
        var values:URLVariables = new URLVariables();
        values.key = "Message";
        var header:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
        var request:URLRequest = new URLRequest("/save");
        var data = getData();// function to get data to post
        request.contentType = "multipart/form-data; boundary=" + UploadPostHelper.getBoundary();
        request.requestHeaders.push(header);
        request.method = URLRequestMethod.POST;
        request.data = UploadPostHelper.getPostDataMultiFiles(
            {
                data:data
            } );
        var loader:URLLoader = new URLLoader();
        loader.dataFormat = URLLoaderDataFormat.BINARY;
        loader.addEventListener(Event.COMPLETE, whenDone);
        loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,function(err:ErrorEvent):void
        {
            Scratch.app.logMessage("Failed server request for ");
            ExternalInterface.call("console.log", "SECURITY_ERROR");
        });
        loader.addEventListener(IOErrorEvent.IO_ERROR,function(err:ErrorEvent):void
        {
            Scratch.app.logMessage("Failed server request for ");
            ExternalInterface.call("console.log", "IO_ERROR");
        });
        loader.addEventListener(ProgressEvent.PROGRESS,function(event:ProgressEvent):void
        {
            ExternalInterface.call("console.log", "PROGRESS");
        });
        try {
            ExternalInterface.call("console.log", "Before load");  //正常输出
            loader.load(request);    // 用 JS 调用时,没有效果,没有请求出现。
            ExternalInterface.call("console.log", "After load");   //正常输出
        }
        catch (error:ArgumentError) {
            trace("An ArgumentError has occurred."); // no error caught.
        }
        catch (error:SecurityError) {
            trace("A SecurityError has occurred.");
        }catch (error:*){
            trace("other errors");
        }
    }
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.