Copy link to clipboard
Copied
I trouble with the day of week showing as a 2 digit number it should show in this format 01/01/2019 but its showing 01/1/2019
any suggestions what I did wrong
import flash.utils.Timer;
import flash.events.TimerEvent;
var looper:Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopf);
function loopf(event:TimerEvent):void{
var time:Date = new Date();
var month:Number = time.getMonth()+1;
var day:Number = time.getDate();
var year:Number = time.getFullYear();
if (month < 10){
date_txt.text = "0" + month + "/" + day + "/" + year;
} else{
date_txt.text = month + "/" + day + "/" + year;
if (day < 10){
date_txt.text = month + "/" + "0" + day + "/" + year;
} else{
date_txt.text = month + "/" + day + "/" + year;
}
//date_txt.text = month + "/" + day + "/" + year;
}
}
I have to correct myself. This is Actionscript 3, hence strict data typing:
...import flash.utils.Timer;
import flash.events.TimerEvent;
var looper: Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopf);
function loopf(event: TimerEvent): void {
var time: Date = new Date();
var month: Number = time.getMonth() + 1;
var day: Number = time.getDate();
var year: Number = time.getFullYear();
var monthStrg:String;
var dayStrg:String;
if (month < 10) {
Copy link to clipboard
Copied
HI daggerzEdge
Try it this way:
import flash.utils.Timer;
import flash.events.TimerEvent;
var looper: Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopf);
function loopf(event: TimerEvent): void {
var time: Date = new Date();
var month: Number = time.getMonth() + 1;
var day: Number = time.getDate();
var year: Number = time.getFullYear();
var monthStrg, dayStrg;
if (month < 10) {
monthStrg = "0" + month + "/";
} else {
monthStrg = month + "/"
}
if (day < 10) {
dayStrg = "0" + day + "/";
} else {
dayStrg = day + "/";
}
date_txt.text = monthStrg + dayStrg + year;
}
Klaus
Copy link to clipboard
Copied
I have to correct myself. This is Actionscript 3, hence strict data typing:
import flash.utils.Timer;
import flash.events.TimerEvent;
var looper: Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopf);
function loopf(event: TimerEvent): void {
var time: Date = new Date();
var month: Number = time.getMonth() + 1;
var day: Number = time.getDate();
var year: Number = time.getFullYear();
var monthStrg:String;
var dayStrg:String;
if (month < 10) {
monthStrg = "0" + month + "/";
} else {
monthStrg = month + "/"
}
if (day < 10) {
dayStrg = "0" + day + "/";
} else {
dayStrg = day + "/";
}
date_txt.text = monthStrg + dayStrg + year;
}
The previous one worked, but this is following the RULEZ.
Klaus
Copy link to clipboard
Copied
I put your code in now it is giving a error
C:\Users\steel\Videos\Auction Timer\New folder (3)\timerClass.as, Line 1 5007: An ActionScript file must have at least one externally visible definition.
am I naming the class or should I just use actions for this
ty jeff
Copy link to clipboard
Copied
ok I got it now
thank you very much
Copy link to clipboard
Copied
I also have a question about a 05:00 minute time I have stop pause and restart all work fine on it, the problem is once I put into a game like second life only the person pressing start will actually see the time countdown any ideas how to fix that, I need to use it at place in game for auctions
Copy link to clipboard
Copied
"... once I put into a game like second life only the person pressing start will actually see the time countdown"
Are you talking about a multi-player scenario?
Copy link to clipboard
Copied
yes its a multiplayer rpg type game
this is what timer looks like if want me to I will post its code
Copy link to clipboard
Copied
Hi
I'm sorry but I never developed a game for the use on a multi player server or the like. It seems to me that when one player starts the timer that this event has to be passed on to all other players (ports, instances, whatever). For that I guess must be methods, events and properties available within the multi player framework. I searched for multi player here on this forum but there isn't much if any.
What is your multi player framework and is the coding language for those multi player events still Actionscript?
I would have to learn all that stuff first before I could possibly answer.
Klaus
Copy link to clipboard
Copied
I am trying to get that information
now I have added a clock that can be see by all and it grabs their time for correct time where ever they maybe.
question I have for you is can I grab from my timer and pull a 05:00 timer off the date/time clock and maybe it will show start and stop and restart
this is my time/date code
import flash.utils.Timer;
import flash.events.TimerEvent;
var looper: Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopF);
function loopF(event:TimerEvent):void{
var time: Date = new Date();
//time variables
var hours:* = time.getHours();
var minutes:* = time.getMinutes();
var seconds:* = time.getSeconds();
var hourStrg:String;
var minuteStrg:String;
var secondStrg:String;
//date variables
var month: Number = time.getMonth() + 1;
var day: Number = time.getDate();
var year: Number = time.getFullYear();
var monthStrg:String;
var dayStrg:String;
//date text
if (month < 10) {
monthStrg = "0" + month + "/";
} else {
monthStrg = month + "/"
}
if (day < 10) {
dayStrg = "0" + day + "/";
} else {
dayStrg = day + "/";
}
//time text
if(String(seconds).length < 2){
seconds = "0" + seconds;
}
if(String(minutes).length < 2){
minutes = "0" + minutes;
}
if(hours > 11){
ampm_txt.text = "PM";
} else {
ampm_txt.text = "AM";
}
if(hours > 12){
hours = hours - 12;
}
if (String(hours).length < 2){
hours = "0" + hours;
}
time_txt.text = hours + ":" + minutes + ":" + seconds;
date_txt.text = monthStrg + dayStrg + year;
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------
and this is timer I have at moment
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.ui.Mouse;
public class timerClass extends MovieClip
{
var myTimer:Timer = new Timer(1000, 300);
var i:Number = 300;
public function timerClass()
{
//# constructor code
timerTxt.text = String("05:00");
myTimer.addEventListener(TimerEvent.TIMER, updateTime);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);
startbutton.addEventListener(MouseEvent.CLICK, StartNow);
pausebutton.addEventListener(MouseEvent.CLICK, PauseNow);
restartbutton.addEventListener(MouseEvent.CLICK, restartNow);
}
private function updateTime(e:TimerEvent)
{
i--;
var totalSeconds:* = i;
var minutes:* = Math.floor(totalSeconds/60);
var seconds:* = totalSeconds % 60;
if(String(minutes).length < 2)
{
minutes = "0" + minutes;
if(String(seconds).length < 2)
seconds = "0" + seconds;
}
timerTxt.text = minutes + ":" + seconds;
}
private function TimerComplete(e:TimerEvent)
{
messageTxt.text = "PRESENTATION IS NOW OVER"
timerTxt.text = String("00:00");
}
private function StartNow(e:MouseEvent)
{ myTimer.start(); }
private function PauseNow(e:MouseEvent)
{ myTimer.stop(); }
private function restartNow(e: MouseEvent): void
{
myTimer.stop();
myTimer = new Timer(1000, 300);
myTimer.addEventListener(TimerEvent.TIMER, updateTime);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerComplete);
i = 300;
messageTxt.text = "";
timerTxt.text = String("05:00");
}
} //#end Class
} //#end Package
Find more inspiration, events, and resources on the new Adobe Community
Explore Now