【问题标题】:Flex/AIR calling Javascript functionsFlex/AIR 调用 Javascript 函数
【发布时间】:2011-03-07 15:51:13
【问题描述】:

我在从我的 AIR / Flex 应用程序调用 javascript 函数时遇到问题。在 web 应用程序中,使用 externallInterface 很容易,但在本机应用程序中,这是一个问题。我的 AIR 应用程序是这样的......

<?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”时,这会抛出“TypeError: Undefined value”。我错过了什么重要的事情?任何人都可以帮忙吗?重要的是我忘记了 documentRoot - 我不在其他地方使用这个名字.....感谢所有回复

【问题讨论】:

    标签: javascript apache-flex flex3 air


    【解决方案1】:

    如果我明白这是你的错误,我似乎有点困惑:

    如果你定义这个

    myHTML.htmlLoader.window.inputFunction = testInputFunction;
    

    myAIRHTML.html 中的 js 不能调用 testInputFunction(someData);但是 inputFunction(someData) 因为您将 AS3 函数 testInputFunction 传递给了一个名为 inputFunction 的变量

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 2013-12-14
      • 2015-11-11
      • 1970-01-01
      相关资源
      最近更新 更多