A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Timed event

  1. #1
    Junior Member
    Join Date
    May 2004
    Posts
    10

    Timed event

    need a script that will execute a event when ever it reaches the specifiec Day, & Time. However it is a reacuring event every week at the same time.

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    for web use or intranet use? if intranet, there're lots of options - if its for the web you're probably going to have to use a batch or NT's at command (if you're being served on a windows box; otherwise - i dunno if nix have something similiar but you could do it with php if there werent other options)...

    anyhow you're probably gonna have to use something else (the "at" command is like window's task scheduler for nt - and i guess .net now hmmm) to check the date/time whatever then have it reup the swf - i suppose you could call several million setIntervals or enterFrames and then use the Date class with conditionals to over and over to check what time it is.

    if you find something less retarded than enterFrame and less cumbersome than batching to ftp, i'd be interested in hearing about what you found

  3. #3
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Here's a sample script that does it. Read the documentation for both the Date() object, and setInterval() for help figuring it out.

    - Jim

    code:

    // A sample script to generate an event every thursday at 5:00 pm
    alarmDay = 4; // sunday is 0, monday is 1, etc.
    alarmHour = 17;
    alarmMinute = 0;

    // Some useful constants
    kMillisecondsInSecond = 1000;
    kMillisecondsInMinute = kMillisecondsInSecond*60;
    kMillisecondsInHour = kMillisecondsInMinute*60;
    kMillisecondsInDay = kMillisecondsInHour*24;

    myAlarmAction = function(alarmDay, alarmHour, alarmMinute)
    {
    clearInterval(alarmHandle);

    // Do whatever you want to do on thursday here...
    trace('brrrrring! brrrrrng!');

    mySetAlarm(alarmDay, alarmHour, alarmMinute); // set alarm for next week
    }

    mySetAlarm = function(alarmDay,alarmHour,alarmMinute)
    {
    // get current time
    var d = new Date();
    // get date of previous midnight
    var dm = new Date(d.getFullYear(), d.getMonth(), d.getDate()); // date of last midnight
    // convert it to milliseconds
    var ms = dm.getTime();
    // figure out how many days till day of alarm
    var day = dm.getDay();
    var dayD = (alarmDay+7 - day) % 7;
    // adjust milliseconds to time of alarm
    ms += dayD*kMillisecondsInDay;
    ms += alarmHour*kMillisecondsInHour;
    ms += alarmMinute*kMillisecondsInMinute;
    // new date object for time at which we want alarm to go off
    var df = new Date(ms);
    trace("Setting alarm for " + df);

    // Difference in milliseconds between alarm time and now
    var msDiff = df.getTime() - d.getTime();
    alarmHandle = setInterval(myAlarmAction, msDiff, alarmDay, alarmHour, alarmMinute);
    }

    mySetAlarm(alarmDay, alarmHour, alarmMinute);


    Last edited by jbum; 09-27-2004 at 05:38 PM.

  4. #4
    Junior Member
    Join Date
    May 2004
    Posts
    10

    Thank you

    thanks for the script that will do what i need it to do. I appreciate it.

  5. #5
    Junior Member
    Join Date
    May 2004
    Posts
    10

    Timmer hangs up

    I tested the timer out however everytime it gets to the set time it freezes and doesn't display the Brrrrrring Brrrrrring. Any ideas.

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    maybe copy/paste didn't work..
    see attachment.

    gparis
    Attached Files Attached Files

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