I see.

I think the part I was missing was the fact that the class object
needed to be a child of the application to be in its display list,
instead of instantiated to a variable.

I could convert my class to a component I suppose, and place it in my
MXML but frankly I don't mind dispatching from mx..application.

I just needed to understand why I had to do it that way.

Thanks


--- In flexcoders@yahoogroups.com, "Sam Lai" <samuel....@...> wrote:
>
> The event listener attached to the Application is not reacting to the
> event fired from your custom class because your custom class instance
> is not attached to the Application DisplayList. It is just an object
> in memory. If you want the event from your custom class instance to
> bubble up to the Application, you need to add it to the Application's
> DisplayList.
> 
> The DisplayList is typically used for UI components, i.e. when you
> click a button in the UI, it fires an event and that event propagates
> up the display list.
> 
> However, you can add non-UI components to it too. Your custom class
> just needs to extend the DisplayObject class (I think - it should have
> extended EventDispatcher already). You also need to add the instance
> to the Application object by using the addChild method on the
> Application object, e.g. application.addChild(myclass);
> 
> If you declare the custom class instance in MXML, it is automatically
> added to the Application object (well, technically, only if it is a
> loaded component in the UI).
> 
> 
> 
> 2009/1/12 biosmonkey <biosmon...@...>:
> >
> > The dispatched event needs to be heard by any component, anywhere, by
> > setting an event listener for it at the application level.  So
> > bubbling up to the app is critical.
> >
> >
> > --- In flexcoders@yahoogroups.com, "Manish Jethani"
> > <manish.jethani@> wrote:
> >>
> >> On Mon, Jan 12, 2009 at 11:42 AM, biosmonkey <biosmonkey@> wrote:
> >>
> >> > In my main app, I instantiate an instance of this class.  I also
> >> > create an event listener at the application level.
> >> >
> >> > Here's the problem:
> >> >
> >> > * If I use dispatchEvent(...) inside MyClass, the event listener in
> >> > the main app never fires (the custom event *is* set to bubble)
> >>
> >> To add to Josh's response, I would say the best way to do this is to
> >> listen on the object itself.
> >>
> >>     obj = new MyClass();
> >>     obj.addEventListener(...);
> >>
> >> The events don't have to be bubbling then.
> >>
> >> Manish
> >>
> >
> >
> >
> > ------------------------------------
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Alternative FAQ location:
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
> > Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
Links
> >
> >
> >
> >
>


Reply via email to