  | |  | EventDispatcher 1 frame delay | EventDispatcher 1 frame delay
2004-02-17 - By Muzak
Back Hi Phil,
Thanx alot for clarifying.
And yes, I now see that it 's not EventDispatcher that takes a frame, but listeners added with addEventListener aren 't registered
until the Class has initialized (which takes some time, one frame).
Your solution may come in handy.
kind regards,
Muzak
-- -- Original Message -- --
From: "Phil Chung " <phil@(protected) >
To: <flashcoders@(protected) >
Sent: Tuesday, February 17, 2004 8:22 PM
Subject: Re: [Flashcoders] EventDispatcher 1 frame delay
> I don 't know if the following is good form, but I want to try to prove what Tatsuo and I are saying (ie., that EventDispatcher
itself doesn 't need a frame to work, but that it 's the process of setting up the listener that is the issue).
>
> I modified the class that you built Muzak:
>
> <code >
> import mx.events.EventDispatcher;
>
> class BasicClass extends MovieClip {
> public var listeners:Array;
> private static var __eventInit = EventDispatcher.initialize(BasicClass.prototype);
> var addEventListener:Function;
> var removeEventListener:Function;
> var dispatchEvent:Function;
>
> function BasicClass() {
> init();
> }
> function init() {
> for (var i = 0; i <listeners.length; i++) {
> addEventListener( "init ", listeners[i]);
> }
> dispatchEvent({type: "init "});
> }
> }
> </code >
>
> Then, here is what is in the Flash movie:
>
> <code >
> var handlerObject:Object = {};
> handlerObject.init= function(o) {
> trace( "init ");
> };
>
> this.attachMovie( "basic ", "basic_mc ",0,{listeners:[handlerObject]});
> </code >
>
> Again, i 'm not sure if this is good form because it requires the setting of the listeners within the dispatching class itself, but
at least it shows that EventDispatcher DOESN 'T need a frame to work.
>
> I think pretty much the only time you might want to do this is if you need an "init " event to fire when the class initializes. If
you 're firing any other type of event, you can assign the listener externally before firing the event so there won 't be any issues.
>
> Any thoughts?
>
> Phil
>
>
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104533
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |