URL example.com/redir会自动将用户(HTTP 302)重定向到example.com/hi.SWF?message=Message+Value。
如何在以下示例中使用javascript或flash获取消息值?
dict get
考虑一下:
答案 0 :(得分:0)
我认为获取重定向swf的url及其参数的最简单方法是使用另一个swf作为当前的swf加载器,在这里你可以获取url并将参数传递给重定向的swf然后您可以通过ExternalInterface
将其发送到JavaScript。
为此,请看一下这个例子:
ActionScript:
// url : the url of the current swf
// this url is passed by flash vars in the html page
// default value : http://www.example.com/redirect
var swf_url:String = this.loaderInfo.parameters.url || 'http://www.example.com/redirect',
// fn : the name of the js function which will get the url and the message param
// this name is passed by flash vars in the html page
// default value : console.log
js_function:String = this.loaderInfo.parameters.fn || 'console.log',
message:String = 'no message';
var url_request:URLRequest = new URLRequest(swf_url);
var swf_loader:Loader = new Loader();
swf_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_content_load);
swf_loader.load(url_request);
function on_content_load(e:Event): void
{
var loader_info:LoaderInfo = LoaderInfo(e.currentTarget);
// get the message param or use the default message
message = loader_info.parameters.message || message;
// if ExternalInterface is available, send data to js
if(ExternalInterface.available)
{
// send the swf url and the message param to the js function
ExternalInterface.call(js_function, { url: loader_info.url, message: message });
}
// show the redirected loaded swf
addChild(swf_loader);
}
HTML方面:
对于这个例子,假设我们有一个.htaccess
这样的文件:
.htaccess:
Redirect /redirect /new.swf?message=a%20message%20here
JavaScript:
function get_data_from_flash(data)
{
console.log('url : ' + data.url);
// gives :
// url : http://www.example.com/new.swf?message=a%20message%20here
console.log('message : ' + data.message);
// gives :
// message : a message here
}
HTML:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400">
<param name="movie" value="loader.swf" />
<param name="flashvars" value="url=http://www.example.com/redirect&fn=get_data_from_flash" />
<object type="application/x-shockwave-flash" data="loader.swf" width="550" height="400">
<param name="flashvars" value="url=http://www.example.com/redirect&fn=get_data_from_flash" />
</object>
</object>
这就是全部!
如果您想了解有关如何使用ExternalInterface
的详细信息,可以查看here。
希望可以提供帮助。