是否可以在 flash 横幅中 运行 html <script>?
Is it possible to run html <script> in the flash banner?
我想 运行 一些 javascript 代码直接 "from the flash (swf) banner"。
可能吗?我该如何处理?
为了能够使用 ActionScript 在 DOM 中注入 JS 脚本,然后通过注入的函数进行通信,您可以这样做:
1) 导入外部 class.
import flash.external.ExternalInterface;
2) 声明一个包含所有JS函数的常量变量:
private const script_js :XML =
<script>
<![CDATA[
function() {
AJXFNC = {
ajaxFunction:function(_url){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari, Chrome
ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("GET", _url, true);
ajaxRequest.send(null);
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
ajaxRequest.open("GET", _url, true);
ajaxRequest.send();
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
ajaxRequest.open("GET", _url, true);
ajaxRequest.send();
} catch (e){
// Something went wrong
return false;
}
}
}
}
}
}
]]>
</script>;
3) 将 JS 注入 DOM:
try {
if( ExternalInterface.available )ExternalInterface.call( script_js );
} catch( error:Error ) {
trace("ExternalInterface is not available");
}
4) 调用一个函数:
ExternalInterface.call( "AJXFNC.ajaxFunction", "http://www.google.com" );
我已将该技术粘贴到此答案中,因为我通常不相信博客的正常运行时间,但所有权利归 Adi Feiwel 所有,因为他写了这篇文章:http://todepoint.com/blog/2011/08/01/injecting-and-calling-js-functions-from-within-flash-using-external/
我想 运行 一些 javascript 代码直接 "from the flash (swf) banner"。
可能吗?我该如何处理?
为了能够使用 ActionScript 在 DOM 中注入 JS 脚本,然后通过注入的函数进行通信,您可以这样做:
1) 导入外部 class.
import flash.external.ExternalInterface;
2) 声明一个包含所有JS函数的常量变量:
private const script_js :XML =
<script>
<![CDATA[
function() {
AJXFNC = {
ajaxFunction:function(_url){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari, Chrome
ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("GET", _url, true);
ajaxRequest.send(null);
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
ajaxRequest.open("GET", _url, true);
ajaxRequest.send();
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
ajaxRequest.open("GET", _url, true);
ajaxRequest.send();
} catch (e){
// Something went wrong
return false;
}
}
}
}
}
}
]]>
</script>;
3) 将 JS 注入 DOM:
try {
if( ExternalInterface.available )ExternalInterface.call( script_js );
} catch( error:Error ) {
trace("ExternalInterface is not available");
}
4) 调用一个函数:
ExternalInterface.call( "AJXFNC.ajaxFunction", "http://www.google.com" );
我已将该技术粘贴到此答案中,因为我通常不相信博客的正常运行时间,但所有权利归 Adi Feiwel 所有,因为他写了这篇文章:http://todepoint.com/blog/2011/08/01/injecting-and-calling-js-functions-from-within-flash-using-external/