To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 02-24-2004, 05:37 PM   #1
princeee
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?
princeee is offline   Reply With Quote
Old 02-24-2004, 06:03 PM   #2
jbum
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...
__________________
jbum is offline   Reply With Quote
Old 07-04-2005, 07:42 PM   #3
webwasp
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
File Type: fla painted-mask.fla (23.0 KB, 443 views)

Last edited by webwasp; 07-05-2005 at 04:30 AM.
webwasp is offline   Reply With Quote
Old 05-17-2006, 12:08 PM   #4
mrlame
Junior Member
 
Join Date: Mar 2006
Location: Serbia
Posts: 29
I can't get it work too....
mrlame is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:18 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.