是否可以在 flash 横幅中运行 html<脚本>

Is it possible to run html <script> in the flash banner?

本文关键字:html 运行 脚本 flash 是否      更新时间:2023-09-26

我想直接"从flash(swf)横幅"运行一些javascript代码。

可能吗?我该如何管理呢?

为了能够使用 ActionScript 在 DOM 中注入 JS 脚本,然后通过注入的函数进行通信,您可以执行以下操作:

1) 导入外部类。

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/