Im having an issue due to async functions on my widget
My code:
<viewer:BaseWidget 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:viewer="com.esri.viewer.*" xmlns:components="com.esri.viewer.components.*" xmlns:esri="http://www.esri.com/2008/ags" initialize="basewidget1_initializeHandler(event)" creationComplete="basewidget1_creationCompleteHandler(event)" > <fx:Declarations> <s:GlowFilter id="glowFilter" alpha="1" color="{getStyle('focusColor')}" inner="true" strength="2"/> <s:DateTimeFormatter id="dateFormatter" dateTimePattern="dd/MM/yyyy"/> </fx:Declarations> <fx:Script> <![CDATA[ import com.esri.ags.FeatureSet; import com.esri.ags.Graphic; import com.esri.ags.tasks.QueryTask; import com.esri.ags.tasks.supportClasses.Query; import flash.utils.setTimeout; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.AsyncResponder; import mx.rpc.Responder; import widgets.AdmIngresoClientes.utilidad.urls; [Bindable] public var idPosteNuevo:String; [Bindable] public var idDirNueva:String; [Bindable] public var rotNuevo:String; [Bindable] public var dirNueva:String; [Bindable] public var coleccionClientes:ArrayCollection = new ArrayCollection; [Bindable] public var fs:FeatureSet = new FeatureSet; [Bindable] public var rotu:int; protected function basewidget1_initializeHandler(event:FlexEvent):void { // TODO Auto-generated method stub coleccionClientes.removeAll(); // TODO Auto-generated method stub var queryTask:QueryTask = new QueryTask(widgets.AdmIngresoClientes.utilidad.urls.URL_ADD_CLIENTE); var query:Query = new Query(); query.where = "1=1"; query.outFields = ['*']; query.orderByFields = ['created_date']; query.returnGeometry = true; queryTask.execute(query, new AsyncResponder(onResultQuery, onFaultQuery)); function onResultQuery(featureSet:FeatureSet, token:Object = null):void { var k:int; for(k=0;k<featureSet.features.length;k++) { if ( (featureSet.features.attributes["TIPO_POSTE_CAMARA"] == "nuevo") && (featureSet.features idPosteNuevo = "calcular ID Poste"; rotNuevo = "calcular rotulo"; idDirNueva = "calcular ID Dir"; dirNueva = "calcular direccion nombre"; } if ( (featureSet.features.attributes["TIPO_DIRECCION"] == "nueva") ){ .attributes["TIPO_POSTE_CAMARA"] == "nuevo") && (featureSet.features idPosteNuevo = "calcular ID Poste"; rotNuevo = "calcular rotulo"; idDirNueva = featureSet.features.attributes["TIPO_DIRECCION"] == "existente") ) { .attributes["ID_DIRECCION"]; dirNueva = "calcular direccion nombre"; } if ( (featureSet.features.attributes["TIPO_POSTE_CAMARA"] == "existente") && (featureSet.features idPosteNuevo = featureSet.features.attributes["TIPO_DIRECCION"] == "nueva") ) { .attributes["ID_POSTE_CAMARA"]; rotNuevo = "calcular rotulo"; idDirNueva = "calcular ID Dir"; dirNueva = "calcular direccion nombre"; } if ( (featureSet.features.attributes["TIPO_POSTE_CAMARA"] == "existente") && (featureSet.features rotNuevo = buscarRotulo(featureSet.features.attributes["TIPO_DIRECCION"] == "existente") ) { .attributes["ID_POSTE_CAMARA"]); idDirNueva = featureSet.features.attributes["ID_DIRECCION"]; } var recordGraphic:Graphic = featureSet.features; coleccionClientes.addItem({OBJECTID:recordGraphic.attributes["OBJECTID"], NIS:recordGraphic.attributes["NIS"], NUMERO_MEDIDOR:recordGraphic.attributes["NUMERO_MEDIDOR"], TIPO_POSTE_CAMARA:recordGraphic.attributes["TIPO_POSTE_CAMARA"], ID_POSTE_CAMARA:String(idPosteNuevo), TIPO_DIRECCION:recordGraphic.attributes["TIPO_DIRECCION"], ID_DIRECCION:String(idDirNueva), ROTULO:String(rotNuevo), gra:recordGraphic}); } } function onFaultQuery(info:Object, token:Object = null):void { Alert.show("Error en consulta","Carga de Clientes"); } } public function buscarRotulo(idp:String):String{ var rt:String; var queryTask:QueryTask = new QueryTask(widgets.AdmIngresoClientes.utilidad.urls.URL_ROTULOS); var query:Query = new Query(); query.where = "id_nodo="+ idp; query.outFields = ['rotulo']; query.returnGeometry = false; queryTask.execute(query, new AsyncResponder(onResultQuery2, onFaultQuery2)); function onResultQuery2(featureSet2:FeatureSet, token:Object = null):void { //var recordGraphic:Graphic = featureSet2.features[index]; rt = String(featureSet2.features[0].attributes["rotulo"]); // Alert.show(rotNuevo); } function onFaultQuery2(info:Object, token:Object = null):void { } return rt; } protected function basewidget1_creationCompleteHandler(event:FlexEvent):void { // TODO Auto-generated method stub DataClientesNuevos.dataProvider = coleccionClientes; } ]]> </fx:Script> <viewer:WidgetTemplate id="wTemplate" width="800" height="500" visible="true"> <mx:Canvas id="ListadoClientes" label="Lista Clientes Nuevos" width="100%" height="100%"> <s:VGroup width="100%" top="5" bottom="5" height="100%"> <mx:Label id="Lblclie" text="Listado de Nuevos Clientes" fontSize="18"/> <mx:DataGrid id="DataClientesNuevos" resizableColumns="true" sortableColumns="true" editable="false" width="100%" height="100%" visible="true" selectable="true"> <mx:columns> <mx:DataGridColumn dataField="OBJECTID" headerText="OBJECTID" width="30" visible="false"/> <mx:DataGridColumn dataField="NUMERO_MEDIDOR" headerText="NUMERO MEDIDOR" width="50" /> <mx:DataGridColumn dataField="NIS" headerText="NIS" width="50"/> <mx:DataGridColumn dataField="TIPO_POSTE_CAMARA" headerText="TIPO_POSTE_CAMARA" visible="true" width="50" /> <mx:DataGridColumn dataField="ID_POSTE_CAMARA" headerText="ID_POSTE_CAMARA" visible="true" width="50" /> <mx:DataGridColumn dataField="ROTULO" headerText="ROTULO" visible="true" width="50" /> <mx:DataGridColumn dataField="TIPO_DIRECCION" headerText="TIPO_DIRECCION" visible="true" width="50" /> <mx:DataGridColumn dataField="ID_DIRECCION" headerText="ID_DIRECCION" visible="true" width="50" /> <mx:DataGridColumn dataField="DIRECCION_PROPIETARIO" headerText="DIRECCION PROPIETARIO" visible="true" width="50" /> <mx:DataGridColumn dataField="CALLE" headerText="CALLE" visible="true" width="50" /> <mx:DataGridColumn dataField="NUMERO" headerText="NUMERO" visible="true" width="50" /> </mx:columns> </mx:DataGrid> </s:VGroup> </mx:Canvas> </viewer:WidgetTemplate> </viewer:BaseWidget>
The logic is:
the main query that u get the "numero medidor, nis, tipo tipo_direccion is from a layer)
The "rotulo" is a query from another layer in the service, the result has to be in the coleccionClientes arrayList, where i ask for the id_poste and it gives me the result for the rotulo.
I have to do the same with the direccion , calle , and numero.
Since im starting to get the rotulo, my problem is i get null for the 2 rows that it has to be shown.
The result is this one in the attach.
How can i do this more efficiently? Cuz the async functions from the other layer im asking has a delay between each row.
thanks in advice! Soon i will start changing this to javascript T -T, i promise.