我有一个容器MovieClip,它作为内容区域需要被遮罩。当我在这个容器内使用Shape创建遮罩时,似乎无法与我在此处创建的其他容器内容进行交互,例如按钮等。
以下是我的代码(省略了所有导入等):
class MyContainer extends MovieClip
{
protected var masker : Shape = null;
protected var panel : MyPanel = null;
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(); // has buttons and stuff.
addChild( this.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.
this.panel.resize( width / 2, height / 2);
}
}
当我将遮罩(形状)添加到显示层级中时,我无法再与MyPanel中定义的任何按钮进行交互。然而,如果不将遮罩添加到显示层级中,则可以与MyPanel中的内容进行交互,但遮罩的大小/位置不正确。我猜想当遮罩未添加到显示层级中时,它位于影片的左上角(虽然我无法证明)。
如何让我的遮罩大小/位置正确,并让用户与MyPanel中的按钮进行交互?