forked from: Camera

by umhr forked from Camera (diff: 131)
...

@author umhr
♥0 | Line 54 | Modified 2012-09-16 20:53:59 | MIT License
play

ActionScript3 source code

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

package  

{

    import flash.display.Sprite;

    import flash.events.Event;

    import flash.events.MouseEvent;

    import flash.media.Camera;

    import flash.media.Video;

    /**

     * ...

     * @author umhr

     */

    public class WonderflMain extends Sprite

    {

        

        public function WonderflMain() 

        {

            init();

        }

        private function init():void 

        {

            if (stage) onInit();

            else addEventListener(Event.ADDED_TO_STAGE, onInit);

        }

        

        private function onInit(event:Event = null):void 

        {

            removeEventListener(Event.ADDED_TO_STAGE, onInit);

            // entry point

            

            setCamera();

            

            stage.addEventListener(MouseEvent.CLICK, stage_click);

        }

        

        private function stage_click(e:MouseEvent):void 

        {

            while (this.numChildren > 0) {

                this.removeChildAt(0);

            }

            

            if(stage.displayState == "normal"){

                stage.displayState = "fullScreen";

            }else{

                stage.displayState = "normal";

            }

            setCamera();

        }

        

        private function setCamera():void {

            var camera:Camera = Camera.getCamera();

            //カメラの存在を確認

            if (camera) {

                camera.setMode(1920, 1080, 30);

                var video:Video = new Video();

                video.attachCamera(camera);

                

                var scale:Number = Math.max(stage.stageWidth / video.width, stage.stageHeight / video.height);

                video.width = stage.stageWidth;
                video.height = stage.stageHeight;

                

                video.x = int((stage.stageWidth - video.width) * 0.5);

                video.y = int((stage.stageHeight - video.height) * 0.5);

                

                this.addChild(video);

            } else {

                trace("カメラが見つかりませんでした。");

            }

        }

        

    }



}