Skip to main content
Known Participant
July 3, 2009
Question

triggering events with Date function (addEventListener)

  • July 3, 2009
  • 1 reply
  • 834 views

I am trying to figure out a way to be able to trigger an event which will display a message. The only thing is that the date function does not seem to be equipped with the ability to set events to it. I read the reference to it on the Flash support site and it seems as it is usually only used for date stuff.

I downloaded a digital clock, but it seems as that is based on diffrent principals as it was simply iterating throught the if stmts

var todayDate:Date = new Date();
var currentHours:Number = todayDate.getHours();
var currentMinutes:Number = todayDate.getMinutes();

//Looking to set a addEventListener when the current time reaches 15:30 and to fire off a public function showTime

//If it 10 minutes away from 15:30 play function almostThere()


public function showTime(event:Event):void
{
if ( (currentHours == 15) && (currentMinutes == 38))
{
    timeis_mc.text = currentHours + ":" + currentMinutes;
}
}

public function almostThere

{

}

Could someone assist me in analysis of this problem

Any suggestions

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 4, 2009

create a class that extends the Timer class

georgeebAuthor
Known Participant
July 4, 2009

and then how would you go about attaching a timer to a date method such as getHours()

since those methods return Numbers

can you elaborate

Thank you kindly

Best Regards

kglad
Community Expert
Community Expert
July 4, 2009

that doesn't make sense so you wouldn't do that.  i'm not sure you need to use the date class for this but if you needed it you would import the class into your timer extension.

the timer class, by itself is capable of dispatching an event after any given time:

package{

import everything you need

public class TimerDispatch extends Timer{

function TimerDispatch(t:uint){

var ti:Timer=new Timer(t,1);

ti.addEventListener(TimerEvent.TIMER,f);

ti.start();

}

private function f(e:TimerEvent){

this.dispatchEvent(new Event("timeExpired"));

}

}

}

so, wherever you have access to the TimerDispatch class:

var td:TimerDispatch=new TimerDispatch(90000);  // to dispatch an event after 90 seconds

td.addEventListener("timeExpired",timeExpiredF);

function timeExpiredF(e:Event){

//do whatever

}