关于Flash as3.0 求制作一个数字时钟的代码? 20
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();
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();
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();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
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文档里
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文档里
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询