flash – 为什么EventListeners在操作z-property和更改stage.quality后停止工作?

目前,我们的一个团队遇到了一个非常奇怪的现象:在操纵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

[/更新]

解决方法

我发现使用stage.quality = StageQuality.MEDIUM;而不是HIGH工作. 我知道flash z转换实际上是通过将剪辑转换为位图来实现的.而且这些位图不是InteractiveObjects.我想你找到了一个flash播放器的bug. 但希望使用中等质量的缩放项目将为您提供“足够好”的质量来完成您的项目.

相关文章

  译序:JWMediaPlayer是开源的网页使用的Flash播放器。本...
    Flash编程原理都是只能将1写为0,而不能将0写成1.所...
 上传setenvgatewayip192.168.1.1;setenvserverip192.168.1...
Error:FlashDownloadFailed-"Cortex-M3"出现一般有...
jPlayer是一个用于控制和播放mp3文件的jQuery插件。它在后台...
#ifndef__FONTUPD_H__#define__FONTUPD_H__#include"sy...