//比如此FLASH文件为1.swf，则访问为1.swf?id=2



stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//right click credits menu
var rightClickMenu:ContextMenu = new ContextMenu();
var copyright:ContextMenuItem = new ContextMenuItem("Idaishu.cn 2.93" );
copyright.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, myLink );
copyright.separatorBefore = false;
rightClickMenu.hideBuiltInItems();
rightClickMenu.customItems.push(copyright);
this.contextMenu = rightClickMenu;
function myLink(e:Event){
	navigateToURL(new URLRequest("http://idaishu.cn"), "_blank" );
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import com.adobe.images.JPGEncoder;

var param:Object = root.loaderInfo.parameters;
var url:String=param["id"];

var snd:Sound = new camerasound(); //new sound instance for the "capture" button click

var bandwidth:int = 0; // Maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second.
var quality:int = 100; // This value is 0-100 with 1 being the lowest quality. 

var cam:Camera = Camera.getCamera();
cam.setQuality(bandwidth, quality);
cam.setMode(320,240,30,false); // setMode(videoWidth, videoHeight, video fps, favor area)
var video:Video = new Video();
video.attachCamera(cam);
video.x = 28;
video.y = 13;
addChild(video);

var bitmapData:BitmapData = new BitmapData(video.width,video.height);
var bitmap:Bitmap = new Bitmap(bitmapData);

bitmap.x = 28;
bitmap.y = 13;
addChild(bitmap);
bitmap.visible=false
capture_mc.buttonMode = true;
capture_mc.addEventListener(MouseEvent.CLICK,captureImage);

function captureImage(e:MouseEvent):void {	
	play()
	snd.play();
	bitmap.visible=true
	video.visible=false
	bitmapData.draw(video);
	save_mc.buttonMode = true;
	save_mc.addEventListener(MouseEvent.CLICK, onSaveJPG);
	save_mc.alpha = 1;
}
save_mc.alpha = .5;


function onSaveJPG(e:Event):void{
	var myEncoder:JPGEncoder = new JPGEncoder(100);
	var byteArray:ByteArray = myEncoder.encode(bitmapData);	
	var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
	var saveJPG:URLRequest = new URLRequest("save.php?url="+url);
	saveJPG.requestHeaders.push(header);
	saveJPG.method = URLRequestMethod.POST;
	saveJPG.data = byteArray;	
	var urlLoader:URLLoader = new URLLoader();
	urlLoader.addEventListener(Event.COMPLETE, sendComplete);
	urlLoader.load(saveJPG);	
	play()//保存成功 !	
	function sendComplete(event:Event):void{		
		addChild(warn);		
		warn.addEventListener(MouseEvent.MOUSE_DOWN, warnDown);
		warn.buttonMode = true;
		warn.tishi.text="保存成功!点击返回"
	}
}

	
function warnDown(e:MouseEvent):void{
	//navigateToURL(new URLRequest("images/"), "_blank");	
	play()//点击继续返回。
}

