-
Senior Member
Images/objects change based on time
I am trying to think through this tutorial that allows you to change an imgae based on time:
http://www.flashkit.com/tutorials/Ti...-788/index.php
and in particular this code:
onClipEvent (enterFrame) {
daynight = new Date();
dayframe = daynight.getHours()+1;
this.gotoAndStop(dayframe);
}
I'm not really understanding what's happening here. How would I modify this code if I wanted the object to appear for 8 hours, then dissapear for 16 hours?
My goal is to have 3 different objects that appear, each for 8 hours. For this solution, I would have to put the 3 different objects on 3 different layers, each with the proper code, right?
Thanks for the help.
-
newb of many sorts
Try this for your Timer
Wrote this out to be a little easier for you to read.. I think that last code you put down was a little incomplete.
Code:
onClipEvent (load) {
starttimer = getTimer()/1000;
this.onEnterFrame = function() {
totalTime = getTimer()/1000;
goTime = totalTime-starttimer;
_root.hours = Math.floor(goTime/3600);
_root.minutes = Math.floor(goTime/60);
_root.seconds = Math.floor(goTime);
_root.miliseconds = Math.floor(goTime*10);
};
}
Then for the images, just make sure they're objects and give them each their own coding. Something like..
Code:
onClipEvent (enterFrame) {
if ((_root.seconds >= 10) && (_root.seconds <=19)) {
setProperty(this, _alpha, 100);
} else {
setProperty(this, _alpha, 0);
}
}
in that example, i have it so that the object with this code appears when _root.seconds is 10 and then disapears when it hits 20. This script however, starts when the user enters the page and is not based on his or her home clock at all. I wasnt sure if you wanted the object to disapear at 8:00 o'clock or just 8 hours in general. This will work for the 8 hours one atleast.
also.. if you arent planning on using minutes, seconds, or miliseconds for anything then you can go ahead and delete those three lines... i just added those incase they would become useful.
Last edited by Ralgoth; 12-16-2002 at 01:17 PM.
-
Senior Member
Thanks for thehelp.
Actually, I'm looking for something that will be clock based as oppossed to when the user enters the page. There will be a three different images used, one of an early morning scene, one of a day time scene and another for an evening scene. So based on what time it is,the appropriate image would appear.
-
newb of many sorts
alright, ill have to get back to you on that one.. work calls.. tho, hopefully someone else will answer your question for you while im away.
-
Senior Member
Great, thanks for your help, I appreciate it. If you do come up with something later, I'd love to see it. I'm in no hurry at all. This is for a project a week or two away from beginning.
-
newb of many sorts
Okay.. i wanted to get this out before i headed to work.. so here you go..
Add this code to an object...
Code:
onClipEvent (enterFrame) {
myDate = new Date();
_root.Hour = myDate.getHours();
}
that will give you the hour of the clients computer that is viewing your page. now add this to your objects...
Code:
onClipEvent (enterFrame) {
if ((_root.Hour >= 8) && (_root.Hour <=16)) {
setProperty(this, _alpha, 100);
} else {
setProperty(this, _alpha, 0);
}
}
The 'Hour' variable is in military time. So if Hour = 8 then it is 8:00am and if Hour = 16 then it is 4:00pm which means the object i specified above will appear at 8am and disapear at 4pm. There ya go, hope that helps.
P.s. there is no 24th hour.. it is set as hour 0.. so the scale is from 0 to 23
-
Senior Member
Awesome, thanks a million!
-
newb of many sorts
not a problem.. glad i could help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|