/As:MainAs:Main
Hi, we are going to make a time counter for a game.
http://img70.imagesh..e=timecounter8dt.swf
1.- Make 2 Dinamic Text Box. Minutes & Seconds.
In the Dinamic Text properties on Minutes ,
where it say var put mins & on seconds put sec.
2. Open on your first frame Actions Panel.
3. We are going to put some variables after the function
4. Now we are going to make a function called time_
fps = 30; //put here the fps number if you have 12 put 12 if you have 50 put 50.
min = 3; //or whatever you want but less than 59
sec = 59; // or whatever you want but less than 59
//We create a function that is going to be called soon.
function time_()
{
if(fps > 0) // we are checking if the fps is greater than 0
{
fps--; //we decrease it by one.
}else // if fps is not greater than 0 then do the next action
{
sec++; // we increase the seconds by one,if you want to decrease it put sec--
fps = 30; // we put again our fps
}
//Now we are going to change the minutes
if(sec >= 60) // we check if sec its greater than 60 why 60 it is going to look better/
{
min++;
sec = 0; // just look at a clock and you will see why it changes to cero.
}
//if you want to decrease your mins just put this bit of code
if(sec <= -1) // why -1 becouse if we put 0 is going to look strange
{
min--;
sec = 59; // you know why
}
}
Now we are going to Make a
onEnterFrame = function()
{
time_(); // we call the function like this. if it is on a mc or something else put _level0.time_(); or _root.time();
_root.Mins = min;
//when the secs are < 9 it will look like this 3:9 and we want to add a cero on 3:09
if(sec <= 9 && sec >= 0)
{
_root.Secs = "0"+ sec;
}else //if its not 1 digit number ^^
{
_root.Secs = sec;
}
/ /now if minutes are 0 and sec 0 then do whatever you want so we want to stop it there
if(sec <= 0 && min <= 0)
{
sec=0;
min = 0;
do whatever you want
nextFrame();
gotoAndStop("lose");
etc.
}
}
Thanks you , this is my first tutorial. And i just want to say if you dont understand my english its becouse im mexican and im really bad on English. & I dont miss one thing.. the completed code.
Remember the two dinamic text box.
//////////////////////////////////////////
/////////////////////
fps = 30;
min = 3;
sec = 59;
function time_()
{
if(fps > 0)
{
fps--;
}else
{
sec--;
fps = 30;
}
if(sec >= 60)
{
min++;
sec = 0;
}
if(sec <= -1)
{
min--;
sec = 59;
}
}
onEnterFrame = function()
{
time_();
_root.Mins = min;
if(sec <= 9 && sec >= 0)
{
_root.Secs = "0"+ sec;
}else
{
_root.Secs = sec;
}
if(sec <= 0 && min <= 0)
{
sec=0;
min = 0;
}
}
Time Counter Example ^^ You are free to compress it. TimeCounter Example ^^ you can descompress it if you want