0

我正在使用 httpservice,一旦它被调用,什么都没有发生。我没有得到结果或错误?我添加了各种侦听器,但无法捕获任何错误。我错过了什么吗?

    private function GetUsersServers():void
    {
        var serviceObj:HTTPService = new HTTPService();
        serviceObj.resultFormat = 'text';
        serviceObj.method = 'GET';
        serviceObj.useProxy = false;
        serviceObj.addEventListener(ResultEvent.RESULT, GetUsersServersResult);
        serviceObj.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        serviceObj.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
        serviceObj.addEventListener(Event.COMPLETE, onLoadComplete);
        serviceObj.url = '************************';

        var parameters:Object = new Object();
        parameters["Username"] = m_strUserSIP;

        LogAddItem( -1, "GetUsersServers Request - User = " + parameters.Username);
        serviceObj.send(parameters);
    }

    private function onLoadComplete(e:Event):void
    {
        var loader:URLLoader = URLLoader(e.target);
        LogAddItem( LOG_CATEGORY_MAIN_DEBUG, "securityErrorHandler: " + loader.data);
    }

    // check for security error - probably crossdomain issue
    private function securityErrorHandler(event:SecurityErrorEvent):void {
        LogAddItem( LOG_CATEGORY_MAIN_DEBUG, "securityErrorHandler: " + event);
    }

    public function onLoadError(e:IOErrorEvent):void {
        LogAddItem( LOG_CATEGORY_MAIN_DEBUG, "Fault: " + e.text);
    }

    private function GetUsersServersResult(event:ResultEvent):void
    {
        LogAddItem( -1, "GetUsersServers Result Received..");
        var rawData:String = String(event.result);
        LogAddItem( -1, "GetUsersServersResult = " + rawData);
        InitContinue();
    }
4

1 回答 1

0

问题很可能是您HTTPService在函数内部声明GetUsersServers()。当该函数完成时,持有 的变量HTTPService不再存在并且有资格进行垃圾收集。

相反,如果您将 声明HTTPService为成员变量,则该变量将在它所在的类的整个生命周期中存在。所以尝试这样的事情:

private var serviceObj:HTTPService;

private function GetUsersServers():void
{
    serviceObj = new HTTPService();
    ...
}
于 2013-06-13T17:20:15.813 回答