PDA

View Full Version : Display date and Time


gee-dog
10-07-2008, 06:39 AM
Hi out there,
I am just beginning my AS3 experience and have a question I hope someone can help me with.

I am attempting to display the date and time in two seperate dynamic text boxes on screen.

I have entered the code to call the current date and time but cannot seem to get the right coding to display it in the appropriate text boxes.

The text boxes have instance names of tbDate and tbTime.

Can someone please tell me what code I need to add to have the date and time to show in the appropriate text boxes

rawmantick
10-07-2008, 06:57 AM
Welcome to the forum.

to set text of a text box you should use its text property.
tbDate.text = yourDateInstance.toString();

gee-dog
10-07-2008, 11:55 AM
Thank you for that help.
I know this may sound stupid, but I am trying to adapt the code to display the cutrrent time in the dynamic text box (tbTime).
It appears that I must set a new var for current time.
Can you please tell me what I need to change in this piece of code to do that?
var currentDate.Date=new Date();

rawmantick
10-07-2008, 12:47 PM
you add an event listener on Event.ENTER_FRAME for your text field and set text field text property to (new Date()).toString()

gee-dog
10-07-2008, 10:06 PM
I am still having trouble with the time.
I have tried what is suggested, but now none of my script works.
Here is the code i have written. Could you please tell where I have gone wrong.

var spaceships:Array=new Array();
var yPos:int=0;//initialise a variable for setting the y coordinate
var currentDate.Date=new Date();
var nDay:Number=currentDate.getDate();
var nMonth:Number=currentDate.getMonth()+1;
var nYear:Number=currentDate.getFullYear();
var displayDate:String=new String();
var nHours=currentDate.getHours();
var nMinutes=currentDate.getMinutes();
displayDate=nDay + "/" + nMonth + "/" + nYear;
tbDate.text = displayDate.toString();
tbTime.text = displayTime.toString();
tbTime.addEventListener(Event.ENTER_FRAME,new Date()).toString();
for (var i:int=0; i<8; i++) {
//generate new instances of yhe spaceshiMC movie clip, store in arrayand set at varying levels

var spaceship:spaceshipMC=new spaceshipMC();
this.addChild(spaceship);
//scale the movie clips by 25%
this.spaceship.scaleX=.25;
this.spaceship.scaleY=.25;//change the y coordiniate so the movie clips don't sit on top of one another
this.spaceship.y=yPos;
yPos+=50;
spaceships[i]=spaceship;
this.spaceship.alpha=0.5;//change.AlphaMC(alpha=0.5);
}

Thanks for your help

rawmantick
10-08-2008, 06:17 AM
var currentDate.Date=new Date();

var currentDate : Date=new Date();

var spaceship:spaceshipMC=new spaceshipMC();

Always name classes starting from capital letter.