Customer Service | Training | Contact Us
You are here: Home > User Forums > arcgis server forums > Thread Replies

ArcGIS Server Forums

ArcGIS API for Flex forum

passing an event from one widget to another   drew dowling Nov 04, 2009
Re: passing an event from one widget to ano...   Robert Scheitlin Nov 04, 2009
Re: passing an event from one widget to ano...   drew dowling Nov 12, 2009
Report Inappropriate Content • Top • Print • Reply    
Subject passing an event from one widget to another 
Author drew dowling 
Date Nov 04, 2009 
Message Hi all

I have 2 widgets that I want to be able to interact with one another. One is for reporting zoning info and the other is is for searching for addresses. With the zoning widget the user clicks on the map and zoning info is reported from a geoprocessing service. With the search widget the user enters address info to query a geocoding service.

What I would like is that when the search widget returns a result I would like to be able pass the coordinate to my reporting widget as a map click event to fire the report generation.

I can open the reporting widget from the search widget but I cannot raise a click event. Any suggestions on how to accomplish what I need?

Below is the code that executes when an address result is returned. The last two lines are where I try to get the reporting widget to fire. 
 
private function onGeoResult(candidates:Array, token:Object = null):void 
{
	if (candidates.length > 0)                    
				{                        
		var addressCandidate:AddressCandidate = candidates[0];                        
		var myGraphic:Graphic = new Graphic();                        
		myGraphic.geometry = addressCandidate.location;                        
		myGraphic.symbol = foundSymbol;                       
		myGraphic.toolTip = addressCandidate.address.toString();
		myGraphic.id = "graphic";                        
		myLocationGraphicsLayer.add(myGraphic);

               map.centerAt(addressCandidate.location); 

               SiteContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_MENU_CLICKED, false, false, ZoningWidget));

               SiteContainer.dispatchEvent(new DrawEvent(DrawEvent.DRAW_END, myGraphic))
 
  Drew Dowling
SanGIS 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: passing an event from one widget to another 
Author Robert Scheitlin 
Date Nov 04, 2009 
Message Drew,

You were close on your code to open the widget from another but the widgetId is a sequential number that is given to the widget when it is configured by the configManager and not a string. To get the widgetId add the code below to the SiteContainer. The getWidgetId function is looking for the label of the widget that you specified in the config.xml

The next part of your quest is just knowing the undocumented widget messaging functions. I would not pursue your idea of launching the drawend event I would just go to the function that is listening for the drawend event. 
 
//Add to the SiteContainer
			private var configData:ConfigData;
			
			public function init():void
			{
				_container = this;
				_lock = true; //make sure only one container is created.
				
				initLogging();
				
				//make sure the event bus is ready.
				_containerEventDispatcher = EventBus.getInstance();
				
				//prepare to show error message
				SiteContainer.addEventListener(AppEvent.APP_ERROR, showError);
				
				//listen for the config data to be loaded
				SiteContainer.addEventListener(AppEvent.CONFIG_LOADED, config);
				
				//tell the modules it's on business.
				SiteContainer.dispatch(SiteContainer.CONTAINER_INITIALIZED);
			}
			
			public function getWidgetId(widgetLabel:String):Number
			{
				var id:Number;
				for (var i:Number = 0; i < configData.configWidgets.length; i++)
		        {
		        	if (configData.configWidgets[i].label == widgetLabel)
		        		id = configData.configWidgets[i].id;
		        }
		        return id;
			}

//In your search widget
addSharedData("someNameYouChoose",someObjectLikeAnArrayCollection);

//In your reporting widget
			import com.esri.solutions.flexviewer.utils.Hashtable;
//Add to the init function
				SiteContainer.addEventListener(AppEvent.DATA_UPDATED, sharedDataUpdated);

//Add this new function
			private function sharedDataUpdated(event:AppEvent):void
			{
				var dataTable:Hashtable = event.data as Hashtable;
				if (dataTable.containsKey("someNameYouChoose"))
				{
					var recAC:ArrayCollection = dataTable.find("someNameYouChoose") as ArrayCollection;
					for (var i:Number = 0; i < recAC.length; i++)
					{
						var obj:Object = recAC[i];
						//This is where you do something with the data that is passed to
						//this widget
					}
					dataTable.remove("someNameYouChoose");
				}
			}
 
  Robert Scheitlin
GIS Manager
Calhoun County, Alabama 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: passing an event from one widget to another 
Author drew dowling 
Date Nov 12, 2009 
Message Thanks Robert this is exactly what I need. This addData event is very handy to know about, it will help me out in several places.

As always you're a legend

 
  Drew Dowling
SanGIS