如何在 Flash AS3 中从 URL 获取变量

发布于 2024-08-30 16:32:05 字数 486 浏览 2 评论 0原文

所以我有一个 URL,我需要 Flash 影片从中提取变量:

示例链接:
http://www.example.com/example_xml.php?aID=1234& ;bID=5678

我需要获取 aID 和 bID 号码。

我可以通过ExternalInterface 将完整的URL 获取到字符串中,

var url:String = ExternalInterface.call("window.location.href.toString");
if (url) testField.text = url;

只是不确定如何操作字符串来获取1234 和5678 数字。

感谢任何提示、链接或帮助!

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 to get the aID and the bID numbers.

I'm able to get the full URL into a String via ExternalInterface

var url:String = ExternalInterface.call("window.location.href.toString");
if (url) testField.text = url;

Just unsure as how to manipulate the String to just get the 1234 and 5678 numbers.

Appreciate any tips, links or help with this!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫竹語嫣☆ 2024-09-06 16:32:05

创建 URLVariables 的新实例。

// given search: aID=1234&bID=5678
var search:String = ExternalInterface.call("window.location.search");
var vars:URLVariables = new URLVariables(search);
trace(vars.aID); // 1234
trace(vars.bID); // 5678

Create a new instance of URLVariables.

// given search: aID=1234&bID=5678
var search:String = ExternalInterface.call("window.location.search");
var vars:URLVariables = new URLVariables(search);
trace(vars.aID); // 1234
trace(vars.bID); // 5678
痴骨ら 2024-09-06 16:32:05
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

未经测试的代码!这只是简单的字符串操作。

而且...几乎是 1 行(也未经测试),

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];

但当然,使用 urlVariables 可能会更好:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文