Flex / AIR вызывает функции Javascript - PullRequest
1 голос
/ 07 марта 2011

У меня проблема с вызовом функции JavaScript из моего приложения AIR / Flex. В веб-приложении это легко с 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> 

Это выдает «TypeError: Undefined value», когда я вызываю «remoteFunction» в myAIRHTML.html. Это что-то важное, что я пропустил? Кто-нибудь может помочь? Это что-то важное, что я забываю о documentRoot - я не использую это имя в другом месте ..... Спасибо за все ответы

1 Ответ

0 голосов
/ 18 июля 2011

мне все равно кажется немного смущенным, если я понимаю, что это ваша ошибка:

Если вы определите это

myHTML.htmlLoader.window.inputFunction = testInputFunction;

Вы js в myAIRHTML.html не можете вызвать testInputFunction (someData); но inputFunction (someData), потому что вы передали функцию AS3 testInputFunction в переменную с именем inputFunction

Надеюсь, это поможет

...