flash - Flash AS3中的dispatchEvent是什么?

标签 flash actionscript-3 actionscript actionscript-2

大家好,我想知道 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/

相关文章:

flash - 通过 mxml 中的函数传递值?

apache-flex - 当 Flex 应用程序无法以指定的帧速率运行时会发生什么?

javascript - ExternalInterface.addCallback 不起作用

javascript - 防止 iframe 中的恶意 Flash 广告将用户重定向到顶部位置

actionscript-3 - 使用 socket.io 将数据从 flash 发送到 node.js 服务器

flash - AS3 : Does `FullScreenEvent` temporarily add things to the display list?

actionscript-3 - 是否有一个好的用于 actionscript 的字符串复数库?

ios - 单词拼写建议工具提示以纵向垂直显示

javascript - 使用 HTML5 文件 API 上传 swf 并获取宽度和高度

apache-flex - 如何为我的 Flash 项目使用 crossdomain.xml...?