Pass a variable from one window to another in Adobe AIR?

By | February 6, 2011

We often need to access another window variable in the current window.
The following example shows how to access a variable from one window in the next window.
The logic is to create an object of next window in the current window and assign the value of variable in the current window itself so that it becomes available in the net window.
Take a look at the example.

/*********** passVar.mxml *********************/

xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">


                  import mx.core.Window;

                  private function init():void
                  {
                        var myWindow : win = new win();
                        myWindow.myVar = "Hello";
                        myWindow.open();
                  }
            ]]>

      x="106" y="134" label="Button" click="init()"/>

/********************************************************************************
 win.mxml -> This file’s object is created in the first file. So please give the exact name, it’s case sensitive also.  Take a look at the line in passVar.mxml
              var myWindow : win = new win();
*********************************************************************************/

xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" creationComplete="init2()">


                  import mx.controls.Alert;

                  public var myVar : String = "";

                  private function init2():void
                  {
                        Alert.show(myVar,"Passed Variable",4,this);
                  }
            ]]>

Leave a Reply

Your email address will not be published.