Groups | Blog | Home
all groups > flash actionscript > october 2006 >

flash actionscript : Count Down Time Zone?


SMB
10/22/2006 1:14:47 PM

[quoted text, click to view]


To let you be the one to further experiment I will point you in the right
direction.

http://www.adobe.com/livedocs/flashlite/2/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000468.html

Use GMT as your main reference for everyone, then offeset that time to your
timezone.

SMB
10/22/2006 6:07:15 PM

[quoted text, click to view]

Alrighty then....

My code uses a text box instead of your movie clips... but you should get
the idea.


Just stick all of this code in an empty frame of a new movie.




var hoursDifference:Number = 10;

stop();

currentDate = new Date();
thisYear = currentDate.getFullYear();

// Date( year, month-1, date [, hour [, minute [, second [,
millisecond]]]])
eventDate = new Date(thisYear, 9, 28, 12);
eventMillisecs = eventDate.getTime();

var counter:TextField = this.createTextField("timeRemaining_txt", 1, 50,
50, 200, 20);
counter.text = "TEST";
var now = new Date();
var diffFromGMT = now.getTimezoneOffset();
trace("Diff: " + diffFromGMT);
var myTimezoneOffset:Number = hoursDifference * 60;
trace(myTimezoneOffset);

this.onEnterFrame = function(){
currentDate = new Date();
currentMillisecs = currentDate.getTime();
trace("inside diff = " + (diffFromGMT - myTimezoneOffset));
currentMillisecs -= (diffFromGMT - myTimezoneOffset) * 60000;
this.msecs = eventMillisecs - currentMillisecs;
if (this.msecs <= 0){
play();
return;
}
this.secs = Math.floor(this.msecs/1000);
this.mins = Math.floor(this.secs/60);
this.hours = Math.floor(this.mins/60);
this.days = Math.floor(this.hours/24);
this.msecs = string(this.msecs % 1000);
this.secs = string(this.secs % 60);
this.mins = string(this.mins % 60);
this.hours = string(this.hours % 24);
this.days = string(this.days);

while (this.msecs.length < 3) this.msecs = "0" + this.msecs;
if (this.secs.length < 2) this.secs = "0" + this.secs;
if (this.mins.length < 2) this.mins = "0" + this.mins;
if (this.hours.length < 2) this.hours = "0" + this.hours;
while (this.days.length < 3) this.days = "0" + this.days;

counter.text = this.days + "D " + this.hours + "H " +
this.mins + "M " + this.secs + "S " + this.msecs + "ms";
// for(movie in this){
//if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this);
//}
};

/*
MovieClip.prototype.evaluateFrameFrom = function(variableClip){
var nameArray = this._name.split("_");
var numberSet = variableClip[nameArray[0]];
var character = number(nameArray[1]);
var frame = 1 + number(numberSet.charAt(character));
if (this._currentframe != frame) this.gotoAndStop(frame);
};
*/

SMB
10/22/2006 6:16:50 PM
I meant to include a comment for the first line

var hoursDifference:Number = 10;
// express your number of hours different from GMT.
// Although you need to use the opposite sign of the difference
// so, for the example above it would be for Hawaii.


Pitchsole
10/22/2006 8:05:12 PM
Hey all, i have come to this fourm a few times and every time i posted help i
got it and i got the right help to. So here i am back again. Now here my
problem. i made this count down for a certain event. (yes i got help from
someone) and it works fine i made all the images it works great,,,so i though
then i thought id experament. So i changed my computers time zone and guess
what. The Time changed on the count down. Can i make my count down'er', count
down from a specific time zone so it will count down and be the same for
everyone? so no matter what time zone you have it will ONLY be for a certain
type of time zone? Heres my Count down so far;

http://snro.ifastnet.com/wipe.html

And heres the script i have for my count down. Can someone give me a better
code, so it will keep my counter the exact same just make it count down from
only 1 specific Time zone? (AS below)

[Q]stop();

currentDate = new Date();
thisYear = currentDate.getFullYear();

// Date( year, month-1, date [, hour [, minute [, second [, millisecond]]]])
eventDate = new Date(thisYear, 9, 28, 12);
eventMillisecs = eventDate.getTime();

counter.onEnterFrame = function(){
currentDate = new Date();
currentMillisecs = currentDate.getTime();
this.msecs = eventMillisecs - currentMillisecs;
if (this.msecs <= 0){
play();
return;
}
this.secs = Math.floor(this.msecs/1000);
this.mins = Math.floor(this.secs/60);
this.hours = Math.floor(this.mins/60);
this.days = Math.floor(this.hours/24);
this.msecs = string(this.msecs % 1000);
this.secs = string(this.secs % 60);
this.mins = string(this.mins % 60);
this.hours = string(this.hours % 24);
this.days = string(this.days);

while (this.msecs.length < 3) this.msecs = "0" + this.msecs;
if (this.secs.length < 2) this.secs = "0" + this.secs;
if (this.mins.length < 2) this.mins = "0" + this.mins;
if (this.hours.length < 2) this.hours = "0" + this.hours;
while (this.days.length < 3) this.days = "0" + this.days;

for(movie in this){
if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this);
}
};

MovieClip.prototype.evaluateFrameFrom = function(variableClip){
var nameArray = this._name.split("_");
var numberSet = variableClip[nameArray[0]];
var character = number(nameArray[1]);
var frame = 1 + number(numberSet.charAt(character));
if (this._currentframe != frame) this.gotoAndStop(frame);
};[/Q]

Thanks!
Pitchsole
10/22/2006 8:48:00 PM
I am confused, i am not good when it comes to AS, as i said some one helped me. Could you tell me wat to do? or wat to put in? or give me a updated script?

SMB
10/23/2006 9:33:03 AM
Well, I was hoping you could take my example and look at it to figure it
out... but here you go:

** Just add the lines with the + signs. Then change to hoursDifference to
your negative timezone offset. So, 10 is for Hawaii.

+ var hoursDifference:Number = 10;
+ var now = new Date();
+ var diffFromGMT = now.getTimezoneOffset();
+ var myTimezoneOffset:Number = hoursDifference * 60;

currentDate = new Date();
thisYear = currentDate.getFullYear();

// Date( year, month-1, date [, hour [, minute [, second [,
millisecond]]]])
eventDate = new Date(thisYear, 9, 28, 12);
eventMillisecs = eventDate.getTime();

counter.onEnterFrame = function(){
currentDate = new Date();
currentMillisecs = currentDate.getTime();
+ currentMillisecs -= (diffFromGMT - myTimezoneOffset) * 60000;
this.msecs = eventMillisecs - currentMillisecs;
if (this.msecs <= 0){
play();
return;
}
this.secs = Math.floor(this.msecs/1000);
this.mins = Math.floor(this.secs/60);
this.hours = Math.floor(this.mins/60);
this.days = Math.floor(this.hours/24);
this.msecs = string(this.msecs % 1000);
this.secs = string(this.secs % 60);
this.mins = string(this.mins % 60);
this.hours = string(this.hours % 24);
this.days = string(this.days);

while (this.msecs.length < 3) this.msecs = "0" + this.msecs;
if (this.secs.length < 2) this.secs = "0" + this.secs;
if (this.mins.length < 2) this.mins = "0" + this.mins;
if (this.hours.length < 2) this.hours = "0" + this.hours;
while (this.days.length < 3) this.days = "0" + this.days;

for(movie in this){
if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this);
}
};

MovieClip.prototype.evaluateFrameFrom = function(variableClip){
var nameArray = this._name.split("_");
var numberSet = variableClip[nameArray[0]];
var character = number(nameArray[1]);
var frame = 1 + number(numberSet.charAt(character));
if (this._currentframe != frame) this.gotoAndStop(frame);
};

Pitchsole
10/23/2006 12:23:02 PM
Well umm..i kinda get it but i do not know wha to replace or wat to take away
or wat to add. Couldnt i just add var hoursDifference:Number = 10; and the
beggining of my script? or would i have to change the entire thing?
Pitchsole
10/23/2006 8:03:31 PM
AddThis Social Bookmark Button