A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Using date to swap movie clip or images...

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2

    Using date to swap movie clip or images...

    I've looked through to see if I could find the answer to this and couldn't...please forgive me if it's already been addressed but how could I use the date to swap out a movie clip or image stored in the library?

    Thanks in advance,

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    What does your question mean?

    Do you mean use today's date to determine which library item to instantiate?

    If so, and you have two library items exported for actionscript with class names "ThingyA" and "ThingyB", you could do something like this:
    Code:
    var now:Date = new Date();
    var dayOfMonth:int = now.getDate();
    var thingy:DisplayObject;
    if (dayOfMonth % 2 == 0){
      thingy = new ThingyA();
    }else{
      thingy = new ThingyB();
    }
    addChild(thingy);
    This will put a ThingyA up on days of the month that are even, and a ThingyB up on days of the month which are odd.

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    5Tons, thanks for the quick response....sorry I was a bit vague.

    I have a file with a mc that shows a date and time of a program(e.g: "Starting Monday, Oct 24, 9/8c"). Once that date hits, I want it to change to another mc in my library that says "Sundays, 9/8c"....

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You can easily compare dates.
    Code:
    var deadline:Date = new Date(Date.parse("10/24/2010 20:00:00 GMT-0500"));
    var now:Date = new Date();
    
    if (now < deadline){
      //deadline not passed.
    }else{
      //deadline passed.
    }
    Ideally though, you'd pull the deadline from your object instead of hardcoding it.

    Edit: whoops. Parse apparently returns a Number. Gotta make that a Date.

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