A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: erease with cursor

  1. #1
    Junior Member
    Join Date
    Feb 2004
    Posts
    3

    erease with cursor

    I have a flash movie in which I want to allow the user to either erase a layer (using their mouse) to reveal the layer underneath, or to have the mouse draw a mask, to reveal the layer underneath.

    Is one method easier than the other? Any good samples out there that will show how to simply do that?

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    I don't think there's anyway to dynamically erase in actionscript, but
    creating a mask which reveals the layer underneath is doable. Here's how.

    Let's say you've already created a mask movie clip called myMask.

    Basically you would setup the mask movie to listen to mouse events:

    Code:
    Mouse.addListener(myMask);
    then add some functions to get the mask
    to draw at the current mouse position
    when the mouse is moved, and the button is down...

    Code:
    myMask.onMouseDown = function()
    {
      this.isErasing = true;
    }
    
    myMask.onMouseDown = function()
    {
      this.isErasing = false;
    }
    
    
    myMask.onMouseMove = function()
    {
       if (! this.isErasing)
           return;
       var mx = this._xmouse;
       var my = this._ymouse;
       // Draw something at mx,my.
       // for a mask it must be a fill,
       // not just lines.
       // it will look nicer if you draw a circle using curveTo, but will also be slower...
    
       var eWidth = 10; // radius of eraser
    
       this.moveTo(mx-eWidth,my-eWidth);
       this.beginFill(0,100);
       this.lineTo(mx+eWidth,my-eWidth);
       this.lineTo(mx+eWidth,my+eWidth);
       this.lineTo(mx-eWidth,my+eWidth);
       this.lineTo(mx-eWidth,my-eWidth);
       this.endFill();
    }
    The PROBLEM with this method is that the more drawing you do, the slower your movie is going to get, because all those overlapping boxes you are drawing suck CPU, until your mask does a this.clear(); (which erases the boxes).

    So it would probably be good to spend some time finding a way to optimize your eraser to draw fewer boxes...

  3. #3
    Junior Member
    Join Date
    Oct 2002
    Posts
    2
    I tried this - but I am afraid that I am struggelling. I guess I am not putting the code in the right place??
    Attached Files Attached Files
    Last edited by webwasp; 07-05-2005 at 03:30 AM.

  4. #4
    Junior Member
    Join Date
    Mar 2006
    Location
    Serbia
    Posts
    29
    I can't get it work too....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center