[Help] Add countdown timer to webcam application

Greetings, I am new to the forum and to the application. I am a third year student that is currently working on my Final Year Project and I have been having problems with adding a countdown timer to my webcam application.

My aim is to

  1. Click on the ‘Capture’ button
  2. Start countdown timer (10secs)
  3. Capture image after 10 seconds is up
  4. Display Captured Image

My code :

import flash.display.Bitmap;
import flash.display.BitmapData;
import com.adobe.images.JPGEncoder;
import flash.net.FileReference;
 
var cam:Camera = Camera.getCamera();
var video:Video = new Video(320,240);
video.attachCamera(cam);
video.x = 20;
video.y = 20;
addChild(video);
 
var bitmapData:BitmapData = new BitmapData(video.width,video.height);
 
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.x = 360;
bitmap.y = 20;
addChild(bitmap);
 
capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK,captureImage);
 
save_mc.buttonMode = true;
save_mc.addEventListener(MouseEvent.CLICK,saveImage);
 
function captureImage(e:MouseEvent):void {
bitmapData.draw(video);
}
 
var i:Number=1;
var fileRef:FileReference = new FileReference();
 
function saveImage(e:MouseEvent):void{
var encoder:JPGEncoder = new JPGEncoder();
var ba:ByteArray = encoder.encode(bitmapData);
fileRef.save(ba,"capture"+i+".jpg");
i++;
}

It would be nice if you guys could aid me in this process. I look forward to your replies.