result:Function â?? Function that should be called when the request has completed successfully. Must have the following signature: public function (result:Object, token:Object = null):void;
// variable=reciever layer // function getLayer(layerId:Number):Layer returns some data with type Layer var layer:Layer = myMap.getLayer(layerId); // no variable=reciever // function can not return any value layer.refresh(); // refresh():void
private function SearchSaleTable(tmp:ArrayCollection):Number { cursor = tmp.createCursor(); var t:String = new String; while(!cursor.afterLast) { t = cursor.current.toString(); var saleQueryTask:QueryTask = new QueryTask(); saleQueryTask.url = "my url"; saleQueryTask.showBusyCursor = true; saleQueryTask.useAMF = false; sQuery.where = "SAPROP = '" + t + "'" ; saleQueryTask.execute(sQuery, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):void { nsum = 0; for each (var g:Graphic in featureSet.features) { nsum += g.attributes.SAPRICE; } trace("on Result " + nsum); sumSaleValue = sumSaleValue + nsum; } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString()); } cursor.moveNext() } return sumSaleValue; }
private function SearchSaleTable(tmp:ArrayCollection):Number { trace(">>>start of SearchSaleTable()"); ... ... trace("query send") saleQueryTask.execute(sQuery, new AsyncResponder(onResult, onFault)); ... ... function onResult(featureSet:FeatureSet, token:Object = null):void { trace("result recieve"); ... ... trace(">>>end of SearchSaleTable()"); return sumSaleValue;
SearchSaleTable(PinArray); // send array to function trace("The very last value " + nsum); private function SearchSaleTable(tmp:ArrayCollection):Number {[INDENT]// loops thru the pin's to search Sale table [/INDENT] [INDENT] cursor = tmp.createCursor();[/INDENT] [INDENT]var t:String = new String;[/INDENT] [INDENT]while(!cursor.afterLast)[/INDENT] [INDENT]{ [/INDENT] [INDENT=2]t = cursor.current.toString();[/INDENT] [INDENT=2]var saleQueryTask:QueryTask = new QueryTask(); [/INDENT] [INDENT=2] saleQueryTask.url = "my url"; saleQueryTask.showBusyCursor = true; saleQueryTask.useAMF = false;[/INDENT] [INDENT=2]sQuery.where = "SAPROP = '" + t + "'" ; saleQueryTask.execute(sQuery, new AsyncResponder(onResult, onFault)); function onResult(featureSet:FeatureSet, token:Object = null):Number {[/INDENT] [INDENT=3]nsum = 0; <-- put breakpoint here [/INDENT] [INDENT=3]for each (var g:Graphic in featureSet.features)[/INDENT] [INDENT=3]{[/INDENT] [INDENT=4]nsum += g.attributes.SAPRICE; [/INDENT] [INDENT=3]}[/INDENT] [INDENT=3]trace("on Result " + nsum); // both "trace" return correct values.........[/INDENT] [INDENT=3] sumSaleValue = sumSaleValue + nsum;[/INDENT] [INDENT=3]trace("The very last value " + nsum); trace("The very last value " + nsum); trace("on sumSale " + sumSaleValue); [/INDENT] [INDENT=3]return nsum;[/INDENT] [INDENT=2]} [/INDENT] [INDENT=2]function onFault(info:Object, token:Object = null):void {[/INDENT] [INDENT=3]Alert.show(info.toString());[/INDENT] [INDENT=2]} cursor.moveNext() [/INDENT] [INDENT]} [/INDENT] [INDENT]return sumSaleValue; or return nsum <-- put breakpoint here [/INDENT] }
<?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" xmlns:esri="http://www.esri.com/2008/ags" pageTitle="Eddie Test"> <s:layout> <s:VerticalLayout paddingTop="0" gap="0"/> </s:layout> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.Graphic; import com.esri.ags.events.MapEvent; import com.esri.ags.tasks.QueryTask; import com.esri.ags.tasks.supportClasses.Query; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.AsyncResponder; [Bindable] private var nsum:Number = 0; protected function button1_clickHandler(event:MouseEvent):void { var queryTask:QueryTask = new QueryTask(); queryTask.url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"; queryTask.useAMF = false; var query:Query = new Query(); query.outSpatialReference = myMap.spatialReference; query.outFields = [ "CITY_NAME", "AGE_UNDER5", "AGE_5_17", "AGE_18_64", "AGE_65_UP" ]; query.returnGeometry = false; query.where = "upper(STATE_NAME) = upper('" + ti.text + "') AND TYPE = 'city'"; //queryTask.concurrency = "last"; queryTask.execute(query, new AsyncResponder(onResult, onFault)); // add the graphic on the map function onResult(featureSet:FeatureSet, token:Object = null):void { nsum = 0; for each (var g:Graphic in featureSet.features) { nsum += g.attributes.AGE_18_64; } trace(nsum); } function onFault(info:Object, token:Object = null):void { Alert.show(info.toString()); } } ]]> </fx:Script> <s:BorderContainer backgroundColor="0x999999" alpha="0.8" width="100%" height="30"> <s:HGroup gap="5" verticalAlign="middle" paddingLeft="30" height="100%" width="100%"> <s:Label fontSize="12" fontWeight="bold" text="State: "/> <s:TextInput id="ti" text="Alaska"/> <s:Button click="button1_clickHandler(event)" label="Search" /> <s:Spacer width="30" /> <s:Label fontSize="12" fontWeight="bold" text="Total Population in {ti.text} from the age of 18 to 64:"/> <s:Label fontSize="12" fontWeight="bold" text="{nsum}"/> </s:HGroup> </s:BorderContainer> <esri:Map id="myMap" openHandCursorVisible="false"> <esri:extent> <esri:Extent xmin="-19385000" ymin="6655000" xmax="-13222000" ymax="13326000"> <esri:spatialReference> <esri:SpatialReference wkid="102100"/> </esri:spatialReference> </esri:Extent> </esri:extent> <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> </esri:Map> </s:Application>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.