我有一个嵌入式系统,通过 CGI 进程提供 JSON 结果。我正在尝试设置一个 Flex 应用程序。每秒定期轮询服务器一次并更新 GUI。我正在使用计时器尝试以下方法,但我只得到初始结果,没有进行后续更新。可能出了什么问题?
<?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" minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:HTTPService id="getPacketCounts" showBusyCursor="true" resultFormat="text"
url="http://10.1.10.28/cgi-bin/getpacketcounts"
requestTimeout="500"
result="getPacketCounts_resultHandler(event)"
fault="faultHandler(event)">
</mx:HTTPService>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private var timer:Timer = new Timer(1000, 0);
private var counter:int;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
timer.addEventListener(TimerEvent.TIMER, timerListener);
timer.start();
}
private function timerListener(evt:Event):void {
label.text = "get http://10.1.10.28/cgi-bin/getpacketcounts";
getPacketCounts.send();
}
protected function getPacketCounts_resultHandler(event:ResultEvent):void
{
label.text = event.result.toString().substr(0, 60);
}
protected function faultHandler(event:FaultEvent):void
{
Alert.show("The server returned error code " + event.statusCode + ".", event.fault.faultString);
}
]]>
</fx:Script>
<s:Label id="label" text="v1.0"/>
</s:Application>