flash on 2010-11-12

by dotton
♥0 | Line 36 | Modified 2010-11-12 06:30:52 | MIT License
play

ActionScript3 source code

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

package {
    import flash.text.TextField;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;    
    import flash.media.Camera;
    import flash.media.Video;
    
    public class FlashTest extends Sprite {
        private var w:int=400;
        private var h:int=300;
        private var video_obj:Video
        private var bmd:BitmapData;
        private var tf:TextField;
        
        public function FlashTest() {
            tf = new TextField();
            tf.y = 350;
            tf.text = "test"
            addChild(tf);
            
            // write as3 code here.
            video_obj = new Video(w,h);
            //addChild(video_obj);
            // カメラオブジェクトを取得
            var cam:Camera = Camera.getCamera();
            video_obj.scaleX=-1;
            video_obj.x = w;
            addChild(video_obj);
            
            // ビデオとカメラを関連付け
            video_obj.attachCamera(cam);
            
            bmd = new BitmapData(w,h,false,0xffffff);
            
            
            addEventListener(Event.ENTER_FRAME, enterHandler);
            stage.addEventListener(MouseEvent.CLICK, onClick);
            
        }
        private function enterHandler(e:Event):void{
            bmd.draw(video_obj);
        }

        private function onClick(e:MouseEvent):void{
               //取得するピクセルは左右逆の位置
               tf.text = bmd.getPixel(w-mouseX, mouseY).toString(16);
        }
        
    }
}