Highlighted

Why an area erazed is clickable ?

Engaged ,
Feb 16, 2019

Copy link to clipboard

Copied

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

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.

TOPICS
Development

Views

341

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Why an area erazed is clickable ?

Engaged ,
Feb 16, 2019

Copy link to clipboard

Copied

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

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.

TOPICS
Development

Views

342

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 16, 2019 0
Engaged ,
Feb 16, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 16, 2019 0
Advocate ,
Feb 18, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 18, 2019 0
pol2095 LATEST
Engaged ,
Feb 22, 2019

Copy link to clipboard

Copied

Thanks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 22, 2019 0