Hi (again),
as previously stated, I am learning AS3.
I have written some code (it’s messy and no where near professional looking but for now, I am settling for it just working!) and it isn’t working.
Basically,
I need to have a timer display on the stage and count down/up according to my calculations.
I believe this is done by having the function run over and over with a TimerEvent.
However, I have included it and it doesn’t work.
I have spent all day trying to get it to work with no joy.
Can anyone point out where I am going wrong?
I really don’t want to quit learning this and so have persevered all day … but I just need a shove in the right direction now!
Any help would be appreciated beyond belief!!
Code is below …
package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class timestuff extends MovieClip {
public function timestuff() {
var myTimer:Timer=new Timer(1000, 0);
myTimer.addEventListener(TimerEvent.TIMER, displayTime);
myTimer.start();
var myText:TextField = new TextField();
var myTextFormat:TextFormat = new TextFormat();
var focsSemStart:int = 9;
var focsSemEnd:int = 16;
var date:Date = new Date();
var secsNow = date.seconds;
var minsNow = date.minutes;
var hoursNow = date.hours;
var minsToGo = int;
var hoursToGo = int;
var secsToGo = int;
// embed this into another if statement for the lessons.
function textStuff()
{
myText.width = 500, myText.height = 200, myText.x = 150, myText.y = 5;
myTextFormat.size = 20;
myText.setTextFormat(myTextFormat);
}
function HourMaths(a:int, b:int):int
{
if (a < b)
{
hoursToGo = (b - a);
minsToGo = 59 - minsNow;
secsToGo = 60 - secsNow;
}
else if (a > b)
{
hoursToGo = a - b;
minsToGo = minsNow;
secsToGo = secsNow;
}
if (secsNow == 60)
{
secsToGo = 0
minsToGo = minsToGo + 1
}
if (secsToGo < 10)
{
secsToGo = "0" + secsToGo;
}
if (minsToGo < 10)
{
minsToGo = "0" + minsToGo;
}
return hoursToGo;
return minsToGo;
return secsToGo;
}
HourMaths(hoursNow, focsSemStart);
function displayTime(e:TimerEvent)
{
if (hoursNow < focsSemStart && minsToGo == 0)
{
myText.text = "Lesson start countdown " + (hoursToGo) + ":00:" + (secsToGo);
textStuff();
}
else if (hoursNow < focsSemStart)
{
myText.text ="Lesson start countdown " + (hoursToGo -1) + ":" + (minsToGo)+ ":" + (secsToGo);
textStuff();
}else if (hoursNow > focsSemStart && minsNow == 0)
{
myText.text = "Lesson time elapsed " + (hoursToGo) + ":00" + ":" + (secsNow);
textStuff();
}
else if (hoursNow > focsSemStart && minsNow > 0)
{
myText.text = "Lesson time elapsed " + (hoursToGo) + ":" + (minsToGo) + ":" + (secsToGo);
textStuff();
}
else if (hoursNow == focsSemStart && minsNow == 0)
{
myText.text = "IT'S LESSON TIME";
textStuff();
}
else if (hoursNow == focsSemStart && minsNow > 0)
{
myText.text = "Lesson time elapsed 00:" + (minsToGo) + ":" + (secsToGo);
textStuff();
}
addChild(myText);
}
}
}
}