3 Replies Latest reply on Feb 17, 2014 10:46 AM by sinious

    How to detect how much of an object has been “cleaned” ?

    aseel jaradat

      so when the player end clening simple animation start




      var lineSize:Number=40;

      var doDraw:Boolean=false;

      var resumeDrawing:Boolean=false;



      var erasableBitmapData:BitmapData = new BitmapData(600, 600, true, 0xFFFFFFFF);

      var erasableBitmap:Bitmap = new Bitmap(erasableBitmapData);

      erasableBitmap.cacheAsBitmap = true;




      Object(this).dirtyBook.cacheAsBitmap = true;

      Object(this).dirtyBook.mask = erasableBitmap;



      var eraserClip:Sprite = new Sprite();


      function initEraser():void {




      var drawnBitmapData:BitmapData = new BitmapData(600, 600, true, 0x00000000);

      var drawnBitmap:Bitmap = new Bitmap(drawnBitmapData);




      stage.addEventListener(MouseEvent.ROLL_OUT, maskOut);







      Mouse down handler

      Begin drawing


      function startDrawing(e:MouseEvent):void {







      Mouse up handler

      Stop drawing


      function stopDrawing(e:MouseEvent):void {


                resumeDrawing = false;






      Mouse out handler

      If user was drawing when they moved mouse off stage, we will need

      to resume drawing when they move back onto stage.


      function maskOut(e:Event):void {

                if (doDraw){

                          resumeDrawing = true;






      Mouse over handler

      If user's mouse if still down, continue drawing from the point where

      the mouse re-entered the stage.


      function maskOver(e:MouseEvent):void {

                if (resumeDrawing){

                          resumeDrawing = false;







      Mouse move handler


      function maskMove(e:MouseEvent):void {

                if (doDraw && !resumeDrawing){

                          // Draw a line to current mouse position


                          // Clear the drawn bitmap by filling it with a transparent color

                          drawnBitmapData.fillRect(drawnBitmapData.rect, 0x00000000);

                          // Copy our eraser drawing into the erasable bitmap

                          // (This is required to ensure the smooth alpha edges on our eraser are retained)

                          drawnBitmapData.draw(eraserClip , new Matrix(), null, BlendMode.NORMAL);

                          // Fill the erasable bitmap with a solid color

                          erasableBitmapData.fillRect(erasableBitmapData.rect, 0xFFFFFFFF);

                          // Copy the scribble bitmap to our main bitmap, with blendmode set to ERASE

                          // This erases the portion of the mask that has been drawn.

                          erasableBitmapData.draw(drawnBitmap, new Matrix(), null, BlendMode.ERASE);


                // Update after event to ensure no lag