Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

building a simple timer

Status
Not open for further replies.

magRoader

Technical User
Dec 2, 2004
5
0
0
US
I'm learning Actionscript
what I'm doing is building a simple timer.
I just want flash to display the current time in a textbox
just a an exercise. can anyone give me some hints?, suggestions? heres my code:

var hrs="hours"
var mins="mins"
this.createTextField("textbox",200,25,100,20,0)
function showTime(){
textbox.getHours
textbox.getMinutes
return showTime
}

Could you also suggest any small projects I
can do to practice loops and functions?

_Mag
 
Hello,

Here's a great timer script that's worked for me:

startTime = getTimer();

//var this_event_seconds:Number = event_seconds * 6000;

_root.txt_output += "\n ( " + this_event_seconds + " ) event_seconds" + event_seconds;
onEnterFrame = function( event_seconds:Number )
{
elapsedTime = getTimer() - startTime;
elapsedHours = Math.floor( elapsedTime / 3600000 );
remaining = elapsedTime - elapsedHours * 3600000;
elapsedM = Math.floor(remaining / 60000);
remaining = remaining - elapsedM * 60000;
elapsedS = Math.floor(remaining / 1000);
remaining = remaining - elapsedS * 1000;
elapsedH = Math.floor(remaining / 10);


if( elapsedHours < 10 )
{
hours = "0" + elapsedHours.toString();
}
else
{
hours = elapsedHours.toString();
} // end if

if( elapsedM < 10 )
{
minutes = "0" + elapsedM.toString();
}
else
{
minutes = elapsedM.toString();
} // end if
if( elapsedS < 10 )
{
seconds = "0" + elapsedS.toString();
}
else
{
seconds = elapsedS.toString();
} // end if

if( elapsedH < 10 )
{
hundredths = "0" + elapsedH.toString();
}
else{ hundredths = elapsedH.toString(); } // end if

trace( "elapsedS: " + elapsedS + " event_seconds: " + this_event_seconds );


_root.timer_txt = hours + ":" + minutes + ":" + seconds + ":" + hundredths;
 
Thanks
oldnewbie and clemrock thank you for your help, the kirupa links are great and that timer code is pretty thorough.

Overall I think in terms of actionscripting what I'm trying to get to is a point where I'm able to create my own timer and reason on my own without just copying and pasting examples,learning from example and reading yes, but then independently reasoning and writing code on my own.

I guess my question is how do you get to a point where you're doing this type of thinking as in the code above. Not nessarily the syntax but the thinking/reasoning skill
involved here.


_Mag
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top