Flash Need to load time from time server or host server

Discussion in 'Programming' started by happyharry, Feb 18, 2009.

  1. #1
    Hi,

    Ive made a flash clock, but it needs to be in GMT, not the time that is picked up from the visitors pc. Does anyone know of a tutorial etc, or have any idea of how to do this? The server is a php one ...

    Cheers in advance :D
     
    happyharry, Feb 18, 2009 IP
  2. higreg7

    higreg7 Peon

    Messages:
    469
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to use getUTCHours instead of getHours...same for Date, Minutes etc...look into flash help for the Date class ;-)
     
    higreg7, Feb 19, 2009 IP
  3. happyharry

    happyharry Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Any idea of a way to convert a string to a time and use it in a clock?

    I need to get the time from a php file and convert it to a time that can be used in this clock...

    Here is the working clock actionscript

    time=new Date(); // time object
    hours = time.getHours()
    minutes = time.getMinutes()
    seconds = time.getSeconds();
    
    seconds = seconds*6; // calculating seconds
    minutes = minutes*6; // calculating minutes
    hours = hours*30; // calculating hours
    
    sec._rotation=seconds; // giving rotation property
    min._rotation=minutes; // giving rotation property
    hour._rotation=hours; // giving rotation property
    
    Code (markup):
    Please help :S
     
    happyharry, Feb 19, 2009 IP
  4. higreg7

    higreg7 Peon

    Messages:
    469
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Why do you need to get the time from a php file? You said you need GMT time, GMT time is GMT time no matter where you get it from. Try this:

    time=new Date(); // time object
    hours = time.getUTCHours()
    minutes = time.getUTCMinutes()
    seconds = time.getUTCSeconds();

    seconds = seconds*6; // calculating seconds
    minutes = minutes*6; // calculating minutes
    hours = hours*30; // calculating hours

    sec._rotation=seconds; // giving rotation property
    min._rotation=minutes; // giving rotation property
    hour._rotation=hours; // giving rotation property
     
    higreg7, Feb 19, 2009 IP
  5. happyharry

    happyharry Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I dont want to collect the time from the clients pc, i want to collect it from the server, hence the php?

    Is this workable?
     
    happyharry, Feb 19, 2009 IP
  6. higreg7

    higreg7 Peon

    Messages:
    469
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    higreg7, Feb 19, 2009 IP
  7. happyharry

    happyharry Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks but...

    The only thing with that is - that if the client's pc is in gmt, and the time is wrong, so will the time on the clock. Is there a way to get it from a php file?
     
    happyharry, Feb 19, 2009 IP
  8. higreg7

    higreg7 Peon

    Messages:
    469
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    What do you mean if the client's pc is in GMT? When using getUTCDate, it will return universal time, not the client's PC time, even if the client's PC time is GMT, it should ignore the client's PC time wherever the client is.

    I'm not that good with php, but you would need to set up a loadVars in flash, and then load your php and parse whatever you need:

    http://livedocs.adobe.com/flash/8/m...htm?context=LiveDocs_Parts&file=00002329.html
     
    higreg7, Feb 19, 2009 IP
  9. starangel

    starangel Notable Member

    Messages:
    164
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    208
    #9
    flash runs on client side so you might need to hard-code the timezone and offset from the client's clock.
     
    starangel, Feb 19, 2009 IP
  10. happyharry

    happyharry Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Not at all possible to collect the time from a php file, parse string as a date then add it to the above function...

    Some thing like (for example)

    on (load) {
    loadText = new loadVars();
    loadText.load("getDate.php");
    loadText.onLoad = function(success) {
    if (success) {
    //trace(success);
    newsBox.text= this.myNews;
    }
    }
    }

    This would solve the issue that stargangel mentioned ?

    Thankyou all for all help by the way
     
    happyharry, Feb 19, 2009 IP
  11. higreg7

    higreg7 Peon

    Messages:
    469
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Ok, I don't understand what you are trying to do. Are you trying to get your clock to display GMT time, no matter where the user is? So that it displays GMT time, whether the user is in USA or Australia?

    Where are you based?

    Open a new flash document (AS2), and put this code in. Test your movie and tell me what you get:

    var today_date:Date = new Date();
    trace(today_date.getHours()); 
    trace(today_date.getUTCHours());
    Code (markup):
     
    higreg7, Feb 19, 2009 IP
  12. happyharry

    happyharry Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    OK.

    I need a clock that uses server time NOT client time, aka gets time from a php file on that server.

    Can anyone use the code posted earlier to convert the string collected from the php file into time?

    I dont want a clock that pulls time from the users pc.
     
    happyharry, Feb 19, 2009 IP
  13. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    PHP, file getDate.php:
    
    echo gmdate('D, d M Y__H:i:s');
    
    Code (markup):
    then in actionscript load up this url, and shove the returned contents into a var named 'dateTime:String';
    
    var dt:String = dateTime.split('__');
    var time:String = dt[1];
    var date:String = dt[0];
    
    var ts:String = time.split(':');
    var hours:String = time[0];
    var minutes:String = time[1];
    var seconds:String = time[2];
    
    
    Code (markup):
     
    rene7705, Feb 19, 2009 IP