Hay un DataGrid de una columna que muestra el atributo "c1" del xml, y un textArea que muestra el atributo "c2".
Construí un sistema de tiempos los cuales gatillan un evento de popup (de Window). Cada 20 segundos se crea una nueva ventana y esta a los 10 se cierra.
//Esta es la aplicación
Código :
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();" layout="absolute"> <mx:HTTPService id="hsXML" url="xml.xml" showBusyCursor="true" result="onResult(event)" resultFormat="object"/> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] public var hsXMLaC:ArrayCollection = new ArrayCollection; [Bindable] public var AHselectedNode:XML; [Bindable] var selectedEntry; private const MIN_MASK:String = "00"; private const SEC_MASK:String = "00"; private const MS_MASK:String = "000"; private const TIMER_INTERVAL:int = 10; private var baseTimer:int; private var t:Timer; private function init():void { hsXML.send(); initTimer(); } private function onResult(e:ResultEvent){ hsXMLaC = e.result.node; } private function initTimer():void { t = new Timer(1000, 20); t.addEventListener(TimerEvent.TIMER, updateTimer); t.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete); startTimer(); } private function updateTimer(evt:TimerEvent):void { var d:Date = new Date(getTimer() - baseTimer); var min:String = (MIN_MASK + d.minutes).substr(-MIN_MASK.length); var sec:String = (SEC_MASK + d.seconds).substr(-SEC_MASK.length); var ms:String = (MS_MASK + d.milliseconds).substr(-MS_MASK.length); counter.text = String(min + ":" + sec + "." + ms); } private function startTimer():void { baseTimer = getTimer(); t.start(); } private function stopTimer():void { t.stop(); } public function onTimerComplete(event:TimerEvent):void{ hsXML.send(); t.reset(); startTimer(); newNot(); } private function datagridChanged(event:Event):void { AHselectedNode=DataGrid(event.target) as XML; } private function newNot():void { var win:WinPop = new WinPop(); win.open(true); //win.stage.align = StageAlign.RIGHT; } ]]> </mx:Script> <mx:HBox height="157" width="100%"> <mx:HDividedBox height="100%" width="100%"> <mx:DataGrid id="AHGrid" height="100%" width="100%" dataProvider="{hsXMLaC}" change="selectedEntry=event.target.selectedItem"> <mx:columns> <mx:DataGridColumn headerText="c1" dataField="c1"/> </mx:columns> </mx:DataGrid> <mx:TextArea height="100%" width="100%" text="{selectedEntry.c2}"> </mx:TextArea> </mx:HDividedBox> </mx:HBox> <mx:ApplicationControlBar dock="true"> <mx:Button label="Start tiempo" click="startTimer()" /> <mx:Button label="Stop tiempo" click="stopTimer()" /> <mx:Label id="counter" fontSize="10" /> <mx:Button x="310" y="0" label="popup" click="newNot()"/> <mx:Button x="380" y="0" label="refresco" click="hsXML.send(), newNot()"/> </mx:ApplicationControlBar> </mx:WindowedApplication>
//Esta es la ventana
Código :
<?xml version="1.0" encoding="utf-8"?> <mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" type="{NativeWindowType.UTILITY}" transparent="false" title="WinPop" width="300" height="150" maximizable="false" minimizable="false" resizable="false" creationComplete="initTimer();" layout="vertical"> <mx:Script> <![CDATA[ private const MIN_MASK:String = "00"; private const SEC_MASK:String = "00"; private var baseTimer:int; private var t:Timer; private function initTimer():void { t = new Timer(1000, 10); t.addEventListener(TimerEvent.TIMER, updateTimer); t.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete); startTimer(); } private function updateTimer(evt:TimerEvent):void { var d:Date = new Date(getTimer() - baseTimer); var min:String = (MIN_MASK + d.minutes).substr(-MIN_MASK.length); var sec:String = (SEC_MASK + d.seconds).substr(-SEC_MASK.length); counter.text = String(min + ":" + sec); } private function startTimer():void { baseTimer = getTimer(); t.start(); } private function stopTimer():void { t.stop(); } public function onTimerComplete(event:TimerEvent):void{ //t.reset(); close(); } ]]> </mx:Script> <mx:TextArea width="100%" height="20" text="popup"/> <mx:TextArea width="100%" height="100%" text="aca deberia aparecer el contenido de c2, la idea sería que se gatille el popup cuando se actualice el xml. Podría ser comparando la fecha o el peso del archivo en cuestión"/> <mx:Label id="counter" width="65"/> </mx:Window>
Para empezar tengo dos pequeñas inquietudes, una tiene que ver con la toma de datos del popup, la idea es que en un campo de texto de este se muestre el dato "c2" (del "selectedEntry" de la aplicación principal).
La otra duda es sobre cuándo se deberia gatillar el evento. Quisiera que esto ocurra cuando se actualiza el xml, pero no se por donde empezar. Se me ocurrió que se podría hacer una comparación entre los pesos, o las fechas de creación del xml (las de antes de actualizarse y las de despues). Para ser honesto, no se como seria posible hacerlo. Se me ocurre que se podría hacer una función al estilo "if (fechaAnterior != fechaPosterior entonces newNot(), y entonces habria que mostrar la nueva noticia (c2) en el campo de texto del popup.
Me harian un gran favor si me pudieran orientar. Muchas gracias.
Su amigo, COOKERNATOR.
PD: La web de cristalab estuvo teniendo problemas, no encontraba la página y ahora que está funcionando veo algunas diferencias como que mi código tiene un espaciado muy grande, disculpen si se trata de un descuido mío.