Search code examples
flashapache-flexflash-builderamfphp

Show Popup window while retrieving data from AMFPHP


Hello i am using Flash Builder 4.6 to create a application and AMFPHP for database. I want to show popup window while retrieving data from AMFPHP. and removed after the execution is complete.

<?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"
           width="615" height="350" minWidth="955" minHeight="600">
<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.rpc.events.ResultEvent;
        import mx.utils.ArrayUtil;

        protected function button1_clickHandler(event:MouseEvent):void
        {
            //i want to show popwindow for slow process
            amf.readProduct();
        }
        protected function method1_resultHandler(event:ResultEvent):void
        {
            //Here the data is retrieved successfully then the popup is removed 
            myArraydata.removeAll();
            myArraydata = new ArrayCollection(ArrayUtil.toArray(event.result));
        }

    ]]>
</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <s:RemoteObject id="amf" source="your_source" destination="your_amf_destination"
                    endpoint="your_services" fault="{Alert.show(event.fault.faultDetail);}" showBusyCursor="true">
        <s:method name="readProduct" result="method1_resultHandler(event)"/>

    </s:RemoteObject>
    <s:ArrayCollection id="myArraydata"/>
</fx:Declarations>
<s:Button x="10" y="10" label="Retrieve Data" click="button1_clickHandler(event)"/>
<mx:AdvancedDataGrid id="adg1" x="10" y="39" width="595" height="301" designViewDataType="flat">
    <mx:columns>
        <mx:AdvancedDataGridColumn dataField="col1" headerText="Column 1"/>
        <mx:AdvancedDataGridColumn dataField="col2" headerText="Column 2"/>
        <mx:AdvancedDataGridColumn dataField="col3" headerText="Column 3"/>
    </mx:columns>
</mx:AdvancedDataGrid>
</s:Application>

Solution

  • Another approach would be to create a new popup instance before starting the readProduct call and to use the AsyncToken that function retruns and save your Popup instance there. Then in the result handler you can get that instance from the ResultEvent.token object and close only that instance.

        protected function button1_clickHandler(event:MouseEvent):void
        {
            var popup:IFlexDisplayObject = PopUpManager.createPopup(this, MyPopupComonent, true);
            //i want to show popwindow for slow process
            var token:AsyncToken = amf.readProduct();
            token.popup = popup;
    
        }
        protected function method1_resultHandler(event:ResultEvent):void
        {
            var popup:IFlexDisplayObject = IFlexDisplayObject(event.token.popup);
            PopUpManager.removePopup(popup);
    
            //Here the data is retrieved successfully then the popup is removed 
            myArraydata.removeAll();
            myArraydata = new ArrayCollection(ArrayUtil.toArray(event.result));
        }