Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-05-2011, 06:07 PM   #1
gotandDrink
Registered User
 
Join Date: Dec 2011
Posts: 5
Default 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.
gotandDrink is offline   Reply With Quote
Old 12-06-2011, 08:51 AM   #2
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

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");
sparX is offline   Reply With Quote
Old 12-06-2011, 07:30 PM   #3
sparX
!Senior Member
 
Join Date: Jan 2010
Posts: 1,675
Default

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);
sparX is offline   Reply With Quote
Old 12-08-2011, 06:43 AM   #4
gotandDrink
Registered User
 
Join Date: Dec 2011
Posts: 5
Default

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
gotandDrink is offline   Reply With Quote
Old 12-08-2011, 08:09 AM   #5
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,683
Send a message via Skype™ to henke37
Default

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.
henke37 is offline   Reply With Quote
Old 12-08-2011, 11:59 AM   #6
kattehus
Registered User
 
Join Date: Dec 2010
Location: Aarhus, Denmark
Posts: 39
Default

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.
kattehus is offline   Reply With Quote
Old 12-09-2011, 06:01 AM   #7
gotandDrink
Registered User
 
Join Date: Dec 2011
Posts: 5
Default

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.
gotandDrink is offline   Reply With Quote
Old 12-06-2011, 11:41 AM   #8
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,683
Send a message via Skype™ to henke37
Default

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.
henke37 is offline   Reply With Quote
Old 12-11-2011, 05:46 AM   #9
gotandDrink
Registered User
 
Join Date: Dec 2011
Posts: 5
Default

Anyone please help. Thanks!
gotandDrink is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:53 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.