通过JS调用AS中的函数,进行POST操作时,到提交请求那一步就停了。如下代码,loader.load(request);
前一句还能正常执行,下一步就没有反应了,没有POST请求,也没有错误。
而直接在AS中调用这个函数,就可以正常提交。
Chrome中有如下错误,但是感觉不是这里的问题,别的浏览器没有错误。
Uncaught TypeError: Cannot use 'in' operator to search for 'rawScopes' in undefined
JS调用与AS调用有啥区别吗?
已经设置 <param name="allowScriptAccess" value="always">
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"); //this is line is logged successfully.
loader.load(request);
}
catch (error:ArgumentError) {
trace("An ArgumentError has occurred."); // no error caught.
}
catch (error:SecurityError) {
trace("A SecurityError has occurred.");
}catch (error:*){
trace("other errors");
}
}