gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:09:11 25 4
gpt4 key购买 nike

目前我们的一个团队遇到了一个非常奇怪的现象:在操纵 MovieClipz 属性并更改嵌套 的一些事件监听器的舞台质量之后MovieClips 似乎消失了(或者至少不再对适当的事件使用react)。

问题也在执行这两项操作时出现,即更改舞台质量操纵z属性。

这是一个演示问题的简单类:

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, 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 上的事件监听器在缩小且舞台质量为 HIGH 时停止工作,但在放大且舞台质量为 LOW 时再次工作?帮助?有人吗?


[更新]

根据@Amy Blankenship 的建议,我添加了更多的 trace 语句。结果是 willTrigger()hasEventListener() 都报告为真,但仍未调用处理函数。

代码更改:

[...]

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 Player 错误。但希望对缩放项目使用中级质量将使您获得“足够好”的质量来完成您的项目。

关于flash - 为什么 EventListeners 在操作 z-property 和更改 stage.quality 后停止工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7448041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com