Skip to main content
Inspiring
February 16, 2019
Answered

Why an area erazed is clickable ?

  • February 16, 2019
  • 2 replies
  • 651 views

Hello,

why the area erazed is clickable ?

package

{

    import flash.display.BlendMode;

    import flash.display.Shape;

    import flash.display.Sprite;

    import flash.events.MouseEvent;

   

    public class Main extends Sprite

    {

        public function Main()

        {

            var sprite:Sprite = new Sprite();

            sprite.graphics.beginFill(0x000000);

            sprite.graphics.drawRect(0, 0, 200, 200);

            sprite.graphics.endFill();

            sprite.blendMode = BlendMode.LAYER;

            var shape:Shape = new Shape();

            shape.graphics.beginFill(0x000000);

            shape.graphics.drawRect(100, 100, 100, 100);

            shape.graphics.endFill();

            sprite.addChild(shape);

            shape.blendMode = BlendMode.ERASE;

            sprite.buttonMode = true;

            sprite.addEventListener(MouseEvent.CLICK, mouseClickOutsideHandler);

            this.addChild( sprite );

        }

       

        private function mouseClickOutsideHandler(event : MouseEvent) : void

        {

            trace( "click" );

        }

    }

}

Thanks

This topic has been closed for replies.
Correct answer ASWC

graphics objects do that work for you directly. Don't use a Shape and instead do this:

  1. sprite.graphics.beginFill(0x000000); 
  2. sprite.graphics.drawRect(0, 0, 200, 200);
  3. sprite.graphics.drawRect(100, 100, 100, 100); 

Line 3 does erase that part for you because it draws on top of existing drawn graphic with the SAME color (< important). Now that part is not clickable.

2 replies

ASWCCorrect answer
Inspiring
February 18, 2019

graphics objects do that work for you directly. Don't use a Shape and instead do this:

  1. sprite.graphics.beginFill(0x000000); 
  2. sprite.graphics.drawRect(0, 0, 200, 200);
  3. sprite.graphics.drawRect(100, 100, 100, 100); 

Line 3 does erase that part for you because it draws on top of existing drawn graphic with the SAME color (< important). Now that part is not clickable.

pol2095Author
Inspiring
February 22, 2019

Thanks

Flipline
Inspiring
February 16, 2019

Since it's using a Blend Mode, it's just a visual effect to change the alpha of that sprite, it's not really erasing anything so that area is still clickable.  If you want to prevent clicks in a cutout area, you'd need to use a mask instead.