开发者

Flex component communication

开发者 https://www.devze.com 2022-12-20 08:53 出处:网络
I use a popup loaded from different MXML file: private function showAddPopUp():void{ addPopUP = PopUpManager.createPopUp(this, add_popup, true);

I use a popup loaded from different MXML file:

private function showAddPopUp():void{
    addPopUP = PopUpManager.createPopUp(this, add_popup, true);
    PopUpManager.centerPopUp(addPopUP);
}

That file is as follows (add_popus.mxml):

<mx:VBox width="100%" height="100%" paddingLeft="5" paddingTop="5" paddingRight="5" paddingBottom="5">
    <mx:Label text="Enter name of the source:" />
    <mx:TextInput width="100%" id="textName" />
    <mx:Label text="Enter URL for the source:" />
    <mx:TextInput width="100%" id="textURL" />
    <mx:HBox width="100%">
        <mx:Button label="OK" id="buttonOK" textAlign="center"/>
        <mx:Button label="Cancel" id="buttonCancel" click="PopUpManager.removePopUp(this)" textAlign="center"/>
    </mx:HBox>
</mx:VBox>

The problem is I don't know how to pass text values from text inputs to the main component after buttonOK is clicked in the popup. I tried custom events, but 开发者_开发百科it didn't work. Documentation is not very helpful. I will appreciate any ideas.

Full code is here: http://github.com/jbajor/Newspapair


Dispatch an event from the button click

<!-- AddPopUp.mxml -->
<mx:Button label="OK" id="buttonOK" textAlign="center" 
    click="dispatchEvent(new Event(POPUP_DONE))"/>
<mx:Script>
<![CDATA[
    public static const POPUP_DONE:String = "popupDone";
]]>
</mx:Script>

And listen to it in the other class. event.target will give you a handle to the popup.

private function showAddPopUp():void
{
    var addPopUp:AddPopup = PopUpManager.createPopUp(this, add_popup, true);
    addPopUp.addEventListener(AddPopUp.POPUP_DONE, onPopupDone);
    PopUpManager.centerPopUp(addPopUP);
}
private function onPopupDone(e:Event):void
{
    var popup:AddPopUp = AddPopUp(e.target);
    trace(popup.textName.text);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号