A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How to Clear a Drawing? [Mask]

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2

    How to Clear a Drawing? [Mask]

    Hello,

    So I have a project I am working on in which I would like to teach how to cash a scratch off card. I have made the scratch and made it so it will "scratch", however my masking technique seems to not be working how it should...

    The idea is that the user would "scratch" the card and then hit "Next" after that it would load a new frame (Progress Bar would move) and then do what they need to on that frame, and so on.

    However it would seem that Flash is keeping the users "drawing" and still allows them to draw after the first frame, which is not what I want.

    First Image - Frame 1 (Before User Scratches)
    Second Image - Frame 1 (After User Scratches)
    Third Image - Frame 2 (After User Scratches)

    I am using this code to make the scratch effect:
    Actionscript Code:
    var mouseclick:Number=0;

    var mask_mc:Sprite = new Sprite();
    maskedbg_mc.mask = mask_mc;
    addChild(mask_mc);

    stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseD);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseM);
    stage.addEventListener(MouseEvent.MOUSE_UP, mouseU);

    function mouseD(event:MouseEvent):void {
    mouseclick = 1;
    }

    function mouseM(event:MouseEvent):void {
    if (mouseclick == 1) {
    mask_mc.graphics.beginFill(0x000000);
    mask_mc.graphics.drawEllipse(mouseX, mouseY, 70, 60);
    mask_mc.graphics.endFill();
    }
    }

    function mouseU(event:MouseEvent):void {
    mouseclick = 0;
    }

    Any ideas on what to do?

    Thank you!

  2. #2
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    If you would like to see it yourself: http://30dayslater.net/wp-content/up...cratchCard.swf

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    16
    Two easy steps to go about it:

    1. Once the "Next" button is clicked, remove the event listeners allowing the user
    to draw or, better yet, use a Boolean variable that can turn false and disable the
    permission to draw.

    2. To clear your canvas from any graphics, use

    Actionscript Code:
    mask_mc.graphics.clear();


    Hope that helps

  4. #4
    Senior Member
    Join Date
    Jun 2008
    Posts
    549
    Looks like my code

    Try clearing the drawings.

    mask_mc.graphics.clear();

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