是闪存异步还是同步的外部接口?

时间:2012-01-10 10:02:17

标签: javascript flash actionscript

我将致电flashObject.httpRequest以通过Flash完成http请求。 问题是没有参考httpRequest异步方法还是同步

这对我的申请很重要。

    private function httpRequest (uri:String, param:String="", method:String="GET"):void
    {
        var 
            urlRequest:URLRequest = new URLRequest(uri),
            urlLoader:URLLoader = new URLLoader();

        method = method.toLowerCase();

        switch (method) 
        {
            case "get":
            urlRequest.method = URLRequestMethod.GET;
            break;
            case "post":
            urlRequest.method = URLRequestMethod.POST;
            break;
            default:
            urlRequest.method = URLRequestMethod.GET;
        }
        urlRequest.contentType = "text/plain; charset=utf-8";
        urlRequest.requestHeaders.push(new URLRequestHeader("X-Requested-From", "Flash"));
        urlRequest.data = param;
        urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
        urlLoader.addEventListener(Event.COMPLETE, urlRequestComplete);
        urlLoader.addEventListener(IOErrorEvent.IO_ERROR, urlRequestError);
        urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, urlRequestError);
        urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, urlRequestProcessing);
        try {
            urlLoader.load(urlRequest);
        } catch (error:Error) {
            ExternalInterface.call("onerror","error");
        }
    }

1 个答案:

答案 0 :(得分:0)

httpRequest是一种Sync方法。 :)