this.masker.mouseEnabled = false; //set on this.masker
那应该有效。现在,它正在拦截您的事件,然后再将其发送到容器中的其他任何内容。不是 100% 确定,但我相信面具会放在容器顶部。另一种选择是向 DisplayList 底部的 MyContainer 添加另一个屏蔽子项,并将面板添加为其同级。不过,您仍然需要在蒙版 sprite/mc 上将 mouseEnabled 和 mouseChildren 设置为 false。
package
{
import flash.display.Shape;
import flash.display.Sprite;
public class MyContainer extends Sprite
{
protected var masker : Shape = null;
protected var panel:MyPanel;
public function MyContainer()
{
this.masker = new Shape();
this.masker.graphics.clear();
this.masker.graphics.beginFill( 0x00ff00 );
this.masker.graphics.drawRect(0, 0, 1, 1); // 1x1 pixel.
this.masker.graphics.endFill();
addChild( this.masker );
this.panel = new MyPanel();
this.addChild(panel);
this.mask = this.masker;
}
// called by it's parent when the stage is resized.
public function resize( width : Number, height : Number ) : void
{
// set the mask to half the size of the stage.
this.masker.width = width / 2;
this.masker.height = height / 2;
// set the panel to half the size of the stage.
}
}
}
-
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class MyPanel extends Sprite
{
public function MyPanel()
{
this.graphics.beginFill(0xFF0000)
this.graphics.drawRect(0,0,10,10);
this.addEventListener(MouseEvent.MOUSE_OVER, this.handleMouseOver)
this.addEventListener(MouseEvent.MOUSE_OUT, this.handleMouseOut)
}
public function handleMouseOver(event:Event):void
{
this.graphics.clear();
this.graphics.beginFill(0x00FF00)
this.graphics.drawRect(0,0,10,10);
}
public function handleMouseOut(event:Event):void
{
this.graphics.clear();
this.graphics.beginFill(0xFF0000)
this.graphics.drawRect(0,0,10,10);
}
}
}