Flex 3: Getting variables from URL

后端 未结 2 825
甜味超标
甜味超标 2021-01-20 12:26

If I have an application located at http://sitename.com/myapp/ and i want to pass in a variable via the url (i.e. - http://sitename.com/myapp/?name=Joe), how can I get that

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 12:58

    Divide 'em with String.split() and conquer:

        var url:String = "http://www.xxx.zzz/myapp?arg1=vae&arg2=victus";
        var params:String = url.substr(url.lastIndexOf("?") + 1);
        if (params.length == url.length) return; //no params
        for each (var pair:String in params.split("&"))
        {
            trace("Got parameter:");
            var nameValue:Array = pair.split("=");
            trace("name: " + nameValue[0] + ", value: " + nameValue[1]);
        }
    

    Output:

    Got parameter:
    name: arg1, value: vae
    Got parameter:
    name: arg2, value: victus
    

提交回复
热议问题