如何从浏览器中获取查询字符串值进入我的Flash电影?
例如,链接为www.blah.com/index.html?name=John
。 html页面加载了一个flash电影,我希望flash电影能够访问变量name=John
。
这可能吗?
答案 0 :(得分:1)
假设ActionScript 3。
结帐:Get current url to Flash swf using an External Interface call (circle cube)
看起来似乎是:ExternalInterface.call(“window.location.href.toString”);
然后我猜你可以从字符串中找到你需要的东西。
或者您可以使用FlashVars并传递您需要的内容:http://blogs.adobe.com/pdehaan/2006/07/using_flashvars_with_actionscr.html
在embed标记中:FlashVars="one=1&two=2"
和参数:<param name="FlashVars" value="one=1&two=2" />
答案 1 :(得分:0)
我建议通过javascript或某些服务器端语言(如PHP)读取变量,然后将它们发送到swf:
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
"yourflashfile.swf?variable1=" + getURLParameter("parameter1") + "&variabl2=" + getURLParameter("parameter2")
然后在ActionScript中使用:
var variable1:String = loaderInfo.parameters.variable1 || "";