关于Flash as3.0 求制作一个数字时钟的代码?

如题,格式就是12:30 这种格式的时钟,哪位高手可以帮帮忙呢?
2024年11月17日 16:54
有2个网友回答
网友(1):

那位兄弟格式上显然不能满足要求,我在他的基础上改改
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.setInterval;
import flash.utils.clearInterval;

//若果放到as里,上面导入必须

var date:Date = null;
var textField:TextField = null;
var id = null;

function Init_(){
createText();
clearInterval(id);
id = setInterval(setTimeFun,1000);
setTimeFun();
}

function createText(){
textField = new TextField();
textField.type = TextFieldType.DYNAMIC;
textField.width = 120;
textField.height = 22;
textField.border = true;

var tf:TextFormat = new TextFormat();
tf.size = 20;
tf.align = "center";

textField.defaultTextFormat = tf;

textField.x = this.stage.stageWidth/2-textField.width/2;
textField.y = this.stage.stageHeight/2-textField.height/2;

addChild(textField);
}

function setTimeFun(){
date = new Date();
var hour:uint = date.getHours();
var minute:uint = date.getMinutes();
var seconds:uint = date.getSeconds();
var hourStr:String = String(hour);
var minuteStr:String = String(minute);
var secondsStr:String = String(seconds);
if (hour < 10)
{
hourStr = "0" + hour;
}
if (minute < 10)
{
minuteStr = "0" + minute;
}
if (seconds < 10)
{
secondsStr = "0" + seconds;
}
textField.text = hourStr + ":" + minuteStr + ":" + secondsStr;
}

Init_();

再给你一种
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
import flash.events.TimerEvent;

var date:Date ;
var myTxt:TextField;
var timer:Timer;

function init()
{
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,setTimeFun,false,0,true);
timer.start();
myTxt = new TextField();
myTxt.type = TextFieldType.DYNAMIC;
myTxt.width = 120;
myTxt.height = 22;
myTxt.border = true;

var tf:TextFormat = new TextFormat();
tf.size = 20;
tf.align = "center";

myTxt.defaultTextFormat = tf;

myTxt.x = this.stage.stageWidth / 2 - myTxt.width / 2;
myTxt.y = this.stage.stageHeight / 2 - myTxt.height / 2;

addChild(myTxt);
}

function setTimeFun(evt:TimerEvent)
{
date = new Date();
var hour:uint = date.getHours();
var minute:uint = date.getMinutes();
var seconds:uint = date.getSeconds();
var hourStr:String = String(hour);
var minuteStr:String = String(minute);
var secondsStr:String = String(seconds);
if (hour < 10)
{
hourStr = "0" + hour;
}
if (minute < 10)
{
minuteStr = "0" + minute;
}
if (seconds < 10)
{
secondsStr = "0" + seconds;
}
myTxt.text = hourStr + ":" + minuteStr + ":" + secondsStr;

}

init();

网友(2):

import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.setInterval;
import flash.utils.clearInterval;

//若果放到as里,上面导入必须

var date:Date = null;
var textField:TextField = null;
var id = null;

function Init_(){
createText();
clearInterval(id);
id = setInterval(setTimeFun,1000);
setTimeFun();
}

function createText(){
textField = new TextField();
textField.type = TextFieldType.DYNAMIC;
textField.width = 120;
textField.height = 22;
textField.border = true;

var tf:TextFormat = new TextFormat();
tf.size = 20;
tf.align = "center";

textField.defaultTextFormat = tf;

textField.x = this.stage.stageWidth/2-textField.width/2;
textField.y = this.stage.stageHeight/2-textField.height/2;

addChild(textField);
}

function setTimeFun(){
date = new Date();
textField.text = date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
}

Init_();

直接复制代码放到一个新建的as3.0flash文档里