2011-03-07 78 views
1

我有問題,從我的AIR/Flex應用程序調用JavaScript函數。在web應用中,使用externallInterface很容易,但在本地應用中,這是一個問題。我的AIR應用程序是這樣的相似....的Flex/AIR調用JavaScript函數

<?xml version="1.0" encoding="utf-8"?> 
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
initialize="init()" ... > 


<mx:Script> 
     <![CDATA[ 

     private function init():void 
      { 
       myHTML.addEventListener(Event.HTML_DOM_INITIALIZE,DOMInit); 
       myHTML.location="myAIRHTML.html"; 

      } 

      private function DOMInit(e:Event):void{ 
       myHTML.htmlLoader.window.inputFunction = testInputFunction;    
      } 
     private function testInputFunction(so:String):void{ 
     //some code ...... 
     } 

     public function someFunction(e:AIREvent):void{ 
       myHTML.htmlLoader.window.outputFunction(e.param); 
      } 

      _]]> 
</mx:Script> 

<mx:HTML id="myHTML" width="5" height="5" visible="true" /> 

</mx:WindowedApplication> 

myAIRHTML.html是

<html>  
    <head> 
     <script language="Javascript"> 


      var interface = {};  

      function outputFunction(param){  
       var childInterface = document.getElementById("mySandbox").childSandboxBridge; 

       childInterface.remoteFunction(param); 
      } 


      interface.inputFunction = function(someData){ 
       testInputFunction(someData); 
      }         
      function initBridge(){ 
       document.getElementById("mySandbox").parentSandboxBridge = interface; 
     } 
     </script> 
    </head>  
    <body>   
     <iframe id="mySandbox" 
      src="js.html" 
      sandboxRoot="http://remote.example.com/js/" 
      documentRoot="app:/myAIRSandbox/" 
     ondominitialize="initBridge()"> 
     </iframe> 
    </body> 
</html> 

和js.html是

<html>   
<head> 
    <script language="Javascript" src="http://www/otherexample.com/other.js"></script> 

     <script language="Javascript" > 

      var interface = {}; 

      interface.remoteFunction = function(st){ 
       alert("st"); 
       callFunctionInOtherJS(st); 
      } 


      window.childSandboxBridge = interface;      

      var someObject = {}; 

      someObject.SomeFunction = function(someParam){ 
       window.parentSandboxBridge.inputFunction(someParam); 
      } 

     </script> 
    </head> 

    <body ></body> 
</html> 

該拋 「類型錯誤:未定義值」 時我在myAIRHTML.html中調用「remoteFunction」。這是我錯過的重要事情?誰能幫忙?它是什麼我忘了的DocumentRoot重要的東西 - 我沒有在其他地方使用這個名字.....感謝所有回覆

回答

0

似乎有點混亂,我反正如果我理解這是你的錯誤:

如果定義在myAIRHTML.html這個

myHTML.htmlLoader.window.inputFunction = testInputFunction; 

您的js不能調用testInputFunction(someData);但inputFunction(someData)因爲您將AS3函數testInputFunction傳遞給一個名爲inputFunction的變量

希望這有助於