2 Replies Latest reply on Sep 22, 2006 12:00 PM by at_play

    How compare time in 15 minute increments?

    at_play Level 1
      Using Flash 8 Pro AS2

      Have an animation that needs to play once at first visit to site, no matter how many pages visited within site. Then start over when come back to site.

      I thought SharedObject would work for this. I got it to run once at site visit and set the shared object. Problem is that the animation NEVER plays again because the shared object is never removed.

      If there was a way to set it so it was like a session then that would solve this easy. I don't know how to do this if there is a way.

      So I decided to have the swf check at page reload or if come back to site again, if 15 minutes has passed. If it has, update the time in shared object to current time and play the animation.

      Problem is I have NO idea how to compare the time set in the shared object with the current time to see if 15 minutes has passed or not.

      I tried different things but the comparision, at the top of the hour, goes into negative numbers. I was comparing minutes that passed between the saved time and the current time. Just minutes nothing else.

      I am not a math wiz or understand all the stuff I see out there in tutorials and code samples when it comes to date and time calculating.

      I need to either. Delete the shared object at browser closing or navigating away from site.
      Check if 15 minutes has passed then update the time in the shared object and play the animation

      I am just stuck at the time calculation to determine if 15 minutes passed or not.

      What happens if they dont come back to the site for days or weeks? My test of tracking minutes has no meaning when getting into hours and days let alone weeks or months. Obviously my approach does NOT work.

      Any help would be great. Remember Flash 8 pro and AS2 NOT AS3 or flash 9.

        • 1. Re: How compare time in 15 minute increments?
          I'm not sure how you're checking the time, but if you create a DATE object:

          var now:Date = new Date(); This is actually a date and time object.

          So, if you compare this date and Time object with a previous date and Time object using the Date method getTime() as follows

          now.getTime() - previousDate.getTime() = the number of milliseconds that have passed between the "previousDate" and "now." If the difference is > 15*60*1000, 15 minutes have passed.
          • 2. Re: How compare time in 15 minute increments?
            at_play Level 1
            That works.

            I did a hack job of a method that also works but yours is much more efficient.

            Basically I compared getMonth, getHour, getDate, getMinute in a bunch of if statements and checked if it was same day and same hour. If it was check minutes and compare current minute with saved minute. If it was past 15 minutes then restart the count.
            If it was different hour then reset the count
            if it was different day reset the count
            if it was different month reset the count

            It worked exactly the same, the end result that is but your method is a lot more compact and saves about 40 or so lines of AS which is great.

            Like i said mine is a large HACK that isn't too resource friendly but the swf isnt running constantly so isn't big deal really either way.

            I learned a hell of a lot testing both ways and I like yours better even though both get the same results. Just, differently.. LOL