How to get/obtain Variables from URL in Flash AS3

前端 未结 2 1085
鱼传尺愫
鱼传尺愫 2020-12-30 13:17

So I have a URL that I need my Flash movie to extract variables from:

example link:
http://www.example.com/example_xml.php?aID=1234&bID=5678

I need t

2条回答
  •  庸人自扰
    2020-12-30 13:46

    var valuePairs:Array = url.substring(url.indexOf("?")+1).split("&");
    var map:Object = new Object();
    for (var i:int=0; i < valuePairs.length; i++) {
        var nextValuePair:Array = valuePairs[i].split("=");
        map[nextValuePair[0]] = nextValuePair[1];
    }
    
    
    trace(map["aID"]); // 1234
    

    Untested code! This is just with simple string manipulation.

    and... almost 1-liner (also untested)

    var map:Object = new Object();
    var temp:Array;
    for each (var i:String in /.*\?(.*)/.exec(url)[1].split("&")) map[(temp=i.split("="))[0]]=temp[1];
    

    but of course it's probably better to go with urlVariables :)

提交回复
热议问题