这个计划非常简单:使用MouseEvent.CLICK隐藏/显示雪碧。第一个点击应该使它消失,第二个使它再次可见。
实际发生的事情真的很奇怪,因为当alpha设置为1时(除非我放大或打开“设置”菜单),雪碧就看不到了。下面是一个例子: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的alpha值(在真α值中),我确实成功地使它工作起来,但不使用0。为什么会发生这种情况?
编辑
由于我确定了这个错误可能是由我的IDE引起的,所以我也在FlashDevelop社区请求帮助(参见链接注释)。
发布于 2015-07-10 18:21:21
经过多次测试(在windows 7上使用firefox、chrome和IE ),我可以确认“问题”(至少是异常行为)与以下因素有关:
MovieClip、Sprite或Shape (和其他一些对象)。wmode (使用时):直接和gpu。我认为这就像Flash“忽略”呈现对象可能是因为性能问题(当它的alpha值从第一次为0时不呈现对象),因为有时当我使用Button或CheckBox时.然后我翻滚它,一个Event.RENDER事件在对象上触发,并且代码只工作一次。我还看到了在同一时间对两个对象执行代码时的工作情况.
因此,为了避免这种行为,可以使用cacheAsBitmap属性:
object.cacheAsBitmap = true;在设置ColorTransform时,还可以使用alpha对象:
object.transform.colorTransform = new ColorTransform(1, 1, 1, (object.alpha == 1 ? 0 : 1), 0, 0, 0, 1);或者简单地说,避免使用direct或gpu模式.
希望能帮上忙。
https://stackoverflow.com/questions/31224011
复制相似问题