0 Replies Latest reply on Mar 8, 2011 12:43 AM by MartinLanghammer

    Call javascript in AIR / Flex

    MartinLanghammer Level 1

      Hi, I have problem with calling javascript function from my AIR / Flex App. My AIR app is similar like this ....

      <?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 is

      
      <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>
      


      and js.html is

       

      <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>  
      

      This throw  "TypeError: Undefined value" when I call "remoteFunction" in myAIRHTML.html. It something important what I missed? Can anyone help? It someting important for documentRoot - I don´t use this name on other place ..... Thanks for all replies