user_78361084
user_78361084

Reputation: 3928

pass data from popup to parent

I have a parent w/ a popup child. When parent loads, I have to call a function within the popup without showing the popup (thus, I load "pupLove" but don't include it in layout)....I then pass this data to the parent. When the user manually clicks another button to open the popup, the same function is called & data passed to the parent. However, I am not able to pass dg.length to the parent. I believe the root problem is that I am loading "pupLove" & thus the parents are getting confused.....I'm guessing if I get rid of "pupLove" I can pass the data correctly but will need to call the child's function at creationComplete of the parent....how do I do that?

Here's my parent:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx"
           backgroundColor="green" width="50%" height="100%" 
           xmlns:local="*"         
           >



<fx:Script>
    <![CDATA[

        import pup;
        import mx.managers.PopUpManager;

        public function showPup(evt:MouseEvent):void {
            var ttlWndw:pup = PopUpManager.createPopUp(this, pup, true) as pup;
            PopUpManager.centerPopUp(ttlWndw);
        }



    ]]>
</fx:Script>

<mx:VBox>

<local:pup id="pupLove" visible="false" includeInLayout="false" />
<s:Button click="showPup(event);" label="launch Pup" />
<mx:Text id="Ptest" color="black" text="from Parent:{pupLove.dg.length}" />

</mx:VBox>


</s:Application>

And a popup child called 'pup.mxml':

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">

<fx:Script>
    <![CDATA[

                    public function init():void{
                    // send php call
                    }

        import mx.events.CloseEvent;
        import mx.managers.PopUpManager;
        private function removePup(evt:Event):void {
            PopUpManager.removePopUp(this);
        }

    ]]>
</fx:Script>

<fx:Declarations>
    <s:ArrayCollection id="dg">

    </s:ArrayCollection>
</fx:Declarations>


<s:TitleWindow width="100%" height="100%" close="removePup(event)">
<mx:VBox>
    <mx:Text id="test" color="red" text="from Child:{dg.length}" />
    <s:Button label="add Items" click="dg.addItem({id:'cat'})" />

</mx:VBox>

</s:TitleWindow>

</s:Group>

UPDATE: I guess my question can be more easily stated as: "is there a way to call a child's function from the parent without actually loading the child?"

Upvotes: 0

Views: 3424

Answers (1)

Florian F
Florian F

Reputation: 8875

Well, if in your child's function, you don't need to access any of its UI component, then you could instanciate the child in the parent view and call the method. When you need to display the popup afterwhile, use the PopupManager addPopup method with this existing instance instead of using createPopup

Upvotes: 1

Related Questions