Webcam with AS3


/ Published in: ActionScript 3
Save to your folder(s)

Using the webcam in AS3 is super easy. You just need to attach the camera class to a video instance. This is a class that extends the video component for easily implementing a webcam display.


Copy this code and paste it in your HTML
  1. package {
  2.  
  3. import flash.media.Camera;
  4. import flash.media.Video;
  5.  
  6.  
  7. public class CameraDemo extends Video {
  8.  
  9. private var camera:Camera;
  10. private var camQuality:int = 80;
  11. private var fps:int = 30;
  12.  
  13. public function CameraDemo(w:Number = 640, h:Number = 480) {
  14. /* Set the width and height of the camera's display */
  15. this.width = w;
  16. this.height = h;
  17. startCamera();
  18. }
  19.  
  20. public function startCamera():void
  21. {
  22. /* Get the default camera for the system */
  23. camera = Camera.getCamera();
  24. /* Set the bandwidth and camera image quality */
  25. camera.setQuality(0, camQuality);
  26. /* Set the size of the camera and frames per second */
  27. camera.setMode(this.width, this.height, fps);
  28. /* Attach the camera to the video object.. In this case the current class. */
  29. this.attachCamera(camera);
  30. }
  31. }
  32. }

URL: http://www.commandreturn.com/demos/cameraDemo/camera.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.