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

Does CPU speed affect swf play?

Status
Not open for further replies.

CGann

Programmer
Jan 23, 2004
31
0
0
US
I've built a clock app that:
1. Get the user's local time. aka "Your Time"
2. Pings a server hosting a cgi script that returns a GMT date string. aka "GMT"
3. Calculates the difference between Your Time and GMT in milliseconds.
4. Uses that calculated difference to dynamically generate dspGMT which is then used to keep the display updated.

I've got a few people on our company intranet, around the world, testing it out. For 90% everything is great. But, for a few of them, "Your Time" and "dspGMT" fall out of sync.

Is this possibly a CPU speed issue? What else cold be causing this?

Here's a sample of the code that generates the display...
Code:
this.onEnterFrame = function():Void {
yourDate = new Date();
// pull out the various date parts 
//  :
yourMilliSecs = Number(yourDate.getMilliseconds()) ;

// _global.diffTimeCalc calculated in another function.
// Now calc calcGmtMilliSecs
calcGmtMilliSecs =  Math.floor(yourMilliSecs + diffTimeCalc);

// Now calculate GMT using calcGmtMilliSecs.
gmDateCalc = new Date(yourYear, yourMonth, yourDayNum, yourHours, yourMins, yourSecs, calcGmtMilliSecs); 	
	
// Extract the parts you need for the clock display
dspGmtTimeHour = Number(String(gmDateCalc).substring(11,13));
dspGmtTimeMin = Number(String(gmDateCalc).substring(14,16));
dspGmtTimeMonth =String(gmDateCalc).substring(4,7) ;
dspGmtTimeDayName = String(gmDateCalc).substring(0,3);
dspGmtTimeDay = Number(String(gmDateCalc).substring(8,10));
dspGmtTimeYear = Number(String(gmDateCalc).substring(29,33));	

// Populate the appropriate display boxes
localTimeBox.htmltext = yourHours + ":" + yourMins  + ":" + yourSecs  ; 	
gmtTimeBox.htmltext = dspGmtTimeHour+ ":" + dspGmtTimeMin + ":" +yourSecs  ;

/* There's a LOT more to it than just this, like calculating daylight savings time, start, end, if at all, etc. But you get the idea. */
}
 
I'm not sure what you mean by "out of sync", but if you actually send the query to the server every onEnterFrame that won't work as the response could take any length of time.

Kenneth Kawamoto
 
Kenneth,
When the file first loads, I set a variable (gmDateLoaded = 0) then query the server. If it successfully gets the date string, it sets gmDateLoaded = 1, gets an initial value for yourDate , calculates the time difference(calcGmtMilliSecs ), then loads the rest of the script. This is all sepeate from onEnterFrame.

onEnterFrame then uses the set variable "calcGmtMilliSecs" and the constantly updating values from "yourDate" to create a time display, which is where the "Out of sync" issue seems to be happening... but only for a few people.

an example is a screenshot they sent me showing Your Time = 5:20:15 pm and GMT = 7:20:15 pm Which is correct if you're in Sao Paulo, Brazil (which they are). But a few minutes later it shows Your Time = 5:22:52 pm and GMT = 7:20:52 pm. The seconds are in sync, but the minutes are not. But only in that location. That's why I was wondering if it could be a CPU speed issue.
 
The CPU speed will makes difference on the frequency of onEnterFrame, if any, so that's not the cause.

I'd calculate gmDateCalc this way:

[tt]gmDateCalc = new Date(yourDate.time + diffTimeCalc);[/tt]

Also to get the hour etc, I'd do this:

[tt]dspGmtTimeHour = gmDateCalc.getHours();[/tt]

But if you do not want any delays between two times, forget about server time etc (because the local machine clock can/will be off from server time), but just do:

[tt]dspGmtTimeHour = yourDate.getUTCHours();[/tt]

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top