A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: How To insert Day And Time In flash AS2?

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    1

    How To insert Day And Time In flash AS2?

    I want to display Day and time in flash with AS2
    not only that i want to put certain event on certain date and time
    that means
    i have a movie clip with object on it ,when i run it,
    it changes its position

    BUT now i want to change movie clip position on certain date and time

    for eg;
    I have made a simple move clip of firework i want it auto play when it is
    (01.01.2012) (12:00 AM)

    Help Me.....

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    are you trying to check a SERVER for a time? (universal, centralized time?)

    or the time on each users machine/computer?


    something like this:
    actionscript Code:
    var today_date:Date = new Date();
    var date_str:String = ((today_date.getMonth() + 1) + "." + today_date.getDate() + "." + today_date.getFullYear());
    trace(date_str);// displays current date in United States date format


    if (date_str == "1.1.12") {
        //play your fireowrk animation
    } else {
        //do nothing
    }

  3. #3
    Member
    Join Date
    Sep 2008
    Posts
    71
    How can you test to see if the date string is past a certain date?

    Ex) if it's past 1.1.12 then do something, else do nothing?

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    what?

    its in there...

    this part

    if (date_str == "1.1.12") {
    //play your firework animation
    } else {
    //do nothing
    }

  5. #5
    Member
    Join Date
    Sep 2008
    Posts
    71
    No I mean if the date is on or past a certain date.

  6. #6
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    its STILL THAT SECTION.

    compare any/all part of the date you want to.

    here..even easier then:

    actionscript Code:
    var todayDate:Date = new Date();
    var targetDate:Date = new Date(2012, 0, 1);

    if (targetDate.getTime() > todayDate.getTime()) {
        trace("TRUE");
    } else {
        trace("FALSE");
    }

  7. #7
    Member
    Join Date
    Sep 2008
    Posts
    71
    edit: see below.
    Last edited by programma; 04-23-2011 at 07:56 PM.

  8. #8
    Member
    Join Date
    Sep 2008
    Posts
    71
    Okay I need help..

    1) I want to make a var, todays date, and a var 7 days from today.

    Ok now after that, how do I do this:

    2) See if a self-defined date var is past or before todays date.

    I followed your code whispers and it worked halfway..

  9. #9
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    what didnt work?



    heres your #1: (your two vars)

    var todayDateate = new Date();
    var targetDateate = new Date(2012, 0, 1);



    Heres your #2: (checking before or after)

    if (targetDate.getTime() > todayDate.getTime()) {
    trace("TARGET DATE IS AFTER TODAYS DATE");
    } else {
    trace("TARGET DATE IS BEFORE TODAYS DATE");
    }

  10. #10
    Member
    Join Date
    Sep 2008
    Posts
    71
    and how would you add seven days to today's date in flash?

  11. #11
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    so you need 3 dates?

    you have your CURRENT DATE..

    and then another var for whatever date you want to compare against (targetDate)

    that is currently set to 1/1/12 (2012, 0, 1) above..

  12. #12
    Member
    Join Date
    Sep 2008
    Posts
    71
    how do I add seven days to the current date?

  13. #13
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    actionscript Code:
    var dayOffSet:Number = 7;
    var todaysDate:Date = new Date();
    trace("BEFORE DATE: "+todaysDate);
    todaysDate.setDate(todaysDate.getDate() + dayOffSet);
    trace("AFTER DATE: "+todaysDate);

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