我有一个容器 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 中的按钮进行交互?