12-05-2011, 06:07 PM
|
#1
|
|
Registered User
Join Date: Dec 2011
Posts: 5
|
Load movies at certain times of the day
Please help, im trying to do this in AS3? Is there any way to do this in AS3?. Thanks a lot.
myDate = new Date();
time = myDate.getHours();
if (time < 1) {
loadMovie("night.jpg","contentMC");
} else if (time < 2){
loadMovie("night.jpg","contentMC");
} else if (time < 3){
loadMovie("night.jpg","contentMC");
} else if (time < 4){
loadMovie("night.jpg","contentMC");
} else if (time < 5){
loadMovie("night.jpg","contentMC");
} else if (time < 6){
loadMovie("morning.jpg","contentMC");
} else if (time < 7){
loadMovie("morning.jpg","contentMC");
} else if (time < 8){
loadMovie("morning.jpg","contentMC");
} else if (time < 9){
loadMovie("morning.jpg","contentMC");
} else if (time < 10){
loadMovie("day.jpg","contentMC");
} else if (time < 11){
loadMovie("day.jpg","contentMC");
} else if (time < 12){
loadMovie("day.jpg","contentMC");
} else if (time < 13){
loadMovie("day.jpg","contentMC");
} else if (time < 14){
loadMovie("day.jpg","contentMC");
} else if (time < 15){
loadMovie("day.jpg","contentMC");
} else if (time < 16){
loadMovie("day.jpg","contentMC");
} else if (time < 17){
loadMovie("day.jpg","contentMC");
} else if (time < 18){
loadMovie("evening.jpg","contentMC");
} else if (time < 19){
loadMovie("evening.jpg","contentMC");
} else if (time < 20){
loadMovie("evening.jpg","contentMC");
} else if (time < 21){
loadMovie("evening.jpg","contentMC");
} else if (time < 22){
loadMovie("night.jpg","contentMC");
} else if (time < 23){
loadMovie("night.jpg","contentMC");
} else if (time < 24){
loadMovie("night.jpg","contentMC");
}
Last edited by gotandDrink; 12-05-2011 at 08:11 PM.
|
|
|
12-06-2011, 08:51 AM
|
#2
|
|
!Senior Member
Join Date: Jan 2010
Posts: 1,675
|
I'm not sure if AS3 will be able to handle it or not, it may be a bit much, but you can try,
ActionScript Code:
var hour:int = new Date().hours;
if (hour > 20 && hour < 5) loadMovie("night.jpg","contentMC");
else if (hour < 9) loadMovie("morning.jpg","contentMC");
else if (hour < 17) loadMovie("day.jpg","contentMC");
else loadMovie("evening.jpg","contentMC");
|
|
|
12-06-2011, 07:30 PM
|
#3
|
|
!Senior Member
Join Date: Jan 2010
Posts: 1,675
|
Ahhh ok, so 'loadMovie' was the AS2 thing...
Didn't notice it turned all brown & stuff when I posted,
thought it was a custom function...
So yeah, just use a Loader instead,
ActionScript Code:
var ldr:Loader = new Loader();
var time:String;
var hour:int = new Date().hours;
if (hour > 20 && hour < 5) time = "night";
else if (hour < 9) time = "morning";
else if (hour < 17) time = "day";
else time = "evening";
ldr.load(new URLRequest(time + ".jpg"));
contentMC.addChild(ldr);
|
|
|
12-08-2011, 06:43 AM
|
#4
|
|
Registered User
Join Date: Dec 2011
Posts: 5
|
Thanks SparX, but i dont understand how to know which hour is represented by numbers, what does the 20 && stand for? and what if i want it to load a different JPG each hour or half hour?
Thanks a lot
|
|
|
12-08-2011, 08:09 AM
|
#5
|
|
Senior Member
Join Date: Mar 2009
Location: Sweden
Posts: 9,773
|
Go and learn 24 hour time, everyone else is using it. And it is not hard at all.
__________________
Signature: I wrote a pair of articles about the timeline.
|
|
|
12-08-2011, 11:59 AM
|
#6
|
|
Registered User
Join Date: Dec 2010
Location: Aarhus, Denmark
Posts: 39
|
if(hour > 20 && hour < 5) means exactly that.
If the hour is greater than 20 (that's 8 pm) and less than 5 (am), then time = night.
if (hour > 20 && hour < 5) loadMovie("night.jpg","contentMC");
else if (hour < 9) loadMovie("morning.jpg","contentMC");
else if (hour < 17) loadMovie("day.jpg","contentMC");
else loadMovie("evening.jpg","contentMC");
If you want to load a different JPG for each hour, try using a switch instead:
ActionScript Code:
var hour:int = new Date().hours
switch (hour) {
case 1:
case 2:
case 3:
case 4:
trace("1-4");
break;
case 5:
case 6:
case 7:
case 8:
case 9:
trace("5-9");
break;
case 10:
trace("10");
break;
default:
trace("not 1-10");
break;
}
This will also remove a lot of your if/else sentences. Now, if you want to do something for each half hour, you will need to keep track of the minutes as well.
|
|
|
12-09-2011, 06:01 AM
|
#7
|
|
Registered User
Join Date: Dec 2011
Posts: 5
|
Thanks kattehus,
Im really bad on my transition from AS2. Do you think you can post me the whole code to load different JPG or SWF to a container every 30 mins? basically i need to do this action from 8am to 9pm daily. I really appreciate your help and time. Thanks a lot.
|
|
|
12-06-2011, 11:41 AM
|
#8
|
|
Senior Member
Join Date: Mar 2009
Location: Sweden
Posts: 9,773
|
Of course as 3 can do it, it is just loading a picture. Go and read up on the Loader class.
__________________
Signature: I wrote a pair of articles about the timeline.
|
|
|
12-11-2011, 05:46 AM
|
#9
|
|
Registered User
Join Date: Dec 2011
Posts: 5
|
Anyone please help. Thanks!
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Hybrid Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 09:10 AM.
///
|
|