Quantcast
Channel: Forums - ArcGIS Viewer for Flex
Viewing all articles
Browse latest Browse all 2097

Running a function in a widget from a child component

$
0
0
I have a widget (widget.mxml). When it loads I have a title window (CustomTitleWindow.mxml) that opens that gives the user two options Yes or No. When they press 'Yes' I want it to run a function saveYes in the widget.mxml and when they press 'No' I want it to run a function saveNo in the widget.mxml. I haven't quite got to grips with how to do this. I have the following code, it closes the CustomTitleWindow but doesn't run the saveYes function. Where am I going wrong?

The code in my widget.mxml is

Code:

private function showWindow():void
                        {
                                        var popUp:IFlexDisplayObject = PopUpManager.createPopUp(parent, CustomTitleWindow, true);
                                        PopUpManager.centerPopUp(popUp);
                                        popUp.addEventListener("evtYes", saveYes);
                        }
                       
                        private function saveYes():void
                        {
                                Alert.show("The Yes requested has been pressed");
                        }

The code in my CustomTitleWindow.mxml is

Code:

<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow 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"
                          title="Custom Window"
                          skinClass="widgets.myWidget.TitleWindowSkin"
                          cornerRadius="8"
                          close="PopUpManager.removePopUp(this);">
        <s:layout>
                <s:VerticalLayout verticalAlign="middle" horizontalAlign="center" />
        </s:layout>
       
        <fx:Metadata>
                [Event(name="evtYes", type="flash.events.Event")]
        </fx:Metadata>
       

        <fx:Script>
                <![CDATA[
                        import mx.managers.PopUpManager;
               
                        private function clickYes(event:Event):void
                        {
                                var myEvent:Event = new Event ('evtYes');
                                dispatchEvent (myEvent);
                                PopUpManager.removePopUp(this);
                        }
                ]]>
        </fx:Script>
        <s:Label text="Are you sure?"/>
        <s:HGroup horizontalAlign="center" verticalAlign="middle" gap="5" width="100%">
                <s:Button id="btnYes" label="Yes" click="clickYes(event)"/>
        </s:HGroup>
</s:TitleWindow>

Thanks!

Viewing all articles
Browse latest Browse all 2097

Trending Articles