Advertisement
YellowAfterlife

Haxe Flash Camera example

Jan 8th, 2014
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.95 KB | None | 0 0
  1. package ;
  2.  
  3. import flash.display.Sprite;
  4. import flash.events.Event;
  5. import flash.events.MouseEvent;
  6. import flash.media.Camera;
  7. import flash.display.Bitmap;
  8. import flash.display.BitmapData;
  9. import flash.media.Video;
  10. import flash.events.StatusEvent;
  11.  
  12. class Main extends Sprite
  13. {
  14.     public var cam:Camera;
  15.     public var vid:Video;
  16.     public function new() {
  17.         super();
  18.         cam = Camera.getCamera();
  19.         if (cam == null) {
  20.             trace("No camera : (");
  21.         } else if (cam.muted) {
  22.             stage.addEventListener(MouseEvent.CLICK, onEnable);
  23.         } else bindCam();
  24.     }
  25.     function onEnable(_) {
  26.         flash.system.Security.showSettings(flash.system.SecurityPanel.PRIVACY);
  27.         cam.addEventListener(StatusEvent.STATUS, onCamStatus);
  28.     }
  29.     function bindCam() {
  30.         trace("bind");
  31.         vid = new Video(cam.width, cam.height);
  32.         vid.attachCamera(cam);
  33.         stage.addChild(vid);
  34.     }
  35.     function onCamStatus(_:StatusEvent) {
  36.         trace(_.code);
  37.         if (_.code == "Camera.Unmuted") bindCam();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement