【发布时间】:2015-07-04 18:38:35
【问题描述】:
计划非常简单:使用 MouseEvent.CLICK 隐藏/显示 Sprite。第一次点击应该让它消失,第二次让它再次可见。
实际发生的事情真的很奇怪,因为当 alpha 设置为 1 时 Sprite 不可见(除非我放大或打开“设置”菜单)。这是一个例子:http://www.fastswf.com/8BuuY14
private function doStuff(e:MouseEvent):void {
(e.target.alpha == 1) ? e.target.alpha = 0 : e.target.alpha = 1;
}
//Sprite on the left
var outter:Sprite = new Sprite(); //Container sprite (gray background)
outter.x = outter.y = 20;
outter.opaqueBackground = 0xCCCCCC;
outter.addEventListener(MouseEvent.CLICK, doStuff);
var inner:Sprite = new Sprite(); //Interactive child (red square)
inner.graphics.beginFill(0xFF0000);
inner.graphics.drawRect(0, 0, 50, 50);
var speck:Shape = new Shape(); //Reference child (tiny black square)
speck.graphics.beginFill(0x000000);
speck.graphics.drawRect(50, 50, 5, 5);
outter.addChild(inner);
outter.addChild(speck);
addChild(outter);
//Sprite on the right
var cont:Sprite = new Sprite();
cont.x = 100; cont.y = 20;
cont.graphics.beginFill(0xFF0000);
cont.graphics.drawRect(0, 0, 50, 50);
cont.addEventListener(MouseEvent.CLICK, doStuff);
addChild(cont);
通过使用等于或大于 0.0078125(在 true alpha value 中)而不是 0 的 alpha 值,我确实设法使其工作。为什么会发生这种情况?
[编辑]
由于我确定错误可能是由我的 IDE 引起的,因此我也在 FlashDevelop 社区寻求帮助(请参阅 cmets 获取链接)。
【问题讨论】:
-
如果你的精灵的 alpha 为 0,你会点击什么?那时没有可见的精灵。
-
@Vesper 显示对象alpha 设置为 0 是活动的,即使它们是不可见的,这与使用
display_object.visible = false;隐藏它不同。 -
@Stefano 我无法重现您所说的奇怪行为。尝试使用
0.0而不是0和1.0而不是1... -
@Vesper:是的。当我向 doStuff 函数添加跟踪时,显示的 alpha 值准确地反映了我预期会发生的情况,但不是视觉上的。
-
@akmozo:谢谢!我会尝试并报告。
标签: actionscript-3 alpha redraw