flash on 2011-5-13

by environmental
♥0 | Line 63 | Modified 2011-05-13 19:32:38 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.MovieClip;
    import flash.display.Sprite;
    
    import flash.system.LoaderContext;
    import flash.net.URLRequest;
    import flash.display.Loader;
    
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.filters.BlurFilter;
    import flash.filters.GlowFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.utils.Timer;    
    
    public class FlashTest extends Sprite {
        
        private var _bg:MovieClip;
        
        private var _width:int;
        private var _height:int;
        
        private var _video:Video;
        private var _output:Bitmap;
        private var _olddata:BitmapData;
        private var _data:BitmapData;
        private var _rect:Rectangle;
        
        private var _pixelarray:Array;
        
        private var loader:Loader; 
        
        public function FlashTest() {
            // write as3 code here..
            
            _bg = new MovieClip();            
            addChild( _bg );
            
            openWebcam();
            
        }
        
        private function openWebcam() : void {
            
            var camera:Camera = Camera.getCamera();
            if (camera != null)
            {
                _video = new Video(160, 120);
                _video.attachCamera(camera);
                _bg.addChild(_video);
            }
         
             _width = _video.width;
            _height = _video.height;
            _rect = new Rectangle(0, 0, _width, _height);
            
            _data = new BitmapData(_width, _height, true, 0xFF000000);
            _olddata = new BitmapData(_width, _height, true, 0x00000000);
            
            _pixelarray = [];      
                        
            _output = new Bitmap(_data);
            _output.smoothing = true;
            addChild(_output);
            
            _output.width = stage.stageWidth;
            _output.height = stage.stageHeight;
            
            _video.width = stage.stageWidth;
            _video.height = stage.stageHeight;
            
            var timer:Timer = new Timer(1);
            timer.addEventListener(TimerEvent.TIMER, onTimer);
            timer.start();              
         
            
        }
        
        
    }
}