The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 7 of 7

Thread: Loading different pictures based on time of day

  1. #1

    Loading different pictures based on time of day

    Hello again everyone. Here's the sit. I'm trying to load a different .gif file based upon the time of day. I figured what I wrote would work, but alas, I was wrong. Here's what I got:
    files=["sunrise.gif", "morning.gif", "midday.gif",
    	   "afternoon.gif", "twilight.gif", "night.gif"]
    var currentHour:Number = myDate.getHours();
    var currentMin:Number = myDate.getMinutes();
    var currentSec:Number = myDate.getSeconds();
    function pictureRotate(){
    	if ((currentHour>21)&(currentHour<6)){
    		loadMovie("night.gif", "_root.main");
    	}else if ((currentHour>6)&(currentHour<9)){
    		loadmovie("sunrise.gif", "_root.main");
    	}else if ((currentHour>9)&(currentHour<12)){
    		loadmovie("morning.gif", "_root.main");
    	}else if ((currentHour>12)&(currentHour<15)){
    		loadmovie("midday.gif", "_root.main");
    	}else if ((currentHour>15)&(currentHour<18)){
    		loadmovie("afternoon.gif", "_root.main");
    		loadmovie("twilight.gif", "_root.main");
    I know I can take out that first array, and I do believe I can take out the minutes and seconds, but I left the code as is, in case I screwed it all up. Oh and the pictures have no paths because I imported them into the actual .fla. Thanks for the help ahead of time!

  2. #2
    Flash can't handle dynamically loaded gif's and also you have to use the logical operator && instead.

  3. #3
    So if I use .jpegs it'll work? I thought that I was supposed to use && instead of & since I was checking 2 things. I'll check it out tomorrow and see what happens. Thanks for your quick response! Makes me feel loved.

  4. #4
    Yes, it will work with jpg's (must be NON progressive)

  5. #5

    still not working...

    Alright, well here's my revised code:
    var myDate:Date=new Date(); //edit put this in as well
    var currentHour:Number = myDate.getHours();
    function pictureRotate(){
    	if ((currentHour>21)&&(currentHour<6)){
    		loadMovie("night.jpg", "_root.main");
    	}else if ((currentHour>6)&&(currentHour<9)){
    		loadmovie("sunrise.jpg", "_root.main");
    	}else if ((currentHour>9)&&(currentHour<12)){
    		loadmovie("morning.jpg", "_root.main");
    	}else if ((currentHour>12)&&(currentHour<15)){
    		loadmovie("midday.jpg", "_root.main");
    	}else if ((currentHour>15)&&(currentHour<18)){
    		loadmovie("afternoon.jpg", "_root.main");
    		loadmovie("twilight.jpg", "_root.main");
    and then I added the command to actually load the friggin' function - since I forgot to do that - to the movie clip:
    onClipEvent(load) {
    	_parent.pictureRotate(); //edited this line to include the _parent
    but it still doesn't work. I made a movie clip with the name of main at a size of 800x300 which is the size of my movie. I gave it the instance name of main. I'm just not getting what I'm doing wrong here.
    Last edited by Pneumonic; April 17th, 2004 at 06:13 PM. Reason: 'cause I'm a lamer

  6. #6
    I've attached the fla since I really have no idea what I'm doing wrong. You can get it here . Thanks for any help in advance.
    this is my edit:
    Ok, so I know my mc doesn't have the instance name of main, so I changed that (although I didn't upload that version). So here's where I'm confused. I was looking at my code and thought, "Well, I wonder what number the variable currentHour is putting out. Maybe that has something to do with it." So I put in this command:
    and when I ran it, it came back "undefined". Why is this? I'm becoming more and more confused as the day goes on. Good thing I got a soccer game to go to tonight.
    Ok so I remembered that I hadn't passed the variable myDate so that's why the trace returned undefined, so I added this:
    var myDate:Date=new Date();
    and now I get the number 15 ('cause it's 3) when I run the trace, but my pictures still wont come up!
    Last edited by Pneumonic; April 17th, 2004 at 04:12 PM. Reason: remembered something!

  7. #7

    Got it working! (with some help from macromedia forums)

    Ok, so here's my final code. If you want to know what it all means, I'll comment it all out later, but right now, I got alot of stuff to do so I gotta jet:
    Put this in your frame 1 of your AS layer
    var myDate:Date=new Date();
    var currentHour:Number = myDate.getHours();
    var currentMin:Number = myDate.getMinutes();
    var myTime = currentHour+ "." +currentMin;
    var path = ""
    function pictureRotate(){
    	if ((myTime>=6.00)&&(myTime<=8.59)){
    		loadmovie(path+"sunrise.jpg", "_root.main");
    	}else if ((myTime>=9.00)&&(myTime<=11.59)){
    		loadmovie(path+"morning.jpg", "_root.main");
    	}else if ((myTime>=12.00)&&(myTime<=14.59)){
    		loadmovie(path+"midday.jpg", "_root.main");
    	}else if ((myTime>=15.00)&&(myTime<=17.59)){
    		loadmovie(path+"afternoon.jpg", "_root.main");
    	}else if ((myTime>=18.00)&&(myTime<=20.59)){
    		loadmovie(path+"twilight.jpg", "_root.main");
    	}else {
    		loadMovie(path+"night.jpg", "_root.main");
    Then put this on an EMPTY movieclip(ctrl+F8). Just name it empty_mc and put it on it's own layer so you don't confuse it.
    Then make a movie called main with an instance name of main and create a box that fills up the entire movie - or however big you want the pictures to be-(this should also be the size of your pictures) inside of it. And that's it! It works like a charm, and is a cool way to show you know what time of the day it is! If anyone actually uses this let me know, just so I know if I've been helpful or not!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012