Avatar of sfletcher1959
sfletcher1959
Flag for United States of America asked on

Popup Window not executing creationComplete="initApp()"

I have a popup window that only executes creationComplete="initApp()" the first time the popup is called. When the popup is closed and opened again the creationComplete="initApp()" doesn't run again.

I need to force "initApp()" to run each time the popup is opened in order to get data via an HTTPService.

Thanks!


<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
	 dropShadowEnabled="true" shadowDistance="10" 
	 borderStyle="solid" width="540" height="100%"
	 creationComplete="initApp()" layout="vertical" title="Chart Filters">
	
	<!--
		PROGRAM NAME ViewFilters
			Purpose: Called from the ChartDesigner Form.  Allows Adding / Editing of Filters
	-->
 
   <mx:Script>
        <![CDATA[
        	import mx.rpc.http.HTTPService;
        	import mx.managers.PopUpManager;       	
        	import mx.controls.Alert;
            import mx.rpc.events.ResultEvent;
            import util.ModelLocator;
            
            [Bindable]
            private var dataCollection2:XMLList;
            
            [Bindable]
			public var model:ModelLocator = ModelLocator.getInstance();
			        
  			public function initApp():void
  						{
    					getChartFiltersService.send()  //get the data now  						
  						}          
							
			 private function getResult(event:ResultEvent):void
			 			{
			 			var result:XML = event.result as XML;	
                        dataCollection2 = result..filter as XMLList;
                        updateGrid();
    					}
    					
			 public function updateGrid():void
			 			{
			  				ta3.text = dgFilters.dataProvider.getItemAt(0).fvalue;
						}
						
			private function handleCancel() : void {			
			mx.managers.PopUpManager.removePopUp(this);
		}
  		       					
                ]]>
    </mx:Script>
    
 
    <mx:HTTPService id="getChartFiltersService"
		url="http://localhost/Magic94Scripts/mgrqispi94.dll"
		method="POST"
		useProxy="false"
		resultFormat="e4x"
		result="getResult(event)">
	<mx:request>
		<appname>Web_Dev_Procurement</appname> 
		<prgname>getFilters</prgname>
		<arguments>param1,param2</arguments>
		<param1>{model.currentChartId}</param1>
	</mx:request>
	</mx:HTTPService>
	
		
		<mx:DataGrid id="dgFilters"
      	dataProvider="{dataCollection2}" width="100%"> 
            <mx:columns>            
            	<mx:DataGridColumn dataField="ffield" headerText="Field" width="60" />
            	<mx:DataGridColumn dataField="ftype" headerText="Filter Type" width="40" />            
        </mx:columns>
         </mx:DataGrid>
                           
         <mx:TextArea id="ta3" text="{dgFilters.selectedItem.fvalue}"  editable="false" width="100%" height="88" />     
		 <mx:TextArea text="{model.currentChartId}"/>
         <mx:ControlBar id="controlbar1" horizontalAlign="right" verticalAlign="bottom">
			<mx:Button id="searchButton" label="Cancel" click="handleCancel()"/>    
              
		</mx:ControlBar>
 
</mx:Panel>

Open in new window

Apache Flex

Avatar of undefined
Last Comment
zzynx

8/22/2022 - Mon
zzynx

>> When the popup is closed and opened again the creationComplete="initApp()" doesn't run again.
That's because the popup panel is not recreated. It is simply removed by the popup manager but it still exists invisibly.
When it pops up again it is NOT recreated and hence the creationComplete event is not thrown.

Show me your code where you make the panel pop up.
sfletcher1959

ASKER
here you go:



                  // FOLLOWING IS THE FILTER POPUP FORM
                  private var filter : ViewFilters = new ViewFilters;      
                        
                  // USER SELECTED TO VIEW (EDIT) THE CHART FILTERS
                  private function handleViewFilters() : void {
                  if (dG1.selectedIndex == -1) return; //user needs to select a chart before viewing Filters
                  
                  mx.managers.PopUpManager.addPopUp(filter,this, true);
                  mx.managers.PopUpManager.centerPopUp(filter);
                  with (filter) {      
                        chartID                        = dG1.selectedItem.Id;
                        }
                  
                                    
                ]]>
   
    </mx:Script>
ASKER CERTIFIED SOLUTION
zzynx

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sfletcher1959

ASKER
Would the better route be to switch from calling a popup to calling a custom component with a viewstack or state?

Thanks!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
zzynx

Explanation:
Calling
>> mx.managers.PopUpManager.removePopUp(filter);
makes your filter disappear, but doesn't "delete" it.
Next time you call
>> mx.managers.PopUpManager.addPopUp(filter,this, true);
**the same filter** is shown again.

By calling resetFilter() after PopUpManager.removePopUp(filter);
you are assured that the next time you do
>> mx.managers.PopUpManager.addPopUp(filter, this, true);
a NEWLY CREATED filter is shown
zzynx

>> Would the better route be to switch from calling a popup to calling a custom component with a viewstack or state?
In my opinion that popup is OK. As long as you make sure - e.g. by using the code I posted - its content is up-to-date
sfletcher1959

ASKER
I got the syntax wrong because I get "undefined method resetFilter" error.


private function handleCancel() : void {                  
                  mx.managers.PopUpManager.removePopUp(this);
                  resetFilter();
            }


Sorry, I am new to Flex.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
sfletcher1959

ASKER
sorry your post #285 just appeared --- I see
sfletcher1959

ASKER
Ok, I am still having the error in the viewFilters.mxml - "call to possibly undefined method resetFilter".

Does the following belong in the ChartDesigner.mxml (where the popup is called from) or in the viewFilters.mxml (the popup itself)?



private function get filter():ViewFilters {
 			    if (_filter==null) {
 			    _filter = new ViewFilters();
     			}
     			return _filter;
				}
				
			private function resetFilter():void {
    			_filter = null;
				}		

Open in new window

sfletcher1959

ASKER
I had to move some things around until I found what when where. But this was the solution and it works great
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
zzynx

Thanx 4 axxepting