1 Reply Latest reply on Oct 15, 2010 2:07 AM by Claudiu Ursica

    Passing data / calling function from child to parent window

    Yue_Hong Level 1

      Hi,

       

      how to pass data / call for a function from child native window to parent window in Adobe Air?

       

      Thanks.

        • 1. Re: Passing data / calling function from child to parent window
          Claudiu Ursica Level 4

          <?xml version="1.0" encoding="utf-8"?>

          <s:WindowedApplication

              xmlns:fx="http://ns.adobe.com/mxml/2009"

              xmlns:s="library://ns.adobe.com/flex/spark"

              xmlns:mx="library://ns.adobe.com/flex/mx">

              <fx:Declarations>

                  <!-- Place non-visual elements (e.g., services, value objects) here -->

              </fx:Declarations>

           

              <fx:Script>

                  <![CDATA[

           

                      private var winRef:MyWIn = new MyWIn();

                       

                      private function openWindow():void

                      {

                          winRef.addEventListener("fromNewWindow", onWinEvent);

                          winRef.open();

                      }

                       

                      private function onWinEvent(event:Event):void

                      {

                          trace("from window");

                          winRef.callFromParentTest();

                      }

                  ]]>

              </fx:Script>

           

              <s:Button

                  label="Create Window"

                  click="openWindow()"/>

          </s:WindowedApplication>

           

          MyWIn

           

          <?xml version="1.0" encoding="utf-8"?>

          <components:Window

              xmlns:fx="http://ns.adobe.com/mxml/2009"

              xmlns:s="library://ns.adobe.com/flex/spark"

              xmlns:mx="library://ns.adobe.com/flex/mx"

              xmlns:components="spark.components.*"

              width="400"

              height="300">

           

              <fx:Script>

                  <![CDATA[

                      protected function btn_clickHandler(event:MouseEvent):void

                      {

                          dispatchEvent(new Event("fromNewWindow"));

                      }

                       

                      public function callFromParentTest():void

                      {

                          trace("called from parent");

                      }

                  ]]>

              </fx:Script>

           

              <fx:Declarations>

                  <!-- Place non-visual elements (e.g., services, value objects) here -->

              </fx:Declarations>

           

              <s:Button id="btn" click="btn_clickHandler(event)" />

           

          </components:Window>

           

           

           

          This is handling back and forth cammunication like main app call method on the

          child window in this case as a result of the child window event dispatching. Not

          sure it is what you are after, not sure the best solution yet, I just started

          digging a little bit more into the air's apis.

           

          C