In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Webカメラで撮影(フィルタ付き)

Web カメラの保存テスト
ダブルクリックで画像を保存する。
フィルターを追加した。マウスを上下に動かすとフィルターが適応される。
フィルターは後で理解しながら増やしていく;;はず
// forked from teageek's Webカメラの保存テスト
//forked from : mogera's 保存サンプル  
// Web カメラの保存テスト
//ダブルクリックで画像を保存する。
//フィルターを追加した。マウスを上下に動かすとフィルターが適応される。
//フィルターは後で理解しながら増やしていく;;はず

package  {
	import com.adobe.images.JPGEncoder;
	import flash.net.FileReference;
	import flash.events.*;
	import flash.net.FileReferenceList;
	import flash.text.*;
	import flash.display.*;
	import flash.media.*;
        import flash.geom.Matrix;
        import flash.filters.*;
        import flash.ui.*;
        import flash.utils.*;
    
	[SWF(width="464", height="464",backgroundColor="#ffff00",frameRate="30")]   
	public class Save extends MovieClip{
                private var menu_cm:ContextMenu ;
		private var mc:MovieClip;
                private var mt:Matrix = new Matrix();
                private var filterArr:Array= [];
                private var cam:Camera = Camera.getCamera();
                private var v:Video= new Video(364,364);
                private var count:int=0;
                private var tf:TextField;
                private var bak:int = new int();

		public function Save() {
		 	//mc= this;
                        mc=new MovieClip();
                        this.addChild(mc);
		        if (cam != null) 
			  ;//  trace("Camera"+Camera.names);
                        //カメラのキャプチャモードを指定の要件に最も近いネイティブモードに設定		        
                        cam.setMode(364,364,30,true);
        	        v.attachCamera(cam);
                        v.x=-63;
                        v.y=30;
                        mc.addChild(v);
                        
                        //鏡みたいに反転
                        mt.scale(-1, 1);
                        mt.translate(cam.width,0);
                        mc.transform.matrix=mt;
                        
                        setFilter();
                     
          		//保存(JPG)
  			this.stage.doubleClickEnabled = true;
                        this.stage.addEventListener(MouseEvent.DOUBLE_CLICK,SaveFile(SaveJPG, "test.jpg"));
                        mc.doubleClickEnabled = true;
                        mc.addEventListener(MouseEvent.DOUBLE_CLICK,SaveFile(SaveJPG, "test.jpg"));

                        mc.addEventListener(Event.ENTER_FRAME,changeFilter);
                        
                        tf= new TextField();
                        tf.text="text";
                        tf.x=0;
                        tf.y=400;
                        tf.width=464;
                        tf.height=100;
                        tf.selectable=false;
                        
                        this.addChild(tf);
                         
                         
		}

                private function changeFilter(e:Event=null):void{
                    
                      var mx:int = mc.mouseY /10;
                      if(bak!=mx){
                      //trace(mx,filterArr.length);
                      if(mx>=filterArr.length||mx<0) tf.text="", mc.filters=[];
                   else      {
                       var fil:*= filterArr[mx];
                       //「ArgumentError: Error #2005: パラメータ 0 の型が正しくありません。
                       //正しい型は Filter です」って出るけど;Filterなんて型なくない? 
                        //mouseYにマイナスが入ってた; 相対座標だからか;;;
                       show(fil);
                       mc.filters=[fil];
                       
                    }
                        }
                        bak=mx;
                        }

		private function SaveFile(encFunc:Function, fileName:String):Function {
		
			return function(e:Event) : void
			{
				
				var ff:FileReference = new FileReference();
				ff.addEventListener(Event.OPEN,    
                                function(e:Event):void { trace("open");  } );
				ff.addEventListener(ProgressEvent.PROGRESS, 
                                function(e:ProgressEvent):void { trace("progress");  } );
				ff.addEventListener(Event.COMPLETE, 
                                function(e:Event):void { trace("complete");  } );
				ff.addEventListener(Event.CANCEL, 
                                function(e:Event):void { trace("cancel");  } );
				ff.addEventListener(Event.SELECT, 
                                function(e:Event):void { trace("select");  } );
				ff.addEventListener(IOErrorEvent.IO_ERROR, 
                                function(e:IOErrorEvent):void { trace("ioError");  } );
				ff.save(encFunc(), fileName);
			}

		}
		
                //  JPGでセーブ
		private function SaveJPG() : ByteArray
		{
			var bmp_data:BitmapData = new BitmapData(464, 464);

                        //鏡みたいに反転
                        bmp_data.draw(mc, mt);
                        //bmp_data.draw(mc)
			
			var jpgEncoder:JPGEncoder = new JPGEncoder(80);
			var jpgData:ByteArray = jpgEncoder.encode(bmp_data); 

			return jpgData;
		}
                private function setFilter():void{
                    //ブラーフィルタ
                    
var blurFilter1:BlurFilter = new BlurFilter(8, 0, 1);
var blurFilter2:BlurFilter = new BlurFilter(0, 8, 1);
var blurFilter3:BlurFilter = new BlurFilter(4, 4, 1);
var blurFilter4:BlurFilter = new BlurFilter(4, 4, 3);
var blurFilter5:BlurFilter = new BlurFilter(2, 2, 3);
//trace(describeType(blurFilter1)..accessor);
//show(blurFilter1);

//trace(getQualifiedClassName(blurFilter1));
//trace(getQualifiedSuperclassName(blurFilter1));

filterArr.push(blurFilter1);
filterArr.push(blurFilter2);
filterArr.push(blurFilter3);
filterArr.push(blurFilter4);
filterArr.push(blurFilter5);

//グローフィルタ
var glowFilter1:GlowFilter = new GlowFilter(0xFFFFFF, 1, 16, 16, 2, 1, false, false);
var glowFilter2:GlowFilter = new GlowFilter(0xFFFFFF, 1, 32, 32, 3, 3, false, false);
var glowFilter3:GlowFilter = new GlowFilter(0xFFFF00, 1, 16, 16, 2, 1, false, false);
var glowFilter4:GlowFilter = new GlowFilter(0xFFFFFF, 1, 16, 16, 2, 1, false, true);
var glowFilter5:GlowFilter = new GlowFilter(0xFFFFFF, 1, 16, 16, 4, 2, false, true);
//trace(describeType(glowFilter1));

filterArr.push(glowFilter1);
filterArr.push(glowFilter2);
filterArr.push(glowFilter3);
filterArr.push(glowFilter4);
filterArr.push(glowFilter5);

//ドロップシャドウフィルタ
var dropShadowFilter1:DropShadowFilter = new DropShadowFilter(8, 45, 0x000000, 0.8, 16, 16, 1, 1, false, false, false);
var dropShadowFilter2:DropShadowFilter = new DropShadowFilter(8, 45, 0x000000, 0.8, 32, 32, 1, 3, false, false, false);
var dropShadowFilter3:DropShadowFilter = new DropShadowFilter(8, 45, 0xFFFF00, 0.8, 16, 16, 1, 1, false, false, false);
var dropShadowFilter4:DropShadowFilter = new DropShadowFilter(8, 45, 0x000000, 0.8, 16, 16, 1, 1, false, false, true);
var dropShadowFilter5:DropShadowFilter = new DropShadowFilter(4, 90, 0x000000, 0.8, 4, 4, 1, 2, true, true, false);

filterArr.push(dropShadowFilter1);
filterArr.push(dropShadowFilter2);
filterArr.push(dropShadowFilter3);
filterArr.push(dropShadowFilter4);
filterArr.push(dropShadowFilter5);

//べベルフィルタ
var bevelFilter1:BevelFilter = new BevelFilter(4, 45, 0xFFFFFF, 1, 0x000000, 1, 8, 8, 1, 2, "inner", false);
var bevelFilter2:BevelFilter = new BevelFilter(4, 45, 0xFFFFFF, 0.5, 0x000000, 0.5, 8, 8, 2, 3, "outer", false);
var bevelFilter3:BevelFilter = new BevelFilter(4, 45, 0xFF0000, 0.5, 0xFFFF00, 0.5, 8, 8, 2, 3, "full", false);
var bevelFilter4:BevelFilter = new BevelFilter(4, 45, 0xFFFFFF, 1, 0x000000, 1, 8, 8, 1, 2, "inner", true);
var bevelFilter5:BevelFilter = new BevelFilter(4, 45, 0xFFFFFF, 0.5, 0x000000, 0.5, 4, 4, 1, 2, "outer", false);

filterArr.push(bevelFilter1);
filterArr.push(bevelFilter2);
filterArr.push(bevelFilter3);
filterArr.push(bevelFilter4);
filterArr.push(bevelFilter5);

//グラデーショングロー
var gradientGlowFilter1:GradientGlowFilter = new GradientGlowFilter(0, 0,[0xFF0000, 0xFFFF00, 0xFFFFFF], [0, 0.5, 1], [0, 128, 255], 16, 16, 2, 2, "outer", false);
var gradientGlowFilter2:GradientGlowFilter = new GradientGlowFilter(0, 0,  [0xFF0000, 0xFFFF00, 0xFFFFFF], [0, 0.5, 1], [0, 192, 255], 32, 32, 3, 3, "outer", false);
var gradientGlowFilter3:GradientGlowFilter = new GradientGlowFilter(0, 0,[0x0000FF, 0x0066FF, 0x00FFFF, 0x66FFFF, 0xFFFFFF], [0, 0.2, 0.4, 0.6, 0.8, 1], [0, 64, 128, 192, 255], 16, 16, 2, 2, "outer", false);
var gradientGlowFilter4:GradientGlowFilter = new GradientGlowFilter(0, 0,[0xFF0000, 0xFFFF00, 0xFFFFFF], [0, 0.5, 1],[0, 128, 255], 16, 16, 2, 2, "outer", true);
var gradientGlowFilter5:GradientGlowFilter = new GradientGlowFilter(0, 0,[0xFF0000, 0xFFFF00, 0xFFFFFF], [0, 0.5, 1],  [0, 128, 255], 16, 16, 4, 2, "outer", true);

filterArr.push(gradientGlowFilter1);
filterArr.push(gradientGlowFilter2);
filterArr.push(gradientGlowFilter3);
filterArr.push(gradientGlowFilter4);
filterArr.push(gradientGlowFilter5);

//グラデーションべベル
var gradientBevelFilter1:GradientBevelFilter = new GradientBevelFilter(4, 45,[0xFFFF00, 0xFFFFFF, 0xFF0000], [1, 0, 1],  [0, 128, 255], 8, 8, 1, 2, "inner", false);
var gradientBevelFilter2:GradientBevelFilter = new GradientBevelFilter(4, 45, [0xFFFF00, 0xFFFFFF, 0xFF0000],  [1, 0, 1], [0, 128, 255], 8, 8, 2, 3, "outer", false);
var gradientBevelFilter3:GradientBevelFilter = new GradientBevelFilter(4, 45,[0x00FFFF, 0x66FFFF, 0xFFFFFF, 0x0066FF, 0x0000FF],[0.5, 0.25, 0, 0.25, 0.5],[0, 64, 128, 192, 255], 8, 8, 2, 3, "full", false);
var gradientBevelFilter4:GradientBevelFilter = new GradientBevelFilter(4, 45, [0xFFFF00, 0xFFFFFF, 0xFF0000],[1, 0, 1], [0, 128, 255], 8, 8, 1, 2, "inner", true);
var gradientBevelFilter5:GradientBevelFilter = new GradientBevelFilter(4, 45,[0xFFFF00, 0xFFFFFF, 0xFF0000], [0.8, 0, 0.8],[0, 128, 255], 4, 4, 2, 2, "outer", false);	

filterArr.push(gradientBevelFilter1);
filterArr.push(gradientBevelFilter2);
filterArr.push(gradientBevelFilter3);
filterArr.push(gradientBevelFilter4);
filterArr.push(gradientBevelFilter5);
	
//カラーマトリックス
var color_mtx1: ColorMatrixFilter  = new ColorMatrixFilter([1/3,1/3,1/3,0,0,1/3,1/3,1/3,0,0,1/3,1/3,1/3,0,0,0,  0,  0,  1,0]);
var color_mtx2: ColorMatrixFilter =new ColorMatrixFilter( [0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0]);
var color_mtx3: ColorMatrixFilter = new ColorMatrixFilter([1,0,0,0,255,0,1,0,0,128,0,0,1,0,0,0,0,0,1,0]);
var color_mtx4: ColorMatrixFilter = new ColorMatrixFilter([1,0,0,0,128,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0]);

filterArr.push(color_mtx1);
filterArr.push(color_mtx2);
filterArr.push(color_mtx3);
filterArr.push(color_mtx4);

//コンボリューション  あとで追加
var convolutionFilter1:ConvolutionFilter= new ConvolutionFilter(3,3,[1,1,0,1,0,-1,0,-1,-1],1,128);
filterArr.push(convolutionFilter1);
//ディスプレイスメントマップ あとで追加
                    }
                    private function show(base:*):void{
                          // trace("show:フィルターの詳細を表示する");
                            var item:XMLList =describeType(base)..accessor;
                            var myAccessType:String =item.@access;
                            var myPropertyName:* = item.@name;
                          
                           tf.text=(""+getQualifiedClassName(base)+"\n");
                           var i:int=0;
                           for each(var a:* in myPropertyName){
                           if(i%4==0) tf.appendText("\n");i++;
                          var s:String=String(a);
                              
                           try{
                              tf.appendText(s+" "+base[s]+" ");
                          }catch(e:Error){;}
                                 
                        }
                        tf.appendText("\n\n");
                            
                      
                           
                          
                   }
                        
	}
}