I’ve got a sprite object that gets a custom shape loaded into it, that gets used as a mask so as to cut out a custom shape from an image that is loaded in with a loader object – The loader(loada) and shape(lines) objects are both children of the sprite object – I’ve added code to save out the image from beneath the mask but when the save function is called nothing is saved out, and no errors are thrown.
function save(evt:MouseEvent):void{
//Create random number from current date/time to name image created
var imgID:Number= new Date().getTime()
//Matrix to holder the area to be cropped
var maskRect = loada.mask.getBounds(lines);
//Matrix of image to be cropped
var imgMatrix= loada.mask.transform.matrix;
//Cropped image
var myCroppedImage:Bitmap = cropImage(maskRect, imgMatrix, loada.mask.width, loada.mask.height, loada.mask );
//Get new matrix of cropped image
var m:Matrix = myCroppedImage.transform.matrix;
var urlLoader:URLLoader = new URLLoader();
//Set jpg quality of the image to be export 1-100
var myEncoder:JPGEncoder = new JPGEncoder(80);
//Create jpg to be exported
var jpgSource:BitmapData = new BitmapData (loada.mask.width, loada.mask.height);
jpgSource.draw(myCroppedImage, m);
//Create byte array to hold jpg data
var byteArray:ByteArray = myEncoder.encode(jpgSource);
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
trace(imgID);
//Send image to the server to be saved
var saveJPG:URLRequest = new URLRequest("save_image.php?r="+imgID);
saveJPG.requestHeaders.push(header);
saveJPG.method = URLRequestMethod.POST;
saveJPG.data = byteArray;
trace(saveJPG);
}
//Crop image
function cropImage( rect, matrix, _width:Number, _height:Number, displayObject:DisplayObject):Bitmap {
//Create cropped image
var croppedBitmap:Bitmap = new Bitmap( new BitmapData( _width, _height ), PixelSnapping.ALWAYS, true );
croppedBitmap.bitmapData.draw(displayObject, matrix , null, null, rect, true );
return croppedBitmap;
}
From what you’ve posted here, it looks like you’re not calling the “load” function: