zoukankan      html  css  js  c++  java
  • 爱你不容易——ExternalInterface


    ExternalInterface是什么?

         ExternalInterface 类是Flash Player 8 以后提供的一个外部 API,在功能上与 fscommand()、CallFrame() 和 CallLabel() 方法相似,用来进行Javascript和Actionscript之间的通讯,这是官方推荐使用的类,相比前述三个方法,它更灵活、更通用。

    通过这个类,as可以调用 HTML 页的js,同时传递任何数据类型的任意数量的参数,并可以接收调用的返回值;反过来,HTML 页上的 js,也可以调用 Flash 中的 as 函数。as 函数可以返回一个值,js会立即接收它作为该调用的返回值。详细使用方法在Flash的帮助中有详细讲述。

    使用ExternalInterface时的"flash_id"未定义错误

         但是在使用这个类时,会出现问题,你满心欢喜而去,郁闷而归,虽然问题解决了,但是心有余悸,就象吃瓜子把皮卡喉咙一样,要想使用ExternalInterface不报"flash_id"未定义(flash_id即htm中插入swf文件的Object的id),有下边三个方法:

    1、加一个<form></form>在你嵌套flash的form里的<form>标记后面

    <form><form></form>
    //这里是你的flash代码内容。
    </form>

    2、添加如下JS在你的flash之前:

    <script type="text/javascript"> 
    function ExternalInterfaceManager() 

          
    this.registerMovie = function(movieName) 
              
    if(!window.fakeMovies) window.fakeMovies = new Array(); 
              window.fakeMovies[window.fakeMovies.length] 
    = movieName; 
          }
     
          
    this.initialize = function() 
              
    if(document.all) 
              

                  
    if(window.fakeMovies) 
                  

                      
    for(i=0;i<window.fakeMovies.length;i++
                      

                          window[window.fakeMovies[i]] 
    = new Object(); 
                      }
     
                      window.onload 
    = initializeExternalInterface; 
                  }
     
              }
     
      
          }
     
    }
     
    function initializeExternalInterface() 
          
    for(i=0;i<window.fakeMovies.length;i++
              
    var movieName = window.fakeMovies[i]; 
              
    var fakeMovie = window[movieName]; 
              
    var realMovie = document.getElementById(movieName); 
      
              
    for(var method in fakeMovie) {             
                  realMovie[method] 
    = function() {flashFunction = "<invoke name=\"" + method.toString() + "\" returntype=\"javascript\">" + __flash__argumentsToXML(arguments, 0+ "</invoke>";this.CallFunction(flashFunction);} 
              }
     
      
              window[movieName] 
    = realMovie; 
          }
     
    }
     
    var eim = new ExternalInterfaceManager(); 
    eim.registerMovie(
    "flash_id"); 
    eim.initialize(); 
    </script> 

    其中eim.registerMovie("flash_id"); 中的flash_id为你的swf的ID。

    3、还有一个方法,就是将flash放在form标记之外;

    这个问题在官方livedocs有人反馈,但不知Flash 9中是否解决。

  • 相关阅读:
    【leetcode】1215.Stepping Numbers
    【leetcode】1214.Two Sum BSTs
    【leetcode】1213.Intersection of Three Sorted Arrays
    【leetcode】1210. Minimum Moves to Reach Target with Rotations
    【leetcode】1209. Remove All Adjacent Duplicates in String II
    【leetcode】1208. Get Equal Substrings Within Budget
    【leetcode】1207. Unique Number of Occurrences
    【leetcode】689. Maximum Sum of 3 Non-Overlapping Subarrays
    【leetcode】LCP 3. Programmable Robot
    【leetcode】LCP 1. Guess Numbers
  • 原文地址:https://www.cnblogs.com/yao/p/803003.html
Copyright © 2011-2022 走看看