Código :
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" applicationComplete="fcnLlenaDatosTipos()" backgroundGradientAlphas="[0.0, 1.0]" backgroundColor="#FDFCFC" width="800" height="742.42426">
<mx:Script>
<![CDATA[
import mx.events.IndexChangedEvent;
import mx.controls.Text;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
public var aryDataProviders:Array=new Array([
{dpName:'mysDatosGrid'},
{dpName:'Tipos'}
]);//declaracion de array que guarda los data providers
public var aryMensaje:Array = ([{mensaje:'', tipo:'',respuesta:''}]);
public var oArray:Object;
public var oControl:Object;
public var cNombreArray:String;
private function onResult(event:ResultEvent,oTarget:Object,cNombreArray:String):void{
aryDataProviders[cNombreArray] = new ArrayCollection(event.result as Array);
oTarget.dataProvider=aryDataProviders[cNombreArray];
}
private function fcnInit():void{
oControl=cboTipos;
cNombreArray='Tipos';
RemoteService.consulta('select * from tipos_mensajes_buzon');
oControl=grdComentarios;
cNombreArray='mysDatosGrid';
RemoteService.consulta('select * from mensajes_buzon_sugerencias');
}
private function onFault(event:FaultEvent):void{
trace("ERROR: ",event.fault.faultString)
}
private function fcnConsultar():void{
oControl=grdComentarios;
cNombreArray='mysDatosGrid';
RemoteService.consulta('select * from mensajes_buzon_sugerencias');
}
private function fcnEliminar(cTable:String,cCampoClave:String,nClave:String):void{
RemoteService.eliminar(cTable,cCampoClave,nClave);
}
private function fcnShowDetails():void{
currentState="detalle"
}
private function fcnLlenaDatosTipos():void{
oControl=cboTipos;
cNombreArray='Tipos';
RemoteService.consulta('Select * from tipos_mensajes_buzon');
}
public function fcnDefaultItem(oTarget:Object,nCodigoBuscar:int,aryDatos:String):void{
var i:int;
var aryDp:Object=aryDataProviders[aryDatos];
for(i=0;i < aryDp.length;i++){
if(aryDp[i].codigo==nCodigoBuscar){
oTarget.selectedIndex=i;
}
}
}
]]>
</mx:Script>
<mx:RemoteObject
destination="GenericDestination"
id="RemoteService"
source="queryssiodd"
showBusyCursor="true"
result="onResult(event,oControl,cNombreArray);"
fault="onFault(event);"
/>
<mx:Binding destination="aryMensaje[0].tipo" source="cboTipos.selectedItem.codigo"/>
<mx:Binding destination="aryMensaje[0].mensaje" source="txtMensaje.text"/>
<mx:Binding destination="aryMensaje[0].respuesta" source="txtRespuesta"/>
<mx:states>
<mx:State name="atender">
<mx:RemoveChild target="{grdComentarios}"/>
<mx:RemoveChild target="{dateFieldA}"/>
<mx:RemoveChild target="{dateFieldDe}"/>
<mx:RemoveChild target="{label3}"/>
<mx:RemoveChild target="{cboCategorias}"/>
<mx:RemoveChild target="{label2}"/>
<mx:RemoveChild target="{label1}"/>
<mx:AddChild position="lastChild">
<mx:Canvas width="730.98486" height="480.83334">
<mx:Button label="Lista" id="cmdLista" height="46" width="123" labelPlacement="left" x="584.9" y="362.05" click="currentState="""/>
<mx:Button label="Guardar Cambios" id="cmdGuardar" height="46" x="442.45" y="359.05"/>
</mx:Canvas>
</mx:AddChild>
<mx:RemoveChild target="{main}"/>
<mx:SetProperty name="height" value="521.13635"/>
</mx:State>
</mx:states>
<mx:Panel width="100%" height="100%" layout="absolute" id="main" title="LISTA DE MENSAJES DEL BUZON ">
<mx:DataGrid x="9.1" y="46.35" width="721.9697" height="219.62122" id="grdComentarios" change="fcnLlenaDatosTipos()">
<mx:columns>
<mx:DataGridColumn width="70" dataField="tipo" headerText="TIPO" />
<mx:DataGridColumn headerText="DESCRIPCION" dataField="mensaje"/>
</mx:columns>
</mx:DataGrid>
<mx:Label x="188.65" y="16.75" text="De" id="label2"/>
<mx:Label x="300.65" y="16.75" text="A" id="label3"/>
<mx:DateField x="210.65" y="16.75" id="dateFieldDe" showToday="true"/>
<mx:DateField x="313.65" y="16.75" id="dateFieldA" showToday="true"/>
<mx:ComboBox width="90.303024" height="22.045454" id="cboCategorias" x="94.7" y="16.75">
</mx:ComboBox>
<mx:Label text="Ver categoria" id="label1" x="9.1" y="18.8"/>
<mx:Form y="298.45" width="713.7121" height="326.81818" x="9.1">
<mx:FormItem label="Tipo">
</mx:FormItem>
<mx:FormItem label="Mensaje">
</mx:FormItem>
<mx:TextArea width="100%" text="{grdComentarios.selectedItem.mensaje}" height="69.01515" id="txtMensaje"/>
<mx:FormItem label="Respuesta">
</mx:FormItem>
<mx:RichTextEditor title="Title" text="{grdComentarios.selectedItem.respuesta}" width="680.98486" height="122.12121" id="txtRespuesta">
</mx:RichTextEditor>
</mx:Form>
<mx:ComboBox id="cboTipos" labelField="descripcion" enabled="true" x="9.05" y="268.9">
</mx:ComboBox>
<mx:Button x="254" y="268" label="Button" click="fcnConsultar()"/>
<mx:Button x="326.6" y="268" label="Button" click="fcnLlenaDatosTipos()"/>
</mx:Panel>
</mx:Application>
