Replace Infinite loop in Flex
Posted
by H P
on Stack Overflow
See other posts from Stack Overflow
or by H P
Published on 2010-06-18T15:54:28Z
Indexed on
2010/06/18
16:13 UTC
Read the original article
Hit count: 222
Hello,
I want to access a webservice:getMonitorData() , on creationcomplete and returns an array, in an infinite loop so that the getIndex0.text is updated each time.
Flex is not able to handle an infinite loop and gives a timeout error 1502. If I run the for loop until i<2000 or so it works fine.
How can replace the loop so that my webservice is accessed continiously and the result is shown in getIndex0.text.
This is how my application looks like:
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
xmlns:plcservicebean="server.services.plcservicebean.*"
creationComplete="clientMonitor1()">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.CallResponder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable] public var dbl0:Number;
//-----------Infinite Loop, Works fine if condition = i<2000------------------------
public function clientMonitor1():void{
for(var i:int = 0; ; i++){
clientMonitor();
}
}
public function clientMonitor():void{
var callResp:CallResponder = new CallResponder();
callResp.addEventListener(ResultEvent.RESULT, monitorResult);
callResp.addEventListener(FaultEvent.FAULT, monitorFault);
callResp.token = plcServiceBean.getMonitorData();
}
public function monitorResult(event:ResultEvent):void{
var arr:ArrayCollection = event.result as ArrayCollection;
dbl0 = arr[0].value as Number;
}
protected function monitorFault(event:FaultEvent):void{
Alert.show(event.fault.faultString, "Error while monitoring Data ");
}
]]>
</fx:Script>
<fx:Declarations>
<plcservicebean:PlcServiceBean id = "plcServiceBean"
showBusyCursor="true"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" />
</fx:Declarations>
<mx:Form x="52" y="97"
label="Double">
<mx:FormItem label = "getMonitorValue">
<s:TextInput id = "getIndex0"
text = "{dbl0}"/>
</mx:FormItem>
</mx:Form>
</s:Group>
© Stack Overflow or respective owner