Select to view content in your preferred language

QueryTask Called Multiple Times in a Row - Only Returns on Result

415
0
01-09-2013 05:05 AM
chuckfrank
Frequent Contributor
Hi All,

In an effort to write reusable code, I wrote the function below that will query a feature layer (url paramater) by a polygon (poly parameter).  This way I don't need to have a separate query and actionscript block for each feature layer that I'll query.  The problem that will happen is that when the function is called multiple times in a row the second query will begin before the first one has completed because it's asynchronous.  At that point I'm not sure how to know which result is which.  I really want to avoid having to write a black of code for each specific query, but when I try to generalize it, like the example below, I'm running into the asynchonous issues.  Does any body have any ideas to handle this or a code example of a better way?  Is there a way I can understand which result is which?

Thanks,
Chuck

  private function FilterAttributeTablesByPolygon(poly:Polygon, strURL:String):void
  {
   querytaskFeaturesByPolygon.url = strURL;
   
   queryFeaturesByPolygon.geometry = poly;
   
   querytaskFeaturesByPolygon.execute(queryFeaturesByPolygon);
  }

                protected function querytaskFeaturesByPolygon_executeCompleteHandler(event:QueryEvent):void
   {
    
    // highlight the selected features - NOT DONE
    var fs:FeatureSet = event.featureSet;
    
    var attributes:Array = fs.attributes;
    var al:ArrayList = new ArrayList();
    
    for each (var objRec in attributes)
    {
     al.addItem(objRec);
    }

                      //code continues....
Tags (2)
0 Kudos
0 Replies