Mailing List
Home
Flash Pro
Extending Flash
Flash Macromedia Developer
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
EventDispatcher 1 frame delay

EventDispatcher 1 frame delay

2004-02-17       - By Phil Chung

 Back
Reply:     1     2     3     4     5     6     7     8     9     10     >>  

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

Original Message:
>From: "Tatsuo Kato " <studio@(protected) >
>To: <flashcoders@(protected) >
>Subject: Re: [Flashcoders] EventDispatcher 1 frame delay
>Date: Wed, 18 Feb 2004 03:59:02 +0900

>hm, I still don 't get your point, Muzak. Neither does Phil, it seems.
>
>It doesn 't take a frame or an interval for an object initialized with
>mx.events.EventDispatcher to be able to dispatch an event.
>It only needs a fact that a listener is registered before dispatching.
>
>And it works for me wherever it 's written, frame1 of _root or the
>component or wherever.
>In order for it to work, it just needs a listener having been registered
>before dispatching.
>
>Cheers,
>--
>Tatsuo Kato
>http://tatsuokato.com
>
>-- -- Original Message -- --
>From: "Muzak " <p.ginneberge@(protected) >
>To: <flashcoders@(protected) >
>Sent: Wednesday, February 18, 2004 3:27 AM
>Subject: Re: [Flashcoders] EventDispatcher 1 frame delay
>
>
> > Sorry about the confusion.
> > I 'm not trying to dispatch an event in the constructor.
> > That was just some sample code (with the 'init ' event) to show that it does take a frame for the EventDispatcher to work properly.
> >
> > And yes, it makes perfect sense that nothing happens before a listener is registered.
> > The thing is, you can 't tell when a listener has been registered... (not sure if that makes any sense tho).
> >
> > And in case you ever have to dispatch an event in the 'first frame ' of a component (or a Class), it won 't work.
> >
> > regards,
> > Muzak
> >
> > -- -- Original Message -- --
> > From: "Tatsuo Kato " <studio@(protected) >
> > To: <flashcoders@(protected) >
> > Sent: Tuesday, February 17, 2004 7:02 PM
> > Subject: Re: [Flashcoders] EventDispatcher 1 frame delay
> >
> >
> > > Muzak,
> > >
> > > Maybe I 'm missing something but I 'm confused as to what you are up to. ;)
> > > Why do you have to dispatch an event in the constructor of the event
> > > dispatcher object?
> > >
> > > It makes perfect sense that nothing happens when you dispatch an event
> > > before the listener is registered as a listener.
> > >
> > > Cheers,
> > > --
> > > Tatsuo Kato
> > > http://tatsuokato.com
>
>
>
>=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
>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:104520
>=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
>To unsubscribe send a blank e-mail to:
>Normal Mode: flashcoders-unsubscribe@(protected)
>Digest Mode: flashcoders-digest-unsubscrive@(protected)
>
>
>



=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
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:104526
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)