flash on 2011-5-27

by tepe
♥0 | Line 50 | Modified 2011-07-20 12:57:01 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.media.*;
    import flash.events.*;
    import flash.text.*;
    
    public class FlashTest extends Sprite {
        private var camera:Camera;
        private var video:Video;
        private var mic:Microphone;
        private var txt:TextField;
        private var cnt:int=0;
        
        public function FlashTest() {
            // write as3 code here..
            txt = new TextField();
            txt.width = 300;
            txt.height = 300;
            stage.addChild(txt);

            
            var i:int;
            if(camera.muted == true)txt.appendText("muted¥n");
            else txt.appendText("Webカメラ\n");
            for(i = 0;i<Camera.names.length;i++){
                txt.appendText(Camera.names[i] + "\n");
            }
            txt.appendText("マイク\n");
            
            for(i=0;i<Microphone.names.length;i++){
                txt.appendText(Microphone.names[i]+ "\n");
            }

            stage.addEventListener(MouseEvent.CLICK,startCam);

            
            
        }
        private function startCam(e:MouseEvent):void{
            var str:String = Camera.names[cnt];
            txt.appendText("\n"+str);
            camera = Camera.getCamera(cnt.toString());
            txt.appendText("\nname:"+camera.name); 
            cnt++;
            cnt%= Camera.names.length;
            mic = Microphone.getMicrophone();
            mic.codec = SoundCodec.SPEEX;
            mic.setUseEchoSuppression(true);
            mic.setLoopBack();            
            
            if(camera != null){
                //camera.setMode(320,240,30);
                video = new Video(camera.width,camera.height);
                video.attachCamera(camera);
                video.x = mouseX;//Math.random()*300;
                video.y = mouseY;//Math.random()*300;
                //video.scaleX = video.scaleY = 1+Math.random()*2;
                addChild(video);
                txt.appendText("\n"+camera.width.toString()+ " "+camera.height.toString());
            }
        }

    }
}