如何将遮罩切换到 Flex 中的组(适用于 BorderContainer)
这是我的测试应用程序:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="initApp()"
width="800" height="800">
<fx:Script>
<![CDATA[
protected function initApp():void {
spe.graphics.clear();
spe.graphics.lineStyle(1,0xff9900);
spe.graphics.beginFill(0xff9900,0.5);
spe.graphics.drawRect(-50,-75,100,100);
}
]]>
</fx:Script>
<s:CheckBox id="showMask" label="Show Mask"/>
<s:Group id="graphArea" width="500" height="500"
horizontalCenter="0" verticalCenter="0"
mask="{(showMask.selected) ? maskCanvas : null}">
<s:SpriteVisualElement id="spe"/>
<s:SkinnableContainer id="maskCanvas" alpha="0" width="100%" height="100%"/>
</s:Group>
</s:Application>
我希望在选中复选框时应用掩码,在未选中复选框时将其删除。但这似乎不起作用。
然而,当你更改为 时,它就像一个魅力。谁能向我解释为什么?
注意:在我的实际应用程序中,我将其应用到一个扩展 SkinnableComponent 的组件的皮肤中,该组件不能使用 BorderContainer,因此解决方案会很好。
Here's my test application:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="initApp()"
width="800" height="800">
<fx:Script>
<![CDATA[
protected function initApp():void {
spe.graphics.clear();
spe.graphics.lineStyle(1,0xff9900);
spe.graphics.beginFill(0xff9900,0.5);
spe.graphics.drawRect(-50,-75,100,100);
}
]]>
</fx:Script>
<s:CheckBox id="showMask" label="Show Mask"/>
<s:Group id="graphArea" width="500" height="500"
horizontalCenter="0" verticalCenter="0"
mask="{(showMask.selected) ? maskCanvas : null}">
<s:SpriteVisualElement id="spe"/>
<s:SkinnableContainer id="maskCanvas" alpha="0" width="100%" height="100%"/>
</s:Group>
</s:Application>
I would expect the mask to be applied when the checkbox is selected, and removed when it issin't. But it doesn't seem to work.
However, when you change to , it works like a charm. Can anyone explain to me why?
Note: In my actual application, i'm applying this in a skin to a component that is extending SkinnableComponent which can't use BorderContainer so a solution to this would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在该组的 mask 属性的文档中说道:
“设置蒙版。该蒙版将被添加到显示列表中。该蒙版不得已位于显示列表中或元素数组中。”
尝试将您的蒙版移至,它应该可以正常工作。
希望这有帮助。
火焰
In the documentation for the mask property of the Group it is said:
"Sets the mask. The mask will be added to the display list. The mask must not already on a display list nor in the elements array."
Try to move your mask to and it should work properly.
Hope this helps.
Blaze