Chapter 33 Example 1

by actionscriptbible
♥0 | Line 34 | Modified 2010-02-05 16:20:53 | MIT License
play

ActionScript3 source code

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7I8m
 */

package {
  import flash.display.Sprite;
  import flash.events.StatusEvent;
  import flash.media.Camera;
  import flash.media.Video;
  import flash.system.Security;
  import flash.system.SecurityPanel;
  public class ch33ex1 extends Sprite {
    protected var camera:Camera;
    protected var video:Video;
    public function ch33ex1() {
      camera = Camera.getCamera();
      if (camera) {
        camera.addEventListener(StatusEvent.STATUS, onCameraStatus);
        if (camera.muted) {
          Security.showSettings(SecurityPanel.PRIVACY);
        } else {
          attach();
        }
      }
    }
    protected function attach():void {
      video = new Video(camera.width, camera.height);
      video.attachCamera(camera);
      addChildAt(video, 0);
    }
    protected function onCameraStatus(event:StatusEvent):void {
      switch (event.code) {
        case "Camera.Muted": removeChild(video); video = null; break;
        case "Camera.Unmuted": attach(); break;
      }
    }
  }
}