Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US :: FAQ
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
ADOBE FLASH:HomeFlash ForumFlash TutorialsFlash Video TutorialsWeb Streaming ForumAdobe FlashPodcast

Keeping track of time in Flash

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook
Manny RellesivaKeeping track of time in Flash
by on Nov 26, 2008 at 10:12:12 am

I created a Flash movie/game wherein users would try to find for specific objects. Im thinking of using getTimer function to keep track of the time it takes for the user to find all these objects. Is there any other function and/or properties in Flash to do this? Another issue I have is that the displayed time should have a format like this - hh:mm:sec:millisec. Any ideas? Thanks in advance.

manny


Return to posts index
Reply   Like  

Sam MatternRe: Keeping track of time in Flash
by on Nov 26, 2008 at 1:34:20 pm

You could use an Interval called every millisecond like so:

var runTime:Number = 0;
var runMSec:Number = 0;
var runSec:Number = 0;
var runMin:Number = 0;
var runHr:Number = 0;

setInterval( timeFunc, 1 );
function timeFunc():Void{
runTime += 1;
displayTime();
}

Then for your display, you convert your runTime variable from milliseconds to hours, minutes, seconds, & milliseconds. Assuming you're using dynamic text boxes:

function displayTime():Void{
runHr.text = runTime / 3600000;
runMin.text = runTime / 60000;
runSec.text = runTime / 1000;
runMSec.text = runTime;
}


That should give you something close, but labor intensive. Let me know if it doesn't work right, and I'll figure out the smarter way to do it. I haven't had my cup of coffee yet this morning. The answers are always in the bottom of it.

-Sam


Return to posts index
Reply   Like  

Manny RellesivaRe: Keeping track of time in Flash
by on Nov 27, 2008 at 8:22:45 am


thanks sam,

i tried the last block of codes you gave me with text property. i figured that text property is only available in Actionscript 3...is there any way to do this in AS2?

manny


Return to posts index
Reply   Like  


Sam MatternRe: Keeping track of time in Flash
by on Dec 1, 2008 at 2:07:08 pm

I responding in AS 2.0. The .text property is of a dynamic text box. If you have a dynamic text box with the instance name runHr, then you set its contents by addressing it as follows:
runHr.text = "This is what it will display.";

In that last bit of original code I gave you, we set the contents of runHr to the number of milliseconds divided by 3.6 million (what you need to divide milliseconds by to get hours).

I'm not sure how else you'd be displaying the run time.

-Sam


Return to posts index
Reply   Like  

Manny RellesivaRe: Keeping track of time in Flash
by on Dec 4, 2008 at 5:07:24 am

thanks sam, you;ve been very helpful. Im a newbie in AS. Another problem im having right now is how to concatenate decimal fields.

manny


Return to posts index
Reply   Like  

Sam MatternRe: Keeping track of time in Flash
by on Dec 4, 2008 at 1:48:20 pm

Post an example of what you're trying to do. Concatenation only applies to strings, so if you're trying to take 0.01234 and make it 0.0123456789, you could try (I haven't tested this):
var sDecimal1:String = "01234";
var sDecimal2:String = "56789";
var concatDecimal:Number = Number( "0."+sDecimal1+sDecimal2 );
trace(concatDecimal);//should display 0.0123456789


So if you have your decimal numbers already, you would make them strings by:
var sDecimal1:String = firstNumber;
var sDecimal2:String = secondNumber;
var concatDecimal:Number = Number( "0."+sDecimal1.slice(sDecimal1.indexOf(".")+1)+sDecimal2.slice(sDecimal1.indexOf(".")+1) );


Conceivably, once again not tested, how this works is stores each number as a string. Problem is, they both conceivably have some whole number in front of them, such as 0 or anything. So we slice each one AFTER the "." and then add them together. See if this works. The other option, of course, is figuring out the actual math behind it.

-Sam


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook


FORUMSTUTORIALSFEATURESVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2014 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]