3 Replies Latest reply on Aug 17, 2006 2:52 AM by blemmo

    creating a date selection

    complexity Level 1
      Hey all,

      I have a small mc that has 10 or so frames. On each frame I am displaying different content.

      I am atempting to create a kind of date selection peice of code that will check todays date and then for the playhead to go to the specific frame I have signaled in the AS.

      eg.
      newdate = Date();

      if newdate = (is between monday 14 & sunday 20)
      gotoAndStop("myframe")
      if newdate = (is between monday 21 & sunday 27)
      gotoAndStop("myframe2")
      etc

      my criteria is for a weekly selection, so every Monday morning at 00:00 hours it should go to the next frame(display the next frame) etc

      Any help with this would be great.
        • 1. Re: creating a date selection
          blemmo Level 1
          You're almost there with the pseudo code:

          var date:Date = new Date();
          var day:Number = date.getDate();
          if (day >= 14 && day <= 20){
          gotoAndStop(2);
          }
          if (day >= 21 && day <= 27){
          gotoAndStop(3);
          }

          hth,
          blemmo
          • 2. Re: creating a date selection
            complexity Level 1
            blemmo thanks for the help on this, I can see your code working for the current month, but how do we make it work for say an entire year.
            Add in another argument I guess?

            if august = currentmonth then{
            //your code
            }

            if september = if august = currentmonth then{
            // your for september
            }

            Something like this prehaps? Could you show me how you would do it. Im no programming expert..

            • 3. Re: creating a date selection
              blemmo Level 1
              If you have specific dates, you could go like this:

              var date:Date = new Date();
              var day:Number = date.getDate();
              var month:Number = date.getMonth(); // months start at 0 (january)
              switch (month){
              case 7: // august
              if (day >= 14 && day <= 20){
              gotoAndStop(2);
              }
              if (day >= 21 && day <= 27){
              gotoAndStop(3);
              }
              break;
              case 8: // september
              // ...
              break;
              }

              You'll need a case statement for every month and inside that, have the code for the days.
              If you want to change weekly, you could also calculate which week it is, and switch that value. This should be little less writing:

              /*** returns passed days and weeks and sets a day to change something based on weekcount ***/
              DAY = 1; // 0=sunday...6=saturday
              //today
              var now:Date = new Date();
              //january 1st
              var january:Date = new Date(now.getFullYear(), 0, 1, 0, 0, 0, 0);
              //get milliseconds since 1970 for today and for january 1st of the same year
              now_ms = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds());
              january_ms = Date.UTC(now.getFullYear(), 0, 1, 0, 0, 0, 0);
              //1000*60*60*24 ms == 1 day, +1 to show actual day
              days = Math.floor((now_ms-january_ms)/86400000)+1;
              //set the weekday to change mcs
              days += 6-DAY+january.getDay();
              weeks = Math.floor(days/7);
              trace("days :"+days+" | week :"+weeks);

              switch (weeks){
              case 12:
              // actions for week 12
              break;
              case 13:
              // actions for week 13
              break;
              //...
              }

              cheers,
              blemmo