Flex and the webcam pt4

Ok now we are going to add a to the application so that we can take pictures every n seconds.

first we add the import statement to add the timer class and the global timer object


import flash.utils.Timer;
public var myTimer:Timer;

And we need to add two buttons to the interface, one to start the process and one to stop it. The buttons have respective click functions declared which we will add next. Also note, the stop button is set to disabled.


Now we add the three functions: The first function starts the timer and sets the timer event handler function which fires at each set ‘delay’ interval

public function startTimer():void{  
/* Fire once every ‘delay’ milliseconds */
var delay:Number = 1000;
myTimer = new Timer(delay, 9999);

/* set the function to fire at each interval */
myTimer.addEventListener(”timer”, timerHandler);
myTimer.start();
btnStop.enabled = true;
btnStart.enabled = false;
}
/*and the stop function which stops and resets the timer*/

public function stopTimer():void{
myTimer.stop();
myTimer.reset();
btnStop.enabled = false;
btnStart.enabled = true;
}

/*and the timerHandler function which fires at each set interval*/
  public function timerHandler(event:TimerEvent):void {
takeSnapshot();
}

And thats pretty much all there is to that.
Here is a link to the complete code.

Comments
Add New
Powered by !JoomlaComment 3.26

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 

Help my beer fund

RocketTheme Joomla Templates