  | |  | EventDispatcher 1 frame delay | EventDispatcher 1 frame delay
2004-02-17 - By Tatsuo Kato
Back I think it 's the loading order of the event dispatcher and the listener.
Either of them has to be loaded earlier than the other, if they are both
movieclips.
In order to add a listener to the event dispatcher, the event dispatcher
has to be loaded earlier than the listener. So, when dispatchEvent is executed
in its constructor, the listener is not loaded yet.
As a test, if you add this line to the BasicClass constructor,
this.addEventListener( "myEvent ", this);
and define a event handler inside the BasicClass as follows,
function myEvent () {
trace( "myEvent called ");
}
then it works as expected without resort to onEnterFrame.
Cheers,
--
Tatsuo Kato
http://tatsuokato.com
-- -- Original Message -- --
From: "Muzak " <p.ginneberge@(protected) >
To: <flashcoders@(protected) >
Sent: Tuesday, February 17, 2004 5:25 PM
Subject: [Flashcoders] EventDispatcher 1 frame delay
> I just noticed that when using EventDispatcher, it takes one frame to get it to work properly.
>
> The following doesn 't work:
>
> import mx.events.EventDispatcher;
> class BasicClass extends MovieClip {
> private static var __eventInit = EventDispatcher.initialize(BasicClass.prototype);
> var addEventListener:Function;
> var removeEventListener:Function;
> var dispatchEvent:Function;
> //
> function BasicClass() {
> init();
> }
> function init() {
> dispatchEvent({type: "init "});
> }
>
> while the following does:
>
> import mx.events.EventDispatcher;
> class BasicClass extends MovieClip {
> private static var __eventInit = EventDispatcher.initialize(BasicClass.prototype);
> var addEventListener:Function;
> var removeEventListener:Function;
> var dispatchEvent:Function;
> //
> function BasicClass() {
> this.onEnterFrame = function(){
> init();
> delete this.onEnterFrame
> }
> }
> function init() {
> dispatchEvent({type: "init "});
> }
>
>
> Anyone know how to get it to work properly without using onEnterFrame?
> In other words, is there a way to avoid the frame delay?
>
> kind regards,
> Muzak
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
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:104466
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |