转载的代码,本人也是刚刚入门,所以添加不上解释,望有高手可以添加一下注释以供学习
- <?xmlversion="1.0"encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"
- creationComplete="init();">
- <mx:Script>
- <![CDATA[
- import mx.utils.UIDUtil;
- private var timer:DataTimer;
- private function init():void {
- timer = new DataTimer(1000);
- timer.data.startTime = getTimer();
- timer.data.uid = UIDUtil.createUID();
- timer.addEventListener(TimerEvent.TIMER, timer_timer);
- timer.start();
- }
- private function timer_timer(evt:TimerEvent):void {
- var tmr:DataTimer = evt.currentTarget as DataTimer;
- var obj:Object = new Object();
- obj.currentCount = tmr.currentCount;
- obj.delay = tmr.delay;
- obj.repeatCount = tmr.repeatCount;
- obj.running = tmr.running;
- obj.startTime = tmr.data.startTime;
- obj.uuid = tmr.data.uid;
- arrColl.addItemAt(obj, 0);
- }
- ]]>
- </mx:Script>
- <mx:ArrayCollection id="arrColl"/>
- <mx:DataGrid id="dataGrid"
- dataProvider="{arrColl}"
- width="100%"
- rowCount="10"
- verticalGridLines="false"
- verticalScrollPolicy="on">
- <mx:columns>
- <mx:DataGridColumn dataField="currentCount"/>
- <mx:DataGridColumn dataField="repeatCount"/>
- <mx:DataGridColumn dataField="delay"/>
- <mx:DataGridColumn dataField="running"/>
- <mx:DataGridColumn dataField="startTime"
- headerText="startTime (*)" />
- <mx:DataGridColumn dataField="uuid"
- headerText="uuid (*)" />
- </mx:columns>
- </mx:DataGrid>
- </mx:Application>
下面是DataTimer.as代码:
- package{
- import flash.utils.Timer;
- public classDataTimer extends Timer{
- private var_data:Object;
- public functionDataTimer(delay:Number,repeatCount:int=0){
- super(delay,repeatCount);
- _data ={};
- }
- public functionget data():Object{
- return _data;
- }
- public functionset data(value:Object):void{
- _data =value;
- }
- }
- }