3 Replies Latest reply on Sep 26, 2010 1:31 PM by kglad

    How to make a custom eraser tool using flash?

    rubesh_vp

      I did make a eraser tool. But once I begin to erase a layer, the background layer is visible. I want the layer just below the topmost layer to be visible.

       

      For eg consider 2 layers.

      Layer2 is above Layer1.

      When I perform erase on Layer2, I see the stage background.

      I want to actually see Layer1 when I erase from Layer2.

       

      Here is the code I used:

      The comment entry shows that, I have tried that possiblity.

       

      import flash.display.BitmapData;

       

      var linkageId:String = "myimage";

      var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId);

      trace(myBitmapData instanceof BitmapData);

      this.createEmptyMovieClip("mc",this.getNextHighestDepth());

      mc.attachBitmap(myBitmapData,this.getNextHighestDepth());

      this.blendMode = "layer";

      //mc.blendMode = "layer";

       

      this.createEmptyMovieClip("mc1",this.getNextHighestDepth());

      var myBitmapData1:BitmapData = new BitmapData(800,600, false, 0xFF000);

      mc1.attachBitmap(myBitmapData1,this.getNextHighestDepth());

       

      mc1.onMouseMove = function() {

      var circle_mc:MovieClip = this.createEmptyMovieClip("circle_mc", this.getNextHighestDepth());

      circle_mc._x = _xmouse-40;

      circle_mc._y = _ymouse-40;

      drawCircle(circle_mc,40,0x000000,50);

      //mc.blendMode = "layer";

      circle_mc.blendMode = "erase";

      }

       

      function drawCircle(target_mc:MovieClip, radius:Number, fillColor:Number, fillAlpha:Number):Void {

      var x:Number = radius;

      var y:Number = radius;

      with (target_mc) {

      beginFill(fillColor,fillAlpha);

      moveTo(x+radius,y);

      curveTo(radius+x,Math.tan(Math.PI/8)*radius+y,Math.sin(Math.PI/4)*radius+x,Math.sin(Math.P I/4)*radius+y);

      curveTo(Math.tan(Math.PI/8)*radius+x,radius+y,x,radius+y);

      curveTo(-Math.tan(Math.PI/8)*radius+x,radius+y,-Math.sin(Math.PI/4)*radius+x,Math.sin(Math .PI/4)*radius+y);

      curveTo(-radius+x,Math.tan(Math.PI/8)*radius+y,-radius+x,y);

      curveTo(-radius+x,-Math.tan(Math.PI/8)*radius+y,-Math.sin(Math.PI/4)*radius+x,-Math.sin(Ma th.PI/4)*radius+y);

      curveTo(-Math.tan(Math.PI/8)*radius+x,-radius+y,x,-radius+y);

      curveTo(Math.tan(Math.PI/8)*radius+x,-radius+y,Math.sin(Math.PI/4)*radius+x,-Math.sin(Math .PI/4)*radius+y);

      curveTo(radius+x,-Math.tan(Math.PI/8)*radius+y,radius+x,y);

      endFill();

      }

      }

        • 1. Re: How to make a custom eraser tool using flash?
          kglad Adobe Community Professional & MVP

          use:

           


           

           

          import flash.display.BitmapData;

           

          var linkageId:String = "myimage";

          var myBitmapData:BitmapData = BitmapData.loadBitmap(linkageId);

          trace(myBitmapData instanceof BitmapData);

          this.createEmptyMovieClip("mc",this.getNextHighestDepth());

          mc.attachBitmap(myBitmapData,this.getNextHighestDepth());


           

          this.createEmptyMovieClip("mc1",this.getNextHighestDepth());

          var myBitmapData1:BitmapData = new BitmapData(800,600, false, 0xFF000);

          mc1.attachBitmap(myBitmapData1,this.getNextHighestDepth());

          mc1.blendMode="layer"

           

          mc1.onMouseMove = function() {

          var circle_mc:MovieClip = this.createEmptyMovieClip("circle_mc", this.getNextHighestDepth());

          circle_mc._x = _xmouse-40;

          circle_mc._y = _ymouse-40;

          drawCircle(circle_mc,40,0x000000,50);

          //mc.blendMode = "layer";

          circle_mc.blendMode = "erase";

          }

           

          function drawCircle(target_mc:MovieClip, radius:Number, fillColor:Number, fillAlpha:Number):Void {

          var x:Number = radius;

          var y:Number = radius;

          with (target_mc) {

          beginFill(fillColor,fillAlpha);

          moveTo(x+radius,y);

          curveTo(radius+x,Math.tan(Math.PI/8)*radius+y,Math.sin(Math.PI/4)*radi us+x,Math.sin(Math.PI/4)*radius+y);

          curveTo(Math.tan(Math.PI/8)*radius+x,radius+y,x,radius+y);

          curveTo(-Math.tan(Math.PI/8)*radius+x,radius+y,-Math.sin(Math.PI/4)*ra dius+x,Math.sin(Math.PI/4)*radius+y);

          curveTo(-radius+x,Math.tan(Math.PI/8)*radius+y,-radius+x,y);

          curveTo(-radius+x,-Math.tan(Math.PI/8)*radius+y,-Math.sin(Math.PI/4)*r adius+x,-Math.sin(Math.PI/4)*radius+y);

          curveTo(-Math.tan(Math.PI/8)*radius+x,-radius+y,x,-radius+y);

          curveTo(Math.tan(Math.PI/8)*radius+x,-radius+y,Math.sin(Math.PI/4)*rad ius+x,-Math.sin(Math.PI/4)*radius+y);

          curveTo(radius+x,-Math.tan(Math.PI/8)*radius+y,radius+x,y);

          endFill();

          }

          }

          • 2. Re: How to make a custom eraser tool using flash?
            rubesh_vp Level 1

            hey tanx a lot.. it worked..

            gosh! y i dint i try dat b4!!