Open a camera in ActionScript


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



Copy this code and paste it in your HTML
  1. if(Camera.names.length==0)
  2. {
  3. var _txt:TextField = new TextField();
  4. _txt.thickness=5;
  5. _txt.textColor = 0xFF0000;
  6. _txt.width = stage.width;
  7. _txt.text = "There is no usable camera.";
  8. addChild( _txt );
  9. return;
  10. }
  11.  
  12. // Get the default camera
  13. var _cam:Camera = Camera.getCamera();
  14.  
  15. // If that doesn't work, look for one named "USB Video Class Video"
  16. // This is mostly for Mac
  17. if(!_cam) {
  18. var index:int = 0;
  19. for ( var i : int = 0 ; i < Camera.names.length ; i++ ) {
  20. if ( Camera.names[ i ] == "USB Video Class Video" )
  21. index = i;
  22. }
  23. _cam = Camera.getCamera( String( index ) );
  24. }
  25.  
  26. // If we still don't have a cmaera, open the security panel
  27. if(!_cam) {
  28. Security.showSettings( SecurityPanel.CAMERA );
  29. }
  30.  
  31. _cam = Camera.getCamera();
  32. _cam.setMode( 640, 480, 12, true );
  33.  
  34. _video = new Video( _cam.width, _cam.height );
  35. _video.attachCamera( _cam );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.