先给大家看看效果效果虽然很简单。这个是我自己学习flex的时候联系自定义控件用的。
上代码
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
public var timer:Timer;
[Bindable]public var time:String;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
timer=new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, timehandle);
timer.start();
}
private function timehandle(e:TimerEvent):void
{
var date:Date=new Date();
var Year:String=date.fullYear.toString();
var Month:String=po0(date.month);
var Day:String=po0(date.date);
var Hours:String=po0(date.hours);
var Minutes:String=po0(date.minutes);
var Seconds:String=po0(date.seconds);
time=Year+"-"+Month+"-"+Day+" "+Hours+":"+Minutes+":"+Seconds
}
public function po0(str:Number):String{
if(str>10){
return str.toString();
}else{
return "0"+str.toString();
}
}
protected function textinput1_mouseUpHandler(event:MouseEvent):void
{
timer.stop();
}
public function gettimeString():String{
return timeInput.text;
}
]]>
</fx:Script>
<s:TextInput width="145" mouseUp="textinput1_mouseUpHandler(event)" text="{this.time}" id="timeInput"/>
</mx:HBox>
功能也不多,动态显示当前时间,鼠标移动到上面时停止时钟。调用gettimeString()方法返回input里面的值。哈哈有了这个东东用户输入时间的时候就不用很麻烦了。