6 Replies Latest reply on May 26, 2006 5:59 AM by Stefan08

    get Data from Popup


      i have a tree in a popup within a title window. I have created the popup in the main application file on an event handler with this function
      function showWindow(modal:Boolean):void {
      var popup: IFlexDisplayObject = mx.managers.PopUpManager.createPopUp(this, SelectTreeItem, modal);

      Now my question is, how can i get the data of selected node back to the main application file

      Thanks for help!
        • 1. Re: get Data from Popup

          I'm a little confused about your question. The second parameter of createPopUp is supposed to be of type Class. Is the type of "SelectTreeItem", Class ?

          To put a tree in a popup, I would instantiate a tree using <mx:Tree id="myTree"/> tag and use mx.managers.PopUpManager.addPopUp to put the tree or its container as a popup.

          The selected node would be accessed using its id for eg "myTree.selectedItem" and it would not depend on whether the tree is in a popup or not.

          Anjali Bhardwaj
          Adobe Flex SDK Team
          • 2. Re: get Data from Popup
            ntsiii Level 3
            This is interesting to me as well.

            It seems that addPopUp does not return a reference to the title window created, nor does it have an "initOb" argument for passing in properties.

            Just how do we communicate with a popup created this way?

            I have not tried to do this yet so I have not really dug into the docs, but I will be.

            • 3. get Data from Popup
              Stefan08 Level 1
              my problem is not putting the tree into a popup. I have already done this and i have have also build a event handler to get the select node. The popup is a mxml-component, i don't know if this the also a class file. The code looks like this
              <?xml version="1.0"?>

              <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml">
              <mx:XML id="treeModel" source="Stoerungsart.xml"></mx:XML>
              <mx:XML id="art" source="Stoerungsart.xml"></mx:XML>
              <mx:XML id="ursache" source="Stoerungsursache.xml"></mx:XML>

              import flash.events.*;
              import mx.events.*;
              import mx.controls.*;
              import mx.controls.treeClasses.TreeListData;

              public var baumart:String;
              public var selectedNode:Object;
              public var isLeaf:Boolean;
              public var selectedData:TreeListData;

              private function changeEvt(event:Event):void {

              private function nodeOpenEvt(event:TreeEvent):void {

              private function treeModelName(treeName:String):String {
              var test:Boolean;
              if (test)
              return ""
              return ""

              public function treeChanged(event:Event):void
              selectedNode = Tree(event.target).selectedNode;
              selectedData = (TreeListData) Tree(event.target).selectedData;
              isLeaf = selectedData.hasChildren;

              import mx.managers.PopUpManager;

              <mx:Tree allowMultipleSelection="true" change="treeChanged(event)" dataProvider="{treeModel}" id="liste" labelField="@label" showRoot="false" height="100%" nodeOpen="nodeOpenEvt(event);" width="100%">

              <mx:TextArea width="100%" height="100%"

              <mx:TextArea width="100%" height="100%"

              <mx:Button label="Fenster schliessen" click="PopUpManager.removePopUp(this)"/>

              But know i don't only want to display the selectedNode into the popup, i want to get the selectedNode back to the application file where i have created the popup into the function showWindow

              I want to have something like this in the application file
              <mx:TextArea width="100%" height="100%" text="{popup.selectedNode.@label}"/>

              I hope that it is clear how my problem looks like
              • 4. Re: get Data from Popup
                poonamsheth Level 1
                well even am facing this problem

                i dont understand where exactly am making mistake in naming filenames or so?

                i get errors.. am not able to understand what kinda mistake am making?
                or what has to be considered for such codes
                please reply soon

                <?xml version="1.0" encoding="utf-8"?>
                <!-- Simple application to demonstrate TitleWindow layout container. -->
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">


                import mx.managers.PopUpManager;
                import mx.containers.TitleWindow;

                // Open the TitleWindow container.
                // Cast the return value of the createPopUp() method
                // to SimpleTitleWindowExample, the name of the
                // component containing the TitleWindow container.
                private function showWindow():void {
                var login:SimpleTitleWindowExample=SimpleTitleWindowExample(PopUpManager.createPopUp( this, SimpleTitleWindowExample , true));

                // Pass a reference to the TextInput control
                // to the TitleWindow container so that the
                // TitleWindow container can return data to the main application.

                <mx:Panel title="TitleWindow Container Example" height="75%" width="75%"
                paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

                <mx:Button label="Click to open the TitleWindow container" click="showWindow();"/>

                <mx:Text id="returnedName" text="" width="100%"/>


                <?xml version="1.0" encoding="utf-8"?>
                <!-- Simple custom MXML TitleWindow component.
                The TitleWindowApp application displays this component.
                You cannot run it independently. -->

                <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml"
                title="Title Window" x="168" y="86">

                import mx.managers.PopUpManager;
                import mx.controls.Text;

                // A reference to the TextInput control in which to put the result.
                public var loginName:Text;

                // Event handler for the OK button.
                private function returnName():void {
                loginName.text="Name entered: " + userName.text;

                <mx:Label text="Enter Name: "/>
                <mx:TextInput id="userName" width="100%"/>

                <mx:Button label="OK" click="returnName();"/>
                <mx:Button label="Cancel" click="PopUpManager.removePopUp(this);"/>

                errors are

                1 Access of undefined property SimpleTitleWindowExample.
                2 Call to a possibly undefined method SimpleTitleWindowExample.
                3 Type was not found or was not a compile-time constant: SimpleTitleWindowExample.
                4 Access of possibly undefined property loginName through a reference with static type SimpleTitleWindowExample.

                please reply soon,
                • 5. Re: get Data from Popup
                  ntsiii Level 3
                  I tried this example and it worked fine.

                  Stefan08, you should look at this as well. the key is to not use "addPopUp ", but rather to use "PopUpManager.createPopUp"(as you are doing).

                  As you know, createPopUp returns a reference to the popup control. You will use that reference for passing data.

                  As poonamsheth does, pass in a reference to your TextArea.text property. Then, in the popup, you can set that peoperty directly.

                  There are other possibilities, including setting a variable, passing in a reference to the application scope using "this". etc.

                  • 6. get Data from Popup
                    Stefan08 Level 1
                    Thanks for your greatly help, know it works!!