Apache flex 将URL参数附加到ActionScript中的URL

Apache flex 将URL参数附加到ActionScript中的URL,apache-flex,url,actionscript,delimiter,Apache Flex,Url,Actionscript,Delimiter,我正在尝试向ActionScript中的URL字符串添加URL参数。目前,我正在检查现有的URL,看看它是否显式地有一个“?”来确定是否有任何现有的参数来确定我的参数分隔符应该是“?”还是“&”。ActionScript中是否有一个库或实用程序方法可以简化下面的代码 var existingParameter:Boolean = existingUrl.indexOf("?") != -1; var urlDelimiter:String = (existingParameter) ? "&am

我正在尝试向ActionScript中的URL字符串添加URL参数。目前,我正在检查现有的URL,看看它是否显式地有一个“?”来确定是否有任何现有的参数来确定我的参数分隔符应该是“?”还是“&”。ActionScript中是否有一个库或实用程序方法可以简化下面的代码

var existingParameter:Boolean = existingUrl.indexOf("?") != -1;
var urlDelimiter:String = (existingParameter) ? "&" : "?";

var urlParameter:String = urlDelimiter + "ParameterName=" + parameterValue;
var completeUrl:String = existingUrl + urlParameter;
查看和类。

您可以使用该实用程序并利用其通过对象获取参数的能力。参数可以作为键值对发送,其余的由类处理

下面是一个实用程序方法的示例,它正好做到了这一点:

public static function sendViaHttpService(url:String, 
                                          format:String,
                                          method:String, 
                                          onComplete:Function, 
                                          onFail:Function, 
                                          parameters:Object=null):void {

    var http:HTTPService = new HTTPService();
    http.url = url;
    http.resultFormat = format;
    http.method = method;

    // create callback functions which remove themselves from the http service 
    // Don't want memory leaks
    var pass:Function = function(event:ResultEvent):void {
        onComplete(event);
        http.removeEventListener(ResultEvent.RESULT, pass);
    }
    var fail:Function = function(event:FaultEvent):void {
        onFail(event);
        http.removeEventListener(FaultEvent.FAULT, fail);
    }

    http.addEventListener(ResultEvent.RESULT, pass);
    http.addEventListener(FaultEvent.FAULT, fail);

    // yeah, we're going to send this in with the date to prevent 
    // browser-caching...kludgey, but it works
    if (parameters == null) {
        parameters = new Object();
    }
    // always get new date so the URL is not cached
    parameters.date = new Date().getTime();

    http.send(parameters);
} //sendViaHttpService()
参数可以通过如下方式传递到此静态函数:

var complete:Function = function(event:ResultEvent):void { /* your 
                                                              callback here */ };

var fail:Function = function(event:FaultEvent):void { /* your 
                                                         failure callback here */ };

var url:String = "<your URL here>";

sendViaHttpService(url, URLLoaderDataFormat.TEXT, URLRequestMethod.GET, complete, fail, { param1: 'value1', param2: 'value2' });
var complete:Function=Function(事件:ResultEvent):void{/*您的
在这里回调*/};
var fail:Function=Function(event:FaultEvent):void{/*您的
此处回调失败*/};
var-url:String=“”;
sendViaHttpService(url,URLLoaderDataFormat.TEXT,URLRequestMethod.GET,complete,fail,{param1:'value1',param2:'value2'});