gpt4 book ai didi

flash - Flash AS3中的dispatchEvent是什么?

转载 作者:行者123 更新时间:2023-12-04 05:05:32 30 4
gpt4 key购买 nike

大家好,我想知道 AS3 中的 dispatchEvent 是什么。
谷歌搜索时没有任何想法。 :(
所以请帮帮我

编辑1:

public static  const SET_VOLUME:String = "setVolume";

private function onclick(evt:MouseEvent):void {
soundClip.scaleX = 0;
dispatchEvent(new Event(SET_VOLUME));

}

这是什么意思? (

最佳答案

一个例子可能有帮助吗?如果您具有Flash IDE,请在时间轴中尝试以下操作:

var ball:Shape = new Shape();
ball.graphics.beginFill(0xFF0000);
ball.graphics.drawCircle(0, 0, 30);
ball.graphics.endFill();
addChild(ball);

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
addEventListener("myCustomEvent", myCustomEventListener);

function mouseMoveListener(event:MouseEvent):void
{
dispatchEvent(new Event("myCustomEvent"));
}

function myCustomEventListener(event:Event):void
{
ball.x = stage.mouseX;
ball.y = stage.mouseY;
}

该代码演示了addEventListener和dispatchEvent是如何对应的。 MOUSE_MOVE事件是在内部调度的,但是您可以使用dispatchEvent像MOUSE_MOVE一样调度自己的事件。

这段代码中发生的事情是,从舞台上检测到MOUSE_MOVE,但是您没有在mouseMoveListener中处理该事件,而是调度了另一个事件(称为myCustomEvemt),该事件在myCustomEventListener中处理。它的工作方式与MOUSE_MOVE事件类似,只是您调度了该事件而不是Flash Player。

希望这可以帮助。

关于flash - Flash AS3中的dispatchEvent是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1855908/

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