Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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:
    Code:
    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");
    	}else{
    		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!
    -Pneumonic
    ------------------------------------------
    "I eat pogey bait for breakfast!"

  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.
    -Pneumonic
    ------------------------------------------
    "I eat pogey bait for breakfast!"

  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:
    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");
    	}else{
    		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:
    Code:
    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
    -Pneumonic
    ------------------------------------------
    "I eat pogey bait for breakfast!"

  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:
    Code:
    trace(currentHour);
    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:
    Code:
    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!
    -Pneumonic
    ------------------------------------------
    "I eat pogey bait for breakfast!"

  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
    Code:
    var myDate:Date=new Date();
    var currentHour:Number = myDate.getHours();
    var currentMin:Number = myDate.getMinutes();
    var myTime = currentHour+ "." +currentMin;
    var path = "http://www.21bluefish.com/media_in_progress/"
    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.
    Code:
    onClipEvent(load){
    _parent.pictureRotate();
    }
    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!
    -Pneumonic
    ------------------------------------------
    "I eat pogey bait for breakfast!"

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 kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012