mrpetem Posted December 4, 2010 Share Posted December 4, 2010 Does anyone know how I can capture and area on the flash movie, then send as an image to a php file? Any suggestions? Here is source code: var mailbd:BitmapData; var xvalue:Number = 80; var yvalue:Number = 120; var gtxt:TextField = new TextField(); var price:Number = 39.90; var picPanel:picPanel_mc = new picPanel_mc(); var numval; var imageLoader:Loader = new Loader(); var thumbLoader:Loader = new Loader(); //var tumbLoader:Loader; iphone_mc.color_mc.visible = false; var coloring:Boolean = false; var xPosSidePanelLP:Tween = new Tween(sidePanels_mc.leftPanel_mc, "x",Regular.easeIn, sidePanels_mc.leftPanel_mc.x , (sidePanels_mc.leftPanel_mc.x +sidePanels_mc.leftPanel_mc.width), 1, true); var xPosSidePanelRP:Tween = new Tween(sidePanels_mc.rightPanel_mc, "x",Regular.easeIn, sidePanels_mc.rightPanel_mc.x , (sidePanels_mc.rightPanel_mc.x - sidePanels_mc.rightPanel_mc.width), 1, true); printArea_mc.visible = false; function loadImage(url:String):void { var inter:uint = setInterval(packup,4000); function packup(){ outergrid_mc.visible = false; iphone_mc.outer_mc.alpha = 1.0; clearInterval(inter); } fontPanel_mc.visible = false; // Set properties on my Loader object init(); imageLoader.load(new URLRequest(url)); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); } thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded); imageLoader.contentLoaderInfo.addEventListener(Event.INIT, thumLoadInit); function thumbLoaded(evt:Event){ thumbLoader.height = 105; thumbLoader.width = 136; sidePanels_mc.leftPanel_mc.frbrowse_btn.addChild(thumbLoader); sidePanels_mc.leftPanel_mc.frbrowse_btn.loader_mc.visible = false; } function thumLoadInit(evt:Event){ sidePanels_mc.leftPanel_mc.frbrowse_btn.loader_mc.visible = true; } function loadAtWork(str:String){ //abhishek iphone_mc.color_mc.visible = false; iphone_mc.image_mc.img_mc.visible = true; loadimg(str); this.removeChild(picPanel); } thumbLoader.load(new URLRequest("img.jpg")); //loadimg("img.jpg"); function loadimg(path:String):void{ loadImage(path); imageLoader.x = 0; imageLoader.y = 0; thumbLoader.load(new URLRequest(path)); } function imageLoaded(e:Event):void { init(); printArea_mc.visible = true; iphone_mc.image_mc.img_mc.addChild(imageLoader); } // Load Image iphone_mc.image_mc.img_mc.addChild(imageLoader); init(); //} fontPanel_mc.visible = false; function init() { //bx_mc.visible = true; //var myTweenY2:Tween = new Tween(iphone_mc.image_mc, "y",Regular.easeOut, -1400 ,stage.y, 2, true); var myTweenY:Tween = new Tween(iphone_mc, "y",Regular.easeOut, 840 , 50, 2, true); loader_mc.visible = false; //iphone_mc.outer_mc.visible = false; iphone_mc.outer_mc._visible = true; //inter = setInterval(timeOver,4000); } iphone_mc.outer_mc.alpha=.8; iphone_mc.bo_mc.addEventListener(MouseEvent.MOUSE_DOWN,imgdragging); iphone_mc.bo_mc.addEventListener(MouseEvent.MOUSE_UP,imgdraggingstop); function imgdragging(evt:MouseEvent){ iphone_mc.image_mc.startDrag(); if(coloring==false){ iphone_mc.outer_mc.alpha = 0.8; } } function imgdraggingstop(evt:MouseEvent){ stopDrag(); iphone_mc.outer_mc.alpha = 1.0; } stonePanel_mc.visible = false; //ResizeButton sidePanels_mc.leftPanel_mc.resize_btn.addEventListener(MouseEvent.CLICK,resizepanelfunc); function resizepanelfunc(evt:MouseEvent) { sidePanels_mc.leftPanel_mc.resize_btn.buttonPressed(); } sidePanels_mc.leftPanel_mc.rotation_btn.addEventListener(MouseEvent.CLICK,rotationpanelfunc); function rotationpanelfunc(evt:MouseEvent) { sidePanels_mc.leftPanel_mc.rotation_btn.buttonPressed(); } //CaptureImage sidePanels_mc.rightPanel_mc.capture_btn.addEventListener(MouseEvent.CLICK,capture); function getBitmapData():BitmapData { iphone_mc.outer_mc.innergrid_mc.visible = false; var rect:Rectangle = new Rectangle(0,0,265,480); var bd:BitmapData = new BitmapData(265,480); bd.draw(iphone_mc,null,null,null,rect,true); iphone_mc.outer_mc.innergrid_mc.visible = true; return bd; } function capture(evt:MouseEvent){ saveim(getBitmapData()); } resizePanel_mc.close_btn.addEventListener(MouseEvent.CLICK,closeResizePanel); function closeResizePanel(evt:Event):void{ sidePanels_mc.leftPanel_mc.resize_btn.buttonPressed(); } rotationPanel_mc.close_btn.addEventListener(MouseEvent.CLICK,closeRotationPanel); function closeRotationPanel(evt:Event):void{ sidePanels_mc.leftPanel_mc.rotation_btn.buttonPressed(); } resizePanel_mc.bg_mc.addEventListener(MouseEvent.MOUSE_DOWN,resizePanelDragging); function resizePanelDragging(evt:MouseEvent):void{ resizePanel_mc.startDrag();; } rotationPanel_mc.bg_mc.addEventListener(MouseEvent.MOUSE_DOWN,rotationPanelDragging); function rotationPanelDragging(evt:MouseEvent):void{ rotationPanel_mc.startDrag();; } sidePanels_mc.rightPanel_mc.iconImage_btn.addEventListener(MouseEvent.CLICK,iconImageLoad); function iconImageLoad(evt:Event){ addChild(picPanel); } var fr:FileReference = new FileReference(); sidePanels_mc.leftPanel_mc.frbrowse_btn.addEventListener(MouseEvent.CLICK,browseFile); function browseFile(evt:Event){ fr.browse(); } fr.addEventListener(Event.SELECT,fileselected); function fileselected(evt:Event){ iphone_mc.color_mc.visible = false; iphone_mc.image_mc.img_mc.visible = true; fr.load(); fr.addEventListener(Event.COMPLETE,completecustomImage); } function completecustomImage(evt:Event){ //iphone_mc.image_mc.img_mc.removeChild(imageLoader); imageLoader.loadBytes(fr.data); thumbLoader.loadBytes(fr.data); thumbLoader.height = 92; thumbLoader.width = 127; sidePanels_mc.leftPanel_mc.frbrowse_btn.addChild(thumbLoader); } //Print Area Button sidePanels_mc.leftPanel_mc.printArea_btn.addEventListener(MouseEvent.CLICK,printAreaAction); function printAreaAction(evt:Event){ if(printArea_mc.visible == true) { printArea_mc.visible = false; } else { printArea_mc.visible = true; } } cPanel_mc.colorPanel_mc.blue_btn.addEventListener(MouseEvent.CLICK,blueColor); cPanel_mc.colorPanel_mc.green_btn.addEventListener(MouseEvent.CLICK,greenColor); cPanel_mc.colorPanel_mc.brown_btn.addEventListener(MouseEvent.CLICK,brownColor); cPanel_mc.colorPanel_mc.darkPink_btn.addEventListener(MouseEvent.CLICK,darkPinkColor); cPanel_mc.colorPanel_mc.lightPink_btn.addEventListener(MouseEvent.CLICK,lightPinkColor); cPanel_mc.colorPanel_mc.lemon_btn.addEventListener(MouseEvent.CLICK,lemonColor); cPanel_mc.colorPanel_mc.yellow_btn.addEventListener(MouseEvent.CLICK,yellowColor); cPanel_mc.colorPanel_mc.darkBlue_btn.addEventListener(MouseEvent.CLICK,darkBlueColor); function blueColor(evt:Event):void{ colorFunction(0x5478bb); } function greenColor(evt:Event):void{ colorFunction(0x5aba46); } function brownColor(evt:Event):void{ colorFunction(0x78451c); } function darkPinkColor(evt:Event):void{ colorFunction(0x800080); } function lightPinkColor(evt:Event):void{ colorFunction(0xff00ff); } function lemonColor(evt:Event):void{ colorFunction(0x9af8f8); } function yellowColor(evt:Event):void{ colorFunction(0xffff00); } function darkBlueColor(evt:Event):void{ colorFunction(0x000080); } function colorFunction(paintColor:uint){ var myColor:ColorTransform = iphone_mc.color_mc.transform.colorTransform; myColor.color = paintColor; iphone_mc.color_mc.transform.colorTransform = myColor; colorAnimation(); } cPanel_mc.colorPanel_mc.gr1_btn.addEventListener(MouseEvent.CLICK,gr1); cPanel_mc.colorPanel_mc.gr2_btn.addEventListener(MouseEvent.CLICK,gr2); cPanel_mc.colorPanel_mc.gr3_btn.addEventListener(MouseEvent.CLICK,gr3); cPanel_mc.colorPanel_mc.gr4_btn.addEventListener(MouseEvent.CLICK,gr4); cPanel_mc.colorPanel_mc.gr5_btn.addEventListener(MouseEvent.CLICK,gr5); function gr1(btn:Event){ fillGradient(iphone_mc.color_mc.gradient1_mc,iphone_mc.color_mc.gradient2_mc,iphone_mc.color_mc.gradient3_mc,iphone_mc.color_mc.gradient4_mc,iphone_mc.color_mc.gradient5_mc); } function gr2(btn:Event){ fillGradient(iphone_mc.color_mc.gradient2_mc,iphone_mc.color_mc.gradient3_mc,iphone_mc.color_mc.gradient3_mc,iphone_mc.color_mc.gradient4_mc,iphone_mc.color_mc.gradient5_mc); } function gr3(btn:Event){ fillGradient(iphone_mc.color_mc.gradient3_mc,iphone_mc.color_mc.gradient2_mc,iphone_mc.color_mc.gradient1_mc,iphone_mc.color_mc.gradient4_mc,iphone_mc.color_mc.gradient5_mc); } function gr4(btn:Event){ fillGradient(iphone_mc.color_mc.gradient4_mc,iphone_mc.color_mc.gradient2_mc,iphone_mc.color_mc.gradient3_mc,iphone_mc.color_mc.gradient1_mc,iphone_mc.color_mc.gradient5_mc); } function gr5(btn:Event){ fillGradient(iphone_mc.color_mc.gradient5_mc,iphone_mc.color_mc.gradient2_mc,iphone_mc.color_mc.gradient3_mc,iphone_mc.color_mc.gradient4_mc,iphone_mc.color_mc.gradient1_mc); } function fillGradient(mc1:MovieClip,mc2:MovieClip,mc3:MovieClip,mc4:MovieClip,mc5:MovieClip):void{ //iphone_mc.color_mc.visible=true; iphone_mc.color_mc.transform.colorTransform = new ColorTransform(); mc1.visible = true; mc2.visible = false; mc3.visible = false; mc4.visible = false; mc5.visible = false; colorAnimation(); } cPanel_mc.visible = false; function colorAnimation(){ coloring = true; iphone_mc.image_mc.img_mc.visible = false; iphone_mc.outer_mc.alpha=1; iphone_mc.color_mc.visible = true; var colorY:Tween = new Tween(iphone_mc.color_mc, "y",Regular.easeIn, -240 , 250, 2, true); } cPanel_mc.close_btn.addEventListener(MouseEvent.CLICK,closeColorPanel); function closeColorPanel(evt:Event){ cPanel_mc.visible = false; } sidePanels_mc.rightPanel_mc.color_btn.addEventListener(MouseEvent.CLICK,showColorPanel); function showColorPanel(evt:Event){ cPanel_mc.visible = true } var stoneIndex = 0; stonePanel_mc.stn1_btn.addEventListener(MouseEvent.CLICK,stn1); stonePanel_mc.stn2_btn.addEventListener(MouseEvent.CLICK,stn2); stonePanel_mc.stn3_btn.addEventListener(MouseEvent.CLICK,stn3); stonePanel_mc.stn4_btn.addEventListener(MouseEvent.CLICK,stn4); stonePanel_mc.stn5_btn.addEventListener(MouseEvent.CLICK,stn5); //stonePanel_mc.stn6_btn.addEventListener(MouseEvent.CLICK,stn6); var stoneArray:Array = new Array(); function stn1(evt:Event){ var newBox:Stone1 = new Stone1(); newBox.x = 100; newBox.y = 200; stoneArray.push(newBox); iphone_mc.addChild(newBox); stoneIndex+=1; price += 0.70; sidePanels_mc.rightPanel_mc.price_txt.text = price.toFixed(2); } function stn2(evt:Event){ var newBox:Stone2 = new Stone2(); newBox.x = 100; newBox.y = 200; stoneArray.push(newBox); iphone_mc.addChild(newBox); stoneIndex+=1; price += 0.70; sidePanels_mc.rightPanel_mc.price_txt.text = price.toFixed(2); } function stn3(evt:Event){ var newBox:Stone3 = new Stone3(); newBox.x = 100; newBox.y = 200; stoneArray.push(newBox); iphone_mc.addChild(newBox); stoneIndex+=1; price += 0.70; sidePanels_mc.rightPanel_mc.price_txt.text = price.toFixed(2); } function stn4(evt:Event){ var newBox:Stone4 = new Stone4(); newBox.x = 100; newBox.y = 200; stoneArray.push(newBox); iphone_mc.addChild(newBox); stoneIndex+=1; price += 0.70; sidePanels_mc.rightPanel_mc.price_txt.text = price.toFixed(2); } function stn5(evt:Event){ var newBox:Stone5 = new Stone5(); newBox.x = 100; newBox.y = 200; stoneArray.push(newBox); iphone_mc.addChild(newBox); stoneIndex+=1; price += 0.70; sidePanels_mc.rightPanel_mc.price_txt.text = price.toFixed(2); } /*function stn6(evt:Event){ var newBox:Stone6 = new Stone6(); newBox.x = 100; newBox.y = 200; stoneArray.push(newBox); iphone_mc.addChild(newBox); stoneIndex+=1; price += 0.70; sidePanels_mc.rightPanel_mc.price_txt.text = price.toFixed(2); }*/ stonePanel_mc.undo_btn.addEventListener(MouseEvent.CLICK,undo); function undo(evt:Event) { if(stoneArray.length>0){ trace(stoneArray.length) var mc:MovieClip = stoneArray[stoneIndex-1]; trace(mc); iphone_mc.removeChild(mc); stoneArray.pop(); stoneIndex -=1; price -= 0.70; sidePanels_mc.rightPanel_mc.price_txt.text = price.toFixed(2); trace(stoneArray.length) } } var myLabels:Array = new Array("Desyrel","International Playboy","Deftone Stylus","Hipchick","Most Wazted"); var myURLs:Array = new Array("Desyrel","International Playboy","Deftone Stylus","Hipchick","Most Wazted"); var mySizeLabels:Array = new Array("12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30","31","32"); var mySizeArray:Array = new Array("12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30","31","32"); for(var i=0;i<myLabels.length;i++) { fontPanel_mc.fontddl.addItem({label:myLabels[i],data:myURLs[i]}) } for(var j=0;j<mySizeLabels.length;j++) { fontPanel_mc.sizeddl.addItem({label:mySizeLabels[j],data:mySizeArray[j]}) } fontPanel_mc.sizeddl.selectedIndex = 21; fontPanel_mc.fontddl.addEventListener(Event.CHANGE, itemChange); fontPanel_mc.sizeddl.addEventListener(Event.CHANGE , sizeChange); function itemChange(e:Event):void { //trace(fontPanel_mc.fontddl.selectedIndex); //var font:Font = fontArray[fontPanel_mc.fontddl.selectedIndex]; var tf:TextFormat = new TextFormat(fontPanel_mc.fontddl.value,fontPanel_mc.sizeddl.value); gtxt.setTextFormat(tf); } function sizeChange(e:Event):void { var tf:TextFormat = new TextFormat(fontPanel_mc.fontddl.value,fontPanel_mc.sizeddl.value); gtxt.setTextFormat(tf); } fontPanel_mc.close_btn.addEventListener(MouseEvent.CLICK,closefontPanel); function closefontPanel(evt:Event){ fontPanel_mc.visible = false; } sidePanels_mc.leftPanel_mc.font_btn.addEventListener(MouseEvent.CLICK,openFontPanel); function openFontPanel(evt:Event):void{ fontPanel_mc.visible = true; } var txtArray:Array = new Array(); fontPanel_mc.addText_btn.addEventListener(MouseEvent.CLICK,AddText); function AddText(evt:Event):void{ var txt:TextField = new TextField(); var mc:MovieClip = new MovieClip(); txt.type = TextFieldType.INPUT; txt.text = "Text"; var tf:TextFormat = new TextFormat(myURLs[0],"32"); txt.setTextFormat(tf); mc.addEventListener(MouseEvent.MOUSE_DOWN,startTextDrag); mc.addEventListener(MouseEvent.MOUSE_UP,stopTextDrag); mc.addChild(txt); //iphone_mc.textContainer_mc.addChild(mc); iphone_mc.addChild(mc); txtArray.push(mc); mc.x = 100 mc.y = 200; gtxt = txt; txt.addEventListener(Event.CHANGE,resizemc); txt.autoSize = TextFieldAutoSize.LEFT; function resizemc(evt:Event):void{ mc.width = txt.width; } function startTextDrag(evt:Event):void{ mc.startDrag(); } function stopTextDrag(evt:Event):void{ mc.stopDrag(); } } stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDownFunc); function KeyDownFunc(event){ if(event.keyCode == Keyboard.ENTER){ stage.focus = stage; } } stonePanel_mc.close_btn.addEventListener(MouseEvent.CLICK,closeStonePanel); function closeStonePanel(evt:Event):void{ stonePanel_mc.visible = false; } sidePanels_mc.rightPanel_mc.stonePanel_btn.addEventListener(MouseEvent.CLICK,showStonePanel); function showStonePanel(evt:Event):void{ stonePanel_mc.visible = true } cPanel_mc.addEventListener(MouseEvent.MOUSE_DOWN,startDragCPanel); cPanel_mc.addEventListener(MouseEvent.MOUSE_UP,stopDragCPanel); function startDragCPanel(evt:Event):void{ cPanel_mc.startDrag(); } function stopDragCPanel(evt:Event):void{ cPanel_mc.stopDrag(); } stonePanel_mc.bg_mc.addEventListener(MouseEvent.MOUSE_DOWN,startDragStonePanel); stonePanel_mc.bg_mc.addEventListener(MouseEvent.MOUSE_UP,stopDragStonePanel); function startDragStonePanel(evt:Event):void{ stonePanel_mc.startDrag(); } function stopDragStonePanel(evt:Event):void{ stonePanel_mc.stopDrag(); } fontPanel_mc.bg_mc.addEventListener(MouseEvent.MOUSE_UP,stopfontPanel); fontPanel_mc.bg_mc.addEventListener(MouseEvent.MOUSE_DOWN,startfontPanel); function stopfontPanel(evt:Event):void{ fontPanel_mc.stopDrag(); } function startfontPanel(evt:Event):void{ fontPanel_mc.startDrag(); } var cartRoomLoaded:Boolean; var cartroom:cart_mc = new cart_mc(); sidePanels_mc.rightPanel_mc.cart_btn.addEventListener(MouseEvent.CLICK,loadCartRoom); var con:MovieClip = new MovieClip(); var itemIndex:Number = 0; var parray:Array = new Array(); function loadCartRoom(evt:Event):void{ var bitmap:Bitmap = new Bitmap(getBitmapData(),PixelSnapping.NEVER, true); bitmap.scaleX = 0.62; bitmap.scaleY = 0.62; var phoneImage:MovieClip = new MovieClip() phoneImage.name = "phoneImage" phoneImage.addChild(bitmap) var cartItem:MovieClip = new MovieClip(); cartItem.addChild(phoneImage); cartItem.x = xvalue; cartItem.y = yvalue; var facebtn:fbutton = new fbutton(); cartItem.addChild(facebtn); facebtn.x = 45; facebtn.y = 305; facebtn.addEventListener(MouseEvent.CLICK,fAction); var mailbtn:mbutton = new mbutton(); cartItem.addChild(mailbtn); mailbtn.x = facebtn.x + facebtn.width+10; mailbtn.y = 305; mailbtn.addEventListener(MouseEvent.CLICK,showMailBox); function fAction(evt:Event):void{ facebookAction(bitmap.bitmapData,"create2.php?name=snapshot.jpg"); } function showMailBox(evt:Event){ var bm:mailbox_mc; mailbd = createDesignForSave(bitmap.bitmapData); if(bm == null) { bm = new mailbox_mc(); addChild(bm); } bm.visible = true; bm.x = 350; bm.y = 350; } if(!cartRoomLoaded) { addChild(cartroom); cartRoomLoaded = true; } else{ cartroom.visible = true; } con.addChild(cartItem); cartroom.addChildAt(con,1); xvalue += 200; parray.push(price); //trace(parray[0]); totalprice += price; //totalPrice(); price = 39.90; sidePanels_mc.rightPanel_mc.price_txt.text = "39.90"; cartroom.updatePrice(); resetIphone(); itemIndex += 1; } function resetIphone(){ iphone_mc.color_mc.visible = false; imageLoader.unload(); thumbLoader.load(new URLRequest("img.jpg")); var i= stoneArray.length; while(stoneArray.length !=0) { trace(stoneArray.length); var mc:MovieClip = stoneArray[stoneArray.length-1]; iphone_mc.removeChild(mc); stoneArray.pop(); } stoneIndex=0; while(txtArray.length!=0) { var mc2:MovieClip = txtArray[txtArray.length -1 ]; iphone_mc.removeChild(mc2); txtArray.pop(); } price = 39.90; sidePanels_mc.rightPanel_mc.price_txt.text = price.toFixed(2); trace(stoneArray.length); } function deleteCartItem(){ con.removeChildAt(itemIndex-1); var p = parray[itemIndex-1]; totalprice -= p; trace(totalPrice()); itemIndex -= 1; parray.pop(); } function moveConRight(){ var myTweenx:Tween = new Tween(con, "x",Regular.easeOut, con.x , con.x+150, 1, true); } function moveConLeft(){ var myTweenx:Tween = new Tween(con, "x",Regular.easeOut, con.x , con.x-150, 1, true); } function getxvalue():Number{ return xvalue; } function setxvalue(){ xvalue -= 200; } var totalprice:Number = 0; function totalPrice():Number{ return totalprice; } function facebookAction(bt:BitmapData,url:String){ /*var rect:Rectangle = new Rectangle(0,0,mymc.width,mymc.height); var bd:BitmapData = new BitmapData(mymc.width,mymc.height); bd.draw(mymc,null,null,null,rect,true); */ var myPreviewLoader:Loader = new Loader(); var num:Number = 80; var myEncoder:JPEGEncoder = new JPEGEncoder(num); // generate a JPG binary stream to have a preview var myCapStream:ByteArray = myEncoder.encode (bt); //size_txt.text = Math.round ( myCapStream.length / 1024 ) + " kb"; // show a preview of the stream with loadBytes myPreviewLoader.loadBytes ( myCapStream ); //box_mc.addChild(myPreviewLoader); var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream"); var myRequest:URLRequest = new URLRequest ( url ); myRequest.requestHeaders.push (header); myRequest.method = URLRequestMethod.POST; myRequest.data = myCapStream; navigateToURL ( myRequest, "_blank" ) } function createDesignForSave(bt:BitmapData):BitmapData{ var mymc:MovieClip = new MovieClip(); var b:Bitmap = new Bitmap(bt); mymc.addChild(b); var l:saveLogo = new saveLogo(); var txt:TextField = new TextField(); txt.text = "Design your own Iphone case or choose one of our premade cases at"; txt.x = 270; txt.y = 100; var f:Font = new Desyrel(); var tf:TextFormat = new TextFormat(myURLs[0],26); txt.setTextFormat(tf); txt.autoSize = TextFieldAutoSize.LEFT; txt.wordWrap = true; txt.multiline = true; txt.width=l.width; txt.height = 300; mymc.addChild(txt); mymc.addChild(l); l.x = 270; l.y = 210; var rect:Rectangle = new Rectangle(0,0,mymc.width,mymc.height); var bd:BitmapData = new BitmapData(mymc.width,mymc.height); bd.draw(mymc,null,null,null,rect,true); return bd; } function saveim(bd:BitmapData){ var myPreviewLoader:Loader = new Loader(); var num:Number = 80; var myEncoder:JPEGEncoder = new JPEGEncoder(num); // generate a JPG binary stream to have a preview var myCapStream:ByteArray = myEncoder.encode (createDesignForSave(bd)); //size_txt.text = Math.round ( myCapStream.length / 1024 ) + " kb"; // show a preview of the stream with loadBytes myPreviewLoader.loadBytes ( myCapStream ); //box_mc.addChild(myPreviewLoader); var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream"); var myRequest:URLRequest = new URLRequest ("create2.php?name=snapshot.jpg"); myRequest.requestHeaders.push (header); myRequest.method = URLRequestMethod.POST; myRequest.data = myCapStream; navigateToURL ( myRequest, "_blank" ) } function postMail(to:String,from:String,mess:String){ var str:String = "postMail.php?name=snapshot.jpg&to=" + to + "&from=" + from + "&mess=" + mess; facebookAction(mailbd,str); //var b:Bitmap = new Bitmap(mailbd); //addChild(b); } function rtnumval():Number{ return numval; } sidePanels_mc.leftPanel_mc.reset_btn.addEventListener(MouseEvent.CLICK,resetAction); function resetAction(evt:Event):void{ resetIphone(); } var savePhpPath:String = "saveImage.php" var imagesSaved = 0; var imagesPaths:Array = new Array() function startCheckout() { imagesSaved = 0; imagesPaths = new Array() saveNextImage() } function saveNextImage() { if (imagesSaved >= con.numChildren) { allImagesWasSaved() return } var filename:String = "image_"+String(randRange(0, 100000)) + ".jpg" imagesPaths.push(filename) var cartItem:MovieClip = MovieClip(MovieClip(con.getChildAt(imagesSaved)).getChildByName("phoneImage")) var jpgSource:BitmapData = new BitmapData (cartItem.width, cartItem.height, false, 0x000000); jpgSource.draw(cartItem); var jpgEncoder:JPEGEncoder = new JPEGEncoder(85); var jpgStream:ByteArray = jpgEncoder.encode(jpgSource); var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream"); var jpgURLRequest:URLRequest = new URLRequest(savePhpPath + "?filename=" + filename); jpgURLRequest.requestHeaders.push(header); jpgURLRequest.method = URLRequestMethod.POST; jpgURLRequest.data = jpgStream; var urlLoader:URLLoader = new URLLoader() urlLoader.addEventListener(Event.COMPLETE, send$complete) urlLoader.addEventListener(IOErrorEvent.IO_ERROR, on$SaveError) urlLoader.load(jpgURLRequest); } function on$SaveError(e:IOErrorEvent):void { trace("error during update php file") } function send$complete(e:Event) { imagesSaved++ storeImg(); saveNextImage(); } function allImagesWasSaved() { trace("all was saved count= " + imagesSaved); var str:String = "cart.php?"; for (var i = 1; i <= imagesSaved; i++) { str += "skin"+i+"="+imagesPaths[i-1] + "&" } str += "count="+imagesSaved navigateToURL(new URLRequest(str), "_self") } /* private function createSnapShot():void { var request:URLRequest = new URLRequest(phpPath); request.method = URLRequestMethod.POST var vars:URLVariables = new URLVariables() vars.filename = filename; request.data = vars jpgSource = new BitmapData (video.width, video.height, false, 0x000000); jpgSource.draw(video_mc); var snapShotHolder:MovieClip = confirmation_mc.snapShotHolder while (snapShotHolder.numChildren) { snapShotHolder.removeChildAt(0) } var bitmap:Bitmap = new Bitmap(jpgSource) bitmap.width = 240 bitmap.height = 180 snapShotHolder.addChild(bitmap) confirmation_mc.visible = true } public function sendToPhp() { var jpgEncoder:JPGEncoder = new JPGEncoder(85); var jpgStream:ByteArray = jpgEncoder.encode(jpgSource); var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream"); var jpgURLRequest:URLRequest = new URLRequest(phpPath + "?filename=" + filename + ".jpg" ); jpgURLRequest.requestHeaders.push(header); jpgURLRequest.method = URLRequestMethod.POST; jpgURLRequest.data = jpgStream; var urlLoader:URLLoader = new URLLoader() urlLoader.addEventListener(Event.COMPLETE, send$complete) urlLoader.addEventListener(IOErrorEvent.IO_ERROR, on$error) urlLoader.load(jpgURLRequest); } */ function randRange(min:Number, max:Number):Number { var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min; return randomNum; } private var grpAction:RadioButtonGroup; private var grpFormat:RadioButtonGroup; function storeImg() { // create radio button groups //grpAction = new RadioButtonGroup("grpAction"); //grpFormat = new RadioButtonGroup("grpFormat"); // initialize radio buttons //optJPG.group = grpFormat; optJPG.value = Snapshot.JPG; //optPNG.group = grpFormat; optPNG.value = Snapshot.PNG; //grpFormat.selection = optJPG; //optDisplay.group = grpAction; optDisplay.value = Snapshot.DISPLAY; //optPrompt.group = grpAction; optPrompt.value = Snapshot.PROMPT; optLoad.group = grpAction; optLoad.value = Snapshot.LOAD; grpAction.selection = optLoad; // set the required Snapshot URL Snapshot.gateway = "snapshot.php"; btnCapture.addEventListener(MouseEvent.CLICK, onCapture); } private function onCapture(evt:MouseEvent):void { // capture as JPG and display prompt user to save/download Snapshot.capture(sample, { format: grpFormat.selectedData, action: grpAction.selectedData, loader: loader }); } Quote Link to comment https://forums.phpfreaks.com/topic/220644-trying-to-capture-image-and-save/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.