1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
import flash.display.GradientType;
import flash.display.Loader;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Bitmap;
import flash.display.BitmapData;
import com.adobe.images.JPGEncoder;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
var snd:Sound = new camerasound(); //new sound instance for the "capture" button click
capture_mc.addEventListener(MouseEvent.CLICK, prendrePhoto);
capture_mc.buttonMode = true;
save_mc.buttonMode = true;
save_mc.addEventListener(MouseEvent.CLICK,saveImage);
//fb_mc.buttonMode = true;
//fb_mc.addEventListener(MouseEvent.CLICK,partageImage);
var prisePhoto:Sprite = new Sprite();
addChild(prisePhoto);
function prendrePhoto(evt:MouseEvent):void
{
snd.play();
if (getChildByName("bmp")) removeChild(getChildByName("bmp"));
var bmp:Bitmap = new Bitmap( getBitmapData(photo) );
bmp.x=390-monCadre.width/2;
bmp.y=145-monCadre.height/2;
prisePhoto.addChild(bmp);
bmp.name = "bmp";
//trace(prisePhoto.addChild(bmp).name);
}
function getBitmapData( target:DisplayObject ) : BitmapData //Fonction permettant de capturer une partie d'un Display Objetc
{
if ( bd )
{
bd = null;
}
var monRectangle:Rectangle = new Rectangle();
monRectangle.x=0;
monRectangle.y=0;
monRectangle.height=photo.loaderTr.height;
monRectangle.width=photo.loaderTr.width;
var bd : BitmapData = new BitmapData( monCadre.width, monCadre.height, true);
//monRectangle.rect();
bd.draw( target, null, null, null, monRectangle);
return bd;
}
var i:Number=1;
var fileRef:FileReference = new FileReference();
function saveImage(e:MouseEvent):void{
var encoder:JPGEncoder = new JPGEncoder();
var ba:ByteArray = encoder.encode(getBitmapData(photo));
fileRef.save(ba,"capture"+i+".jpg");
i++;
}
//http://www.facebook.com/sharer.php?u=http://www.monsite.com
/*function partageImage(e:MouseEvent):void {
var encoder:JPGEncoder = new JPGEncoder();
var ba:ByteArray = encoder.encode(getBitmapData(photo) );
var url:String = "http://www.facebook.com/sharer.php?u=ba";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}*/ |
Partager