# BitmapData copyPixels for an eraser, please help!

**URL:** <https://forum.kirupa.com/t/bitmapdata-copypixels-for-an-eraser-please-help/297040>\
**Category:** flash\
**Created:** [September 24, 2009, 4:24pm UTC](https://forum.kirupa.com/t/bitmapdata-copypixels-for-an-eraser-please-help/297040 "2009-09-24T16:24:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricochet2](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@Ricochet2](https://forum.kirupa.com/u/Ricochet2)\
**Post date:** [September 24, 2009, 4:24pm UTC](https://forum.kirupa.com/t/bitmapdata-copypixels-for-an-eraser-please-help/297040/1 "2009-09-24T16:24:48Z")

</div>

i have the following code:

```auto
newBG.addEventListener(MouseEvent.MOUSE_MOVE, nm2);
  function nm2(e:Event):void
  {
   var sourceData:BitmapData = new BitmapData(500,400);
   sourceData.draw(bg);
   var sourceB:BitmapData = new BitmapData(100,100);
   var sourceRect:Rectangle = new Rectangle(newBG.mouseX, newBG.mouseY,100,100);
   var destP:Point = new Point(newBG.mouseX, newBG.mouseY);
   sourceB.copyPixels(sourceData, sourceRect,destP);
   trace("sourceRect: " + sourceRect + " destP: " + destP);
   var newB:Bitmap = new Bitmap(sourceB);
   newBG.addChild(newB);
   newB.x = newBG.mouseX;
   newB.y = newBG.mouseY;
  }
  newBG.addEventListener(MouseEvent.MOUSE_UP, nu2);
  function nu2(e:Event):void
  {
   newBG.removeEventListener(MouseEvent.MOUSE_MOVE, nm2);
   trace(newBG.numChildren);
  }

```

this code is supposed to allow me to “erase” lines i have drawn on an empty movieclip above a movieclip with an image in it.  
basically i let the user draw on the image, and i want them to be able to erase stuff, so i am trying to get it to use copyPixels to get the pixels of the image below and basically stamp it over the lines that were drawn. but when i run this code, the pasted data is white, unless i move the mouse to the top left corner, then it shows a square of the image from below, but anywhere else it just shows a white box.  
Can anyone see anything obvious in my code?  
Thanks in advance,  
Dave
