mxml:
<s:CheckBox label="刷新"
buttonMode="true"
id = "frc"
selected = "@{model.autoFresh}"
change = "{model.startAutoQuery(frc.selected)}"/>
<s:Label text="间隔"/>
<s:ComboBox width="45"
dataProvider="{model.refreshTime}"
selectedItem = "@{model.freshTime}"
selectedIndex = "0"
enabled = "{frc.selected}"
labelField="name"
buttonMode="true"/>
<s:Label text="分钟"/>
as类:
/**
* 自动刷新时间时间
*/
[Bindable]
public var refreshTime:ArrayCollection = new ArrayCollection([{name:"1",data:60000},{name:"2",data:120000},
{name:"3",data:180000},{name:"4",data:240000},{name:"5",data:300000},
{name:"6",data:360000},{name:"7",data:420000},{name:"8",data:480000},{name:"9",data:540000},{name:"10",data:600000}]);
private var _timer:Timer;
/**
*
* @default
*/
[Bindable]
public var autoFresh:Boolean = false;
/**
*
* @default
*/
[Bindable]
public var freshTime:Object;
/**
*
*
*/
public function startAutoQuery(value:Boolean = true):void
{
if (!value)
{
stopAutoQuery();
return;
}
if (autoFresh)
{
if (freshTime == null)
freshTime = refreshTime.getItemAt(1);
var _delay:int = freshTime.data;
if (_timer == null)
{
_timer = new Timer(_delay);
_timer.addEventListener(TimerEvent.TIMER, timerHandler);
}
_timer.delay = _delay;
_timer.start();
}
}
/**
*
* @param e
*/
protected function timerHandler(e:Event):void
{
if (freshTime && autoFresh)
{
//timeSearch(); 调用的方法
this.dispatchEvent(new Event("timeHandler"));
}
}
/**
*
*/
public function stopAutoQuery():void
{
autoFresh = false ;
if (_timer)
_timer.stop();
}