1 2 Previous Next 47 Replies Latest reply on Nov 22, 2010 8:38 AM by Ron Colmen

    set a time?

    Ron Colmen Level 2

      How can I set a time here?

       

       

      eventDateA = ( 2010, 10, 16 [, 20 [, 20 [, 20 [, 200]]]])

      eventMillisecs = eventDateA.getTime();

      countdown = function(){

      var currentMillisecs = server.time + getTimer();

      this.msecs = eventMillisecs - currentMillisecs;

       

      this.secs = Math.floor(this.msecs/1000);

      this.mins = Math.floor(this.secs/60);

      this.hours = Math.floor(this.mins/60);

      this.days = Math.floor(this.hours/24);

       

      this.msecs = string(this.msecs % 1000);

      this.secs = string(this.secs % 60);

      this.mins = string(this.mins % 60);

      this.hours = string(this.hours % 24);

      this.days = string(this.days);

       

      while (this.msecs.length < 3) this.msecs = "0" + this.msecs;

      if (this.secs.length < 2) this.secs = "0" + this.secs;

      if (this.mins.length < 2) this.mins = "0" + this.mins;

      if (this.hours.length < 2) this.hours = "0" + this.hours;

      while (this.days.length < 3) this.days = "0" + this.days;

       

      for(movie in this){

      if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this);

      }

      };

       

      MovieClip.prototype.evaluateFrameFrom = function(variableClip){

      var nameArray = this._name.split("_");

      var numberSet = variableClip[nameArray[0]];

      var character = number(nameArray[1]);

      var frame = 1 + number(numberSet.charAt(character));

      if (this._currentframe != frame) this.gotoAndStop(frame);

      };

      server = new LoadVars();

      server.onLoad = function(ok){

      if (!ok) return trace("Error getting the date from server");

      counter.onEnterFrame = countdown;

      counter._visible = true;

      this.time = Number(this.time)*1000 - getTimer();

      };

      server.load("/thetime.php");  //php works fine

      counter._visible = false;

        • 1. Re: set a time?
          kglad Adobe Community Professional & MVP

          use the date class:

           

           

           

          var d:Date=new Date(2010,10,16,20,20,20,200);

          var eventMillisecs:Number = d.getTime();

           

          var serverDateTime:Date=new Date();

          • 2. Re: set a time?
            Ron Colmen Level 2

            Thanks Kglad!

            • 3. Re: set a time?
              kglad Adobe Community Professional & MVP

              you're welcome.

              • 4. Re: set a time?
                Ron Colmen Level 2

                I'm using php to set a default timezone, but it seems that the swf is calculating the countdown time using the the local time.

                How can I fix it so everything is calculated using the time pulled by the php?

                • 5. Re: set a time?
                  kglad Adobe Community Professional & MVP

                  you should load the time string (from php) using the loadvars class and use that to create a date instance in flash.

                  • 6. Re: set a time?
                    Ron Colmen Level 2

                    I guess this is what you are reffering. But doesn't work.

                     

                    server = new LoadVars();

                    server.onLoad = function(ok){

                    if (!ok) return trace("Error getting the date from server");

                    counter.onEnterFrame = countdown;

                    counter._visible = true;

                    this.time = Number(this.time)*1000 - getTimer();

                    };

                    server.load("/thetime.php");  //php works fine

                    • 7. Re: set a time?
                      kglad Adobe Community Professional & MVP

                      1.  whatever you get from your php is going to be a string.


                      2.  use the trace() function to see what you're getting from your php.

                      • 8. Re: set a time?
                        Ron Colmen Level 2

                        when i did

                        trace (server.load("/thephp.php"));

                        the output was "true"

                         

                        When I checked the php file on the browser it showed

                        time=1289932221

                        • 9. Re: set a time?
                          kglad Adobe Community Professional & MVP

                          you would use:

                           


                           

                          server = new LoadVars();

                          server.onLoad = function(ok){

                          if (!ok) return trace("Error getting the date from server");

                          counter.onEnterFrame = countdown;

                          counter._visible = true;

                          trace(this.time);

                          // and if you get a number that looks like millseconds, you probably don't want to muliply by 1000

                          this.time = Number(this.time)*1000 - getTimer();

                          };

                          server.load("/thetime.php");  //php works fine

                          • 10. Re: set a time?
                            Ron Colmen Level 2

                            ok. the trace shows miliseconds.

                             

                            But still there is the time difference (though the php sends the time form the timezone which I want the countdown clock calculates using the local time).

                            • 11. Re: set a time?
                              kglad Adobe Community Professional & MVP

                              where's the code that shows what you're doing with this.time after that data loads?

                              1 person found this helpful
                              • 12. Re: set a time?
                                Ron Colmen Level 2

                                (Thanks Kglad).... That's the full code and the below line should offset the recieved server time by the current value of getTimer.

                                 

                                this.time = Number(this.time) - getTimer();

                                 

                                If this is wrong please show me how this.time should be included for the calculation.

                                • 13. Re: set a time?
                                  kglad Adobe Community Professional & MVP

                                  1.  i'm not sure what this.time really is but i assume it's  time()*1000.  is that correct?

                                   

                                  2.  using an offset of getTimer() makes no sense in any scenario i can think of.

                                   

                                  3.  you're not using this.time for anything

                                   

                                   

                                  so, in addition, to answering 1 (or, even better, show your php), what are you trying to do?

                                  • 14. Re: set a time?
                                    Ron Colmen Level 2

                                    1. Yes - correct. (in my swf it's  this.time = Number(this.time)*1000 - getTimer();)

                                     

                                    <?php

                                    date_default_timezone_set("Pacific/Fakaofo");

                                    echo "time=" . time();

                                    ?>

                                    • 15. Re: set a time?
                                      kglad Adobe Community Professional & MVP

                                      ok, so 1. is correct.

                                       

                                      2. and 3.?

                                      • 16. Re: set a time?
                                        Ron Colmen Level 2

                                        2. this.time = Number(this.time)*1000 - getTimer();

                                        Offset the recieved server time by the current value of getTimer since getTimer starts at 0 when the swf starts.  By the time the server time loads, getTimer will be some higher value. This accounts for the extra time added on from getTimer in countdown every frame.

                                         

                                        3. Yes, you are correct. Can you show me how?

                                        • 17. Re: set a time?
                                          kglad Adobe Community Professional & MVP

                                          are you trying to show the date/time in whatever timezone that your app starts/?  if so, create a date instance using this.time and do something with it:

                                           

                                           

                                          var serverDateTime:Date=new Date(this.time);

                                          • 18. Re: set a time?
                                            Ron Colmen Level 2

                                            Hey Kglad... I'm a bit stuck in this... Could you please help to get it fixed?

                                             

                                            var d:Date=new Date(2010,10,18,10,20,0,0);

                                            var eventMillisecs:Number = d.getTime();

                                             

                                            var serverDateTime:Date=new Date(this.time);

                                             

                                            countdown = function(){

                                            var currentMillisecs = erverDateTime + getTimer();

                                            this.msecs = eventMillisecs - currentMillisecs;

                                            • 19. Re: set a time?
                                              kglad Adobe Community Professional & MVP

                                              what is countdown() supposed to do?


                                              • 20. Re: set a time?
                                                Ron Colmen Level 2

                                                Nothing at the moment, but I will do something like this in the countdown(),

                                                 

                                                if (this.msecs <= 0){

                                                play();

                                                }

                                                • 21. Re: set a time?
                                                  kglad Adobe Community Professional & MVP

                                                  use:

                                                   

                                                  var d:Date=new Date(2010,10,16,20,20,20,200);

                                                  var eventMillisecs:Number = d.getTime();

                                                   

                                                  server = new LoadVars();

                                                   

                                                  server.onLoad = function(ok){

                                                  if (!ok) return trace("Error getting the date from server");

                                                  counter.onEnterFrame = countdown;

                                                  counter._visible = true;

                                                  this.time = Number(this.time)*1000;

                                                  }

                                                  server.load("/thetime.php");

                                                   

                                                   

                                                   

                                                  function countdown():Void{

                                                  var n:Number = server.time-eventMillisecs-getTimer();  // this may already be a negative number

                                                  if (n <= 0){

                                                  some_mc.play();

                                                  delete counter.onEnterFrame;

                                                  }

                                                  }

                                                  • 22. Re: set a time?
                                                    Ron Colmen Level 2

                                                    Hey Kglad - Thanks.

                                                     

                                                    But the only change is in the 'n' (msecs) and what is the difference between the new code and the existing code?

                                                     

                                                    Existing code

                                                    var currentMillisecs = server.time + getTimer();

                                                    this.msecs = eventMillisecs - currentMillisecs;

                                                     

                                                    new code

                                                    this.msecs = server.time-eventMillisecs;

                                                     

                                                    I replaced "n" with msecs so my other functions work. But not working as yet?

                                                     

                                                    • 23. Re: set a time?
                                                      kglad Adobe Community Professional & MVP

                                                      that's not the only change.  the major change is using server.time in that context.

                                                       

                                                      anyway, use the trace() function to see what you're doing.  like i mentioned, depending on what's returned from your server, n may start as negative.

                                                      • 24. Re: set a time?
                                                        Ron Colmen Level 2

                                                        exactly...

                                                         

                                                        trace(n) is negative. What does this mean? What should be done to make the countdown work?

                                                        • 25. Re: set a time?
                                                          kglad Adobe Community Professional & MVP

                                                          it means your date instance, using Nov 16, 2010, occurs after the date returned by your php file.  i don't really know if you want to mean to use Oct 16 (months are zero-based in flash) or your php file is returning something different from what you want or you just want to use:

                                                           

                                                          var n:Number = eventMillisecs-server.time-getTimer();

                                                          1 person found this helpful
                                                          • 26. Re: set a time?
                                                            Ron Colmen Level 2

                                                            The month should be -1 from the current month?

                                                             

                                                            In this instance

                                                            var d:Date=new Date(2010,10,16,20,20,20,200);

                                                             

                                                            16 Nov 2010 8:20pm

                                                             

                                                            anyway, I changed it to var d:Date=new Date(2010,12,18,9,0,0,200); and still i get negative for the trace results.

                                                            • 27. Re: set a time?
                                                              Ron Colmen Level 2

                                                              Oops! I guess you updated your post while I was typing a reply. let me try.

                                                              • 28. Re: set a time?
                                                                kglad Adobe Community Professional & MVP

                                                                if you want to use oct 16, use:

                                                                 

                                                                var d:Date=new Date(2010,9,16,20,20,20,200);

                                                                • 29. Re: set a time?
                                                                  Ron Colmen Level 2

                                                                  I guess the time is okay. But my numbers (countdown clock) doesn't work now!

                                                                   

                                                                   

                                                                  var d:Date=new Date(2010,11,18,9,0,0,200);

                                                                  var eventMillisecs:Number = d.getTime();

                                                                   

                                                                  server = new LoadVars();

                                                                  server.onLoad = function(ok){

                                                                  if (!ok) return trace("Error getting the date from server");

                                                                  counter.onEnterFrame = countdown;

                                                                  counter._visible = true;

                                                                  this.time = Number(this.time)*1000;

                                                                  };

                                                                  server.load("/gettime.php");

                                                                  counter._visible = false;

                                                                   

                                                                  function countdown():Void{

                                                                  var msecs:Number = eventMillisecs-server.time-getTimer();

                                                                   

                                                                  this.secs = Math.floor(this.msecs/1000);

                                                                  this.mins = Math.floor(this.secs/60);

                                                                  this.hours = Math.floor(this.mins/60);

                                                                  this.days = Math.floor(this.hours/24);

                                                                   

                                                                  this.msecs = string(this.msecs % 1000);

                                                                  this.secs = string(this.secs % 60);

                                                                  this.mins = string(this.mins % 60);

                                                                  this.hours = string(this.hours % 24);

                                                                  this.days = string(this.days);

                                                                   

                                                                  while (this.msecs.length < 3) this.msecs = "0" + this.msecs;

                                                                  if (this.secs.length < 2) this.secs = "0" + this.secs;

                                                                  if (this.mins.length < 2) this.mins = "0" + this.mins;

                                                                  if (this.hours.length < 2) this.hours = "0" + this.hours;

                                                                  while (this.days.length < 3) this.days = "0" + this.days;

                                                                   

                                                                  for(movie in this){

                                                                  if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this);

                                                                  }

                                                                  };

                                                                   

                                                                  MovieClip.prototype.evaluateFrameFrom = function(variableClip){

                                                                  var nameArray = this._name.split("_");

                                                                  var numberSet = variableClip[nameArray[0]];

                                                                  var character = number(nameArray[1]);

                                                                  var frame = 1 + number(numberSet.charAt(character));

                                                                  if (this._currentframe != frame) this.gotoAndStop(frame);

                                                                  };

                                                                  • 30. Re: set a time?
                                                                    kglad Adobe Community Professional & MVP

                                                                    remove that garbage at the end:

                                                                     

                                                                    /////

                                                                    for(movie in this){

                                                                    if (this[movie]._parent == this) this[movie].evaluateFrameFrom(this);

                                                                    }

                                                                    };

                                                                     

                                                                    MovieClip.prototype.evaluateFrameFrom = function(variableClip){

                                                                    var nameArray = this._name.split("_");

                                                                    var numberSet = variableClip[nameArray[0]];

                                                                    var character = number(nameArray[1]);

                                                                    var frame = 1 + number(numberSet.charAt(character));

                                                                    if (this._currentframe != frame) this.gotoAndStop(frame);

                                                                    };

                                                                    //////

                                                                     

                                                                    and use your enterframe loop.

                                                                    • 31. Re: set a time?
                                                                      Ron Colmen Level 2

                                                                      could not achieve it!!

                                                                       

                                                                      Please help.

                                                                      • 32. Re: set a time?
                                                                        kglad Adobe Community Professional & MVP

                                                                        show your corrected code.


                                                                        • 33. Re: set a time?
                                                                          Ron Colmen Level 2

                                                                          Sorry Kglad. I've got nothing to show - I'm not sure how to go about it.

                                                                          • 34. Re: set a time?
                                                                            kglad Adobe Community Professional & MVP

                                                                            what's the following show:

                                                                             

                                                                             

                                                                            var d:Date = new Date(2010, 10, 16, 20, 20, 20, 200);
                                                                            var eventMillisecs:Number = d.getTime();

                                                                             

                                                                            server = new LoadVars();
                                                                            server.onLoad = function(ok) {
                                                                                if (!ok) {
                                                                                    return trace("Error getting the date from server");
                                                                                }
                                                                                counter.onEnterFrame = countdown;
                                                                                counter._visible = true;
                                                                                this.time = Number(this.time)*1000;
                                                                            };
                                                                            server.load("/thetime.php");

                                                                             

                                                                            function countdown():Void {
                                                                                var n:Number = eventMillisecs-server.time-getTimer();// this may already be a negative number
                                                                                if(n%100==0){
                                                                                trace(n);
                                                                                }
                                                                                if (n<=0) {
                                                                                    some_mc.play();
                                                                                    delete counter.onEnterFrame;
                                                                                }
                                                                            }

                                                                            • 35. Re: set a time?
                                                                              Ron Colmen Level 2

                                                                              with the date set to var d:Date = new Date(2010, 10, 16, 20, 20, 20, 200);

                                                                              trace = nothing

                                                                               

                                                                              When the date was changed to var d:Date = new Date(2010, 11, 16, 20, 20, 20, 200);

                                                                              trace = gave a 10 digit sum and it kept on repeating the same number.

                                                                               

                                                                              As far as the numbers (images), it kept on changing in a strange way.

                                                                               

                                                                              p.s. I appreciate your help.

                                                                              • 36. Re: set a time?
                                                                                kglad Adobe Community Professional & MVP

                                                                                what's the following show.  (shut it down after a few seconds of trace output).:

                                                                                 

                                                                                var d:Date = new Date(2010, 10, 16, 20, 20, 20, 200);
                                                                                var eventMillisecs:Number = d.getTime();

                                                                                 

                                                                                server = new LoadVars();
                                                                                server.onLoad = function(ok) {
                                                                                    if (!ok) {
                                                                                        return trace("Error getting the date from server");
                                                                                    }
                                                                                    counter.onEnterFrame = countdown;
                                                                                    counter._visible = true;
                                                                                    this.time = Number(this.time)*1000;
                                                                                };
                                                                                server.load("/thetime.php");

                                                                                 

                                                                                function countdown():Void {
                                                                                    var n:Number = eventMillisecs-server.time-getTimer();

                                                                                 

                                                                                    trace(n+" : "+eventMillisecs+" : "+server.time+" : "+getTimer());

                                                                                 

                                                                                    if (n<=0) {
                                                                                        some_mc.play();
                                                                                        delete counter.onEnterFrame;
                                                                                    }
                                                                                }

                                                                                • 37. Re: set a time?
                                                                                  Ron Colmen Level 2

                                                                                  -9 digits : 13digits : 13 digits : 4 digits (first one was minus)

                                                                                   

                                                                                  And the countdown (number images) did not work correctly.

                                                                                  • 38. Re: set a time?
                                                                                    kglad Adobe Community Professional & MVP

                                                                                    copy and paste the first few seconds of output.

                                                                                    • 39. Re: set a time?
                                                                                      Ron Colmen Level 2

                                                                                      with var d:Date = new Date(2010, 11, 16, 20, 20, 20, 200);

                                                                                       

                                                                                      2379941183 : 1292511020200 : 1290131067000 : 12017

                                                                                      2379941096 : 1292511020200 : 1290131067000 : 12104

                                                                                      2379941015 : 1292511020200 : 1290131067000 : 12185

                                                                                      2379940927 : 1292511020200 : 1290131067000 : 12273

                                                                                      2379940847 : 1292511020200 : 1290131067000 : 12353

                                                                                      2379940759 : 1292511020200 : 1290131067000 : 12441

                                                                                      2379940679 : 1292511020200 : 1290131067000 : 12521

                                                                                      2379940599 : 1292511020200 : 1290131067000 : 12601

                                                                                      2379940511 : 1292511020200 : 1290131067000 : 12689

                                                                                      2379940431 : 1292511020200 : 1290131067000 : 12769

                                                                                       

                                                                                      1 2 Previous Next