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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VIRT & WANGBAR... QUESTIONS? 2

Status
Not open for further replies.

oldnewbie

Technical User
Dec 6, 2000
9,142
CA
Hi guys!

Please check this out:

Carl, this may be the timer you were looking for. My question to you is: this a 34 seconds track set to loop, for the moment, and the green time display is what you should be looking for. It now displays the actual time of the track as it plays and resets to zero when re-starting. Is this the time you would like in the case of a track looping, or would you rather want a cumulative time displayed as long as the track is playing?

Wangbar, I've never really liked maths and usually have a hard time with them.
I've written this script (inside a looping mc) to simply convert the seconds (from getTimer()) into a minutes and seconds display (the black one):

_root.tkcount = Math.floor(getTimer()/1000);
if (_root.tkcount>59) {
_root.minutes = int(_root.tkcount/60);
_root.seconds = _root.tkcount-(60*_root.minutes);
if (_root.minutes<10) {
if (_root.seconds<10) {
_root.display = &quot;0&quot;+_root.minutes+&quot;:0&quot;+_root.seconds;
} else {
_root.display = &quot;0&quot;+_root.minutes+&quot;:&quot;+_root.seconds;
}
} else {
}
} else if (_root.tkcount<10) {
_root.display = &quot;00:0&quot;+_root.tkcount;
} else {
_root.display = &quot;00:&quot;+_root.tkcount;
}

Now it works fine... But is there a better way (more efficient?) to write such a script? And if I was to put in a function, would it be any better in terms of execution?

Thanks,

mywink2.gif
ldnewbie
 
your the man bro..if you were a woman and were here i'd kiss ya...no can you send it to me?..
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
oh and by the way when the sound trac ends..it will end..they will have to choose another trac..if that helps..no looping!
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
What if they want to hear that same track again? Timer would re-start?

Have to go out for a few hours, will send you the .fla later tonight.
Would be nice if Wangbar answered! I guess you would prefer a minutes & seconds display rather than a cumulative seconds only display, right?

Regards,
mywink2.gif
ldnewbie
 
yeh i need minutes and seconds, would be nice..and if they click the same trac again it will restart..actually it should just start when the movie sound trac is loaded..remembering each sound trac will be in it's own movie pre-loaded and then played..after the pre-loading the timer and sound should start..
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
The nested condition code...


if (_root.minutes<10) {
if (_root.seconds<10) {
_root.display = &quot;0&quot;+_root.minutes+&quot;:0&quot;+_root.seconds;
} else {
_root.display = &quot;0&quot;+_root.minutes+&quot;:&quot;+_root.seconds;
}
} else {
}

... is pretty inefficient (because you're evaluating things twice in some cases) when this would be much less processor intensive...


if (seconds<10) {
seconds = &quot;0&quot;+seconds;
}
if (minutes<10) {
minutes = &quot;0&quot;+minutes;
}
if (hours<10) {
hours = &quot;0&quot;+hours;
}
tkcount = hours+&quot;:&quot;+minutes+&quot;:&quot;+seconds;

I haven't stuck in all the &quot;_root&quot; paths etc. but you get the idea.

Putting all this code in a function would be easy enough and then you could just call it with getTime()...

function getTime(){
//your code
return tkcount;
}
 
Sorry, that last post wasn't particularly helpful, here's a complete version...

count = Math.floor(getTimer()/1000);
seconds = count % 60;
minutes = Math.floor(count/60);
if (minutes<10) {
minutes = &quot;0&quot;+minutes;
}
if (seconds<10) {
seconds = &quot;0&quot;+seconds;
}
display = minutes+&quot;:&quot;+seconds;
 
Ok! Thanks Wang... I'll try your code. Just wondering what seconds = count % 60; really does?

And then, does putting this in a function, really make a difference in terms of processing, or is basicly just for simplicity when calling it from anywhere without having to type it all back each time?

Thanks again,

Regards,
mywink2.gif
ldnewbie
 
That's the modulo operator: &quot;seconds % 60&quot; divides the variable by sixty but only returns the remainder. For instance...

23%5=3 (5*4=20 with 3 remaining)

so...

57%60=57 (0*60 with 57 remaining)

It's cool shorthand.

Putting things into functions doesn't give a speed advantage (not that I've noticed anyway), it's the convenience and clarity it brings to the code that counts.

Ideally you want a frame in your movie where you put all of your functions then call them from wherever you need to: if something goes wrong you know where to go to debug, if something needs to be changed you just have to do it once rather than fish through miles of spaghetti trying to find every instance of a piece of code.

It also helps when you get into extending objects and adding methods with &quot;.prototype&quot; etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top