Crop bitmapdata under mask to create new bitmap AS3

So you want to be able to crop an image based on what is viewable through the mask and then saved that cropped image out to a new file. For two days I played about with code to trying to get this to work. The main problem for me was that the image would be dragged about underneath the mask. This was proving a bit confusing for me in getting the coordinates to crop from. Well thankfully I was able to get it to work the way I wanted. So now that I have it working I thought I would share the code as whilst doing research for a solution I didn’t find anything of real use.

  1. function toCrop(e:Event):void {
  2.  //Matrix to holder the area to be cropped
  3.  var maskRect =mcHolder.mcMask.getBounds(mcHolder);
  4.  //Matrix of image to be cropped
  5.  var imgMatrix= mcHolder.mcImg.transform.matrix;
  6.  //Cropped image
  7.  var myCroppedImage:Bitmap = crop(maskRect, imgMatrix, mcHolder.mcMask.width, mcHolder.mcMask.height,mcHolder.mcImg );
  8.  addChild( myCroppedImage );
  9. }
  11. function crop( rect, matrix, _width:Number, _height:Number, displayObject:DisplayObject):Bitmap {
  12.  //Create cropped image
  13.  var croppedBitmap:Bitmap = new Bitmap( new BitmapData( _width, _height ), PixelSnapping.ALWAYS, true );
  14.  croppedBitmap.bitmapData.draw(displayObject, matrix , null, null, rect, true );
  15.  return croppedBitmap;
  16. }

Here is an example:
Drag the image around then click “crop image”

Get Adobe Flash player

Source example:

Posted in Flash AS3, Flash general | Tagged , , , , , , , , , | 9 Comments

Youtube chromeless player flash source

Following on from my recent post ‘Youtube chromeless player example‘ I’ve finally found the time to get this example source put up available for download.

Click to view Youtube chromelss player AS3 example

So here’s the brief.
The raw code for the Youtube API can be found here. The API is available in both AS2 and AS3. This is a basics you need to get started creating your own chromeless player example in AS3. You can download an sample AS2 version fla from here. You can of course skip this and go ahead and download my moded AS3 version of the chromeless player and hack it to fit your own needs. In my example I’ve set it up so that you can set set the video id in flash embed params and on url like here: If no id is found then flash will load a default video id already set inside the swf.

The source is fully commented and includes both the fla file and html embed page to get you on your way.

Posted in Flash AS3, Flash CS3 components | Tagged , , , , , , | 15 Comments

New Dope awards

It’s been a hard graft over the past few months and we finally find ourselves at a point where we are happy to get all these updates live.  After 10 years of awarding the worlds best Flash websites, Dope is changing to create an amazing new resource of not just websites , but now the worlds best 3D Artists, 3D Animators and Photographers.

DopeAwards image

Dope will now be a site of 4 flavours, with each category complimenting and inspiring the others.

As well as the 4 award programs we are also adding a whole host of new features. You will start to see these new features added to the website shortly after the first launch.

We hope you enjoy the website and content.

Posted in Flash general, What i am upto | Tagged , , , , , | Leave a comment