目前,我们的一个团队遇到了一个非常奇怪的现象:在操纵MovieClip的z属性并改变舞台质量之后,嵌套MovieClip的一些事件监听器似乎消失了(或者至少不再对正确的事件做出反应).
这个问题也只出现在同时进行,改变舞台质量和操纵zproperty时.
这是一个简单的类,演示了这个问题:
package { import flash.display.StageScaleMode; import flash.display.StageAlign; import flash.display.Graphics; import flash.display.MovieClip; import flash.display.StageQuality; import flash.events.MouseEvent; public class StageQualityTestDemo extends MovieClip { private static const OVER_COLOR:uint = 0x13ff37; private static const OUT_COLOR:uint = 0x000000; private static const BACK_COLOR:uint = 0xdeadc0de; private var _qualitySetting:int = 0; private var _zoom:Number = 0.0; private var _mainsprite:MovieClip = new MovieClip(); private var _button:MovieClip = new MovieClip(); public function StageQualityTestDemo() { initDemo(); } private function initDemo():void { this.addChild(_mainsprite); _mainsprite.addChild(_button); this.stage.addEventListener(MouseEvent.MOUSE_WHEEL,handleMouseWheel); stage.quality = StageQuality.LOW; stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; drawButtonCircle(OUT_COLOR); drawMainBackground(BACK_COLOR); _button.addEventListener(MouseEvent.MOUSE_OVER,handleMouSEOver); _button.addEventListener(MouseEvent.MOUSE_OUT,handleMouSEOut); } private function handleMouSEOver(event:MouseEvent):void { drawButtonCircle(OVER_COLOR); } private function handleMouSEOut(event:MouseEvent):void { drawButtonCircle(OUT_COLOR); } private function drawMainBackground(color:uint):void { var g:Graphics = _mainsprite.graphics; g.clear(); g.beginFill(color); g.drawRect(0,500,500); g.endFill(); } private function drawButtonCircle(color:uint):void { var g:Graphics = _button.graphics; g.clear(); g.beginFill(color); g.drawCircle(250,250,50); g.endFill(); } private function handleMouseWheel(event:MouseEvent):void { var motion:Number = event.delta * 5; _zoom += motion; _mainsprite.z = _zoom; if (_zoom < 0 && _qualitySetting != 0 ) { _qualitySetting = 0; trace("setting LOW"); stage.quality = StageQuality.LOW; } if (_zoom > 100 && _qualitySetting == 0 ) { _qualitySetting = 1; trace("setting HIGH"); stage.quality = StageQuality.HIGH; } } } }
任何人都可以给我一个指针在这里发生了什么?为什么_button上的eventlisteners在缩小时停止工作并且舞台质量为HIGH但在放大并且舞台质量低时再次工作?救命?任何人?
[更新]
基于@Amy Blankenship的建议,我添加了一些跟踪语句.结果是willTrigger()和hasEventListener()都报告为true,但仍未调用处理函数.
代码更改:
[...] private var _counter:int; [...] private function initDemo():void { this.addChild(_mainsprite); _mainsprite.addChild(_button); this.stage.addEventListener(MouseEvent.MOUSE_WHEEL,handleMouseWheel); this.stage.addEventListener(MouseEvent.MOUSE_MOVE,handleMouseMove); stage.quality = StageQuality.LOW; stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; drawButtonCircle(OUT_COLOR); drawMainBackground(BACK_COLOR); _button.addEventListener(MouseEvent.MOUSE_OVER,handleMouSEOver); _button.addEventListener(MouseEvent.MOUSE_OUT,handleMouSEOut); } private function handleMouseMove(event:MouseEvent):void { if (_counter++ % 50 == 0) { trace("_button.willTrigger(MouseEvent.MOUSE_OVER): " + _button.willTrigger(MouseEvent.MOUSE_OVER)); trace("_button.willTrigger(MouseEvent.MOUSE_OUT): " + _button.willTrigger(MouseEvent.MOUSE_OVER)); trace("_button.hasEventListener(MouseEvent.MOUSE_OVER): " + _button.hasEventListener(MouseEvent.MOUSE_OVER)); trace("_button.hasEventListener(MouseEvent.MOUSE_OUT): " + _button.hasEventListener(MouseEvent.MOUSE_OUT)); } } private function handleMouSEOver(event:MouseEvent):void { trace("handleMouSEOver"); drawButtonCircle(OVER_COLOR); } private function handleMouSEOut(event:MouseEvent):void { trace("handleMouSEOut"); drawButtonCircle(OUT_COLOR); } [...]
跟踪输出:
_button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true // moving the mouse over and off _button handleMouSEOver handleMouSEOut _button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true // zooming out; handler methods no longer called setting HIGH _button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true _button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true _button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true _button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true // zooming back in; handler methods called again setting LOW handleMouSEOver handleMouSEOut _button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true handleMouSEOver _button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true handleMouSEOut _button.willTrigger(MouseEvent.MOUSE_OVER): true _button.willTrigger(MouseEvent.MOUSE_OUT): true _button.hasEventListener(MouseEvent.MOUSE_OVER): true _button.hasEventListener(MouseEvent.MOUSE_OUT): true handleMouSEOver handleMouSEOut
[/更新]
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。