Setting Frame in a Movieclip based on Time of day
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Setting Frame in a Movieclip based on Time of day

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    3

    Setting Frame in a Movieclip based on Time of day

    Hi there. I'm trying to do something that seems simple enough, but I'm a bit stuck. I'd like to run a function that is simply calling a gotoAndStop command within a movieclip when it reaches a certain time of day in EST. So for example, the movieclip would be on frame 1 until 2:30pm EST and then it would gotoAndStop frame 2 within movieclip, let's call the instance name of movieclip "matchup_mc" - I've tried a few things and no luck. Anyone wanna bail me out here?

    Here is the code I have so far - isn't quite working

    Code:
    var eventDate:Date = new Date();
     eventDate.setHours( 14, 30 );
     var now:Date = new Date();
    
     var delay:Number = eventDate.time - now.time;
    
     if( delay > 0 )//if we haven't yet passed 14:30
     {
       var timer:Timer = new Timer( delay , 1 );
       timer.addEventListener( TimerEvent.TIMER , changeTime );
       timer.start();
     }
    
    function changeTime():void{
    	matchup_mc.gotoAndStop("change");
    }

  2. #2
    Junior Member
    Join Date
    Jun 2013
    Posts
    3
    Here is another method I tried.. I know something is quite right.

    Code:
    var my_date:Date;
    
    var my_timer:Timer=new Timer(1000);
    my_timer.addEventListener(TimerEvent.TIMER, onTimer);
    my_timer.start();
    
    function onTimer(e:TimerEvent):void {
    	var eventDate:Date = new Date("Sun June 23 2013 14:30:00 PM");
    	if (my_date > eventDate){
    	changeTime();
    	} else if  (my_date < eventDate){
    		setTime();
    	}
    }
    
    function changeTime():void{
    	matchup_mc.gotoAndStop(15);
    	trace("hi I'm working");
    }
    
    function setTime():void{
    	matchup_mc.gotoAndStop(1);
    	trace("this is the beginning");
    }

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    3

    more tries

    Hm surprised no responses yet - Here is another method I'm trying - for some reason, regardless of the time - it always thinks it's "game time"

    Code:
    function getGameTime():void {
    var my_date:Date = new Date();
    var currentHour:Number = my_date.getHours() + my_date.getMinutes();
    	if (currentHour < 14) {
    		setTime();
    	trace("game is later");
    	}
    	else if (currentHour > 14) {
    		changeTime();
    	trace("game time!");
    	}
    }
    
    function setTime():void{
    	matchup_mc.gotoAndStop(1);
    	trace("game is later");
    }
    
    function changeTime():void{
    	matchup_mc.gotoAndStop(15);
    	trace("game time!");
    }
    help!

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,511
    Code:
    var my_date:Date = new Date();
    var currentHour:Number = my_date.getHours() + (my_date.getMinutes() / 60);
    trace(currentHour)

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

Poll by Flashkit.com