A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: finding out the time

  1. #1
    junior master chef j_hunter182's Avatar
    Join Date
    Jun 2003
    Location
    Hull, East Yorkshire, UK
    Posts
    556

    finding out the time

    hello.
    on my site i think it would be nice if when you enter a quick "good morning" "good afternoon" or "good evening" message was displayed. how could i do this? is it possible?
    cheers
    jh

  2. #2
    Senior Member
    Join Date
    Feb 2004
    Location
    California
    Posts
    174
    it's very easy.

    just use this code:

    Code:
    myDate = new Date();
    trace(myDate.getHours());
    .getHours returns a number ranging from 0-23. then base your greeting on the hour.


  3. #3
    junior master chef j_hunter182's Avatar
    Join Date
    Jun 2003
    Location
    Hull, East Yorkshire, UK
    Posts
    556
    thanks for the quick reply. but still a few problems

    what do i add this code too?
    how do i get the right greeting for the right hour?

    sorry for my dumbness, bit im an animation man, not actionscript.
    cheers
    jh

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Let's say you make a movie that has 4 keyframes.

    The first one is invisible (has nothing).

    The second one says 'good morning'

    The third says 'good afternoon'

    The fourth says 'good evening'


    On the first frame of the movie, add a script that says:

    Code:
    var myDate = new Date();
    var hour = myDate.getHours();
    
    if (hour < 12) {
       this.gotoAndStop(2); // morning
    }
    else if (hour < 12+6) {
       this.gotoAndStop(3); // afternoon
    }
    else {
       this.gotoAndStop(4); // evening
    }
    If you'd like to animate those messages, then add more frames, and fix the frame numbers in this script to match. Also use 'gotoAndPlay' instead of 'gotoAndStop', and fix the sequences to stop at the end (add a 'stop();' on the last frame of each sequence).
    Last edited by jbum; 03-14-2004 at 10:31 PM.

  5. #5
    junior master chef j_hunter182's Avatar
    Join Date
    Jun 2003
    Location
    Hull, East Yorkshire, UK
    Posts
    556
    thats great thanks.
    i love you people

  6. #6
    Junior Member
    Join Date
    Apr 2006
    Posts
    1
    Quote Originally Posted by jbum
    Let's say you make a movie that has 4 keyframes.

    The first one is invisible (has nothing).

    The second one says 'good morning'

    The third says 'good afternoon'

    The fourth says 'good evening'


    On the first frame of the movie, add a script that says:

    Code:
    var myDate = new Date();
    var hour = myDate.getHours();
    
    if (hour < 12) {
       this.gotoAndStop(2); // morning
    }
    else if (hour < 12+6) {
       this.gotoAndStop(3); // afternoon
    }
    else {
       this.gotoAndStop(4); // evening
    }
    If you'd like to animate those messages, then add more frames, and fix the frame numbers in this script to match. Also use 'gotoAndPlay' instead of 'gotoAndStop', and fix the sequences to stop at the end (add a 'stop();' on the last frame of each sequence).
    Hi there!
    I'm also looking for a variation of this.
    Except instead of displaying a different frame ccording to the time of day, how would I display a different frame according to the day of week?

    Or rather, for a one week period, I would like to display a frame or scene each for Mon-Fri.
    Thanks!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center