AS3:自定义事件传播
我正在尝试将一系列外部加载的 swf 放在一起投影仪,我的一般问题将尽可能简短。
如果加载到 ctrl
的外部 swf(创作期间放置在舞台上的 MovieClip 实例)的第一帧和最后一帧:
dispatchEvent(new Event("FIRST_FRAME")); // in the first frame, and:
dispatchEvent(new Event("LAST_FRAME")); // in the last frame
那么 - 是否应该在 ctrl 容器内“听到”这些事件?目前
,我似乎只能监听加载内容中的那些事件,而不是“更高”,我的意思是 - 如果我在加载器完整监听器中说:
mc:MovieClip = MovieClip(e.currentTarget.content);
mc.addEventListener("LAST_FRAME", function(){ // something });
那么会听到事件,但当我说时则不会:
ctrl.addEventListener("LAST_FRAME", function(){ // something });
后者似乎更强大,因此我正在努力让它发挥作用,但我想我错过了一些课程;-) 有人经历过这个吗?我的方法正确还是应该采取另一条路?
大家干杯。
I'm trying to put together a projector of a sequence of externally loaded swfs and my general question will be as short as it can be.
If an external swf loaded into ctrl
(an instance of MovieClip placed on stage during authoring) has in its first and last frames:
dispatchEvent(new Event("FIRST_FRAME")); // in the first frame, and:
dispatchEvent(new Event("LAST_FRAME")); // in the last frame
then - should those events be "heard" within the ctrl container?
At present I only seem to be able to listen to those events within the loaded content, not "higher", I mean - if I say in the loader complete listener:
mc:MovieClip = MovieClip(e.currentTarget.content);
mc.addEventListener("LAST_FRAME", function(){ // something });
then the events are heard, but not when I say:
ctrl.addEventListener("LAST_FRAME", function(){ // something });
The latter seems to be more robust, therefore I'm struggling to have it work, but I guess I've been missing out some lessons ;-)
Has anyone been through this? Is my approach correct or should I take another path?
Cheers everyone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在分派事件时将 bubbles 选项设置为 true,您可以让
crtl
显示对象接收从外部 swf 分派的事件。查看以下示例,其中 SWFB.swf 加载到 SWFA.swf:SWFB:
SWFA:
SWFB.swf 在添加到舞台后 5 秒调度
Timer
事件。当它调度事件时,气泡和可取消选项设置为 true。在 SWFA.swf 中,SWFB.swf 被加载到其中,然后添加到名为
container
的显示对象容器中。然后,向容器添加一个事件侦听器,用于侦听要调度的 SWFB.swf 中的Timer
事件。当它被调度时,onContainerTimerComplete()
事件处理程序会调用 Timer 事件的stopPropagation()
方法来(如其名称所示)停止事件的传播。You can get your
crtl
display object to recieve the event dispatched from your external swf by setting the bubbles option to true when dispatching your event. Look at the following example where SWFB.swf is loaded into SWFA.swf:SWFB:
SWFA:
SWFB.swf dispatches a
Timer
event 5 seconds after it's added to the stage. When it dispatches the event the bubbles and cancelable options are set to true.In SWFA.swf the SWFB.swf is loaded into it and then added to a display object container called
container
. Then an event listener is added to container that listens for theTimer
event from SWFB.swf to be dispatched. When it's dispatched theonContainerTimerComplete()
event handler invokes the Timer event'sstopPropagation()
method to(as its name suggests) stop the propagation of the event.