I just wanted to follow up in case my last
post wasn’t totally clear. JesterXL said:
> > I usually do:
> >
> > dispatchEvent({type:
"someEvent", target: this});
What I wanted to make sure I pointed out is
that Flex will set the target property to ‘this’ (the object calling
dispatchEvent) when the event gets broadcast, overwriting any value you may set.
So although this actually shows up in some of the doc examples, don’t do
it, it doesn’t work – it may have “seemed” to work, but
only coincidentally because ‘this’ is generally what you want.
You know, I also find the behavior not
exactly intuitive because of semantic reasons. If you think of ‘target’
as meaning the component upon which an event occurred, then this value should
be preserved up the chain; in any case, I think target is a poor naming choice.
An event broadcaster is a ‘source,’ like in Java, or something
along those lines. For a listener receiving a notification, source ought to
point to the broadcasting object, even if it is just a middle link in what is a
chain of listeners. Target should be a value that refers to a component and is
set only once and preserved up the chain.... Or something along these lines….
;-)
Tony
tony pujals| senior engineer | Yahoo!
SiteBuilder
p. 408.349.6284 | e. [EMAIL PROTECTED] |
y!id tonypujals
From: Tony Pujals
Sent: Wednesday, November 23, 2005
11:06 AM
To: '[email protected]'
Subject: RE: [flexcoders] event
bubbling Flex 1.5
So funny – this thread just caught my
eye because I just had to deal with the very same issue.
When you call dispatchEvent, the target
property is always overridden. Although I have seen a few erroneous examples,
the docs tell you not to set the target property in the event object because it
will be explicitly set to refer to the object that is dispatching the event.
Therefore, the original “target” will be lost.
I bubble up my events through chaining (for
example, a ThemeManager that propagates theme changes that propagates scheme
changes that propagates individual style (font and color) changes), but I
preserve the original event with a rootEvent property. The chain of handlers
continue to add this property to the new event that is getting dispatched up
the chain, preserving the value that each listener receives.
I should point out that athough preserving
the original event is useful, each listener in the chain generally needs to add
other context aside from just “bubbling” up the original event. The
ultimate listener can’t do much with the rootEvent object (eg, a font
style), without the additional context added by the listeners in the change
(for example, current theme : page title scheme : new font style).
-Tony
tony pujals| senior engineer | Yahoo!
SiteBuilder
p. 408.349.6284 | e. [EMAIL PROTECTED] |
y!id tonypujals
helps to actually attach the
file, eh? sorry about the traffic...I
need some of that coffee now too Jesse.
DK
On 11/23/05, Douglas Knudsen
<[EMAIL PROTECTED]> wrote:
> lol!
>
> Ok, I attached a sample in a zip, hope it
stays attached. In it I
> have a A, B, C as an example of this thread
discussion. You can see
> that the final capture of the event in A loses
the original target.
> upon a suggestion elsewhere, I tried
'chaining' the events by catching
> the event in B and re-dispatching it.
This still messed with the
> target property of the event object.
Seems have to add this as a
> extra property in the original event.
>
> Jeff, looking at your evenmanger class now to
see if I can use this.
>
> DK
>
> On 11/23/05, JesterXL
<[EMAIL PROTECTED]> wrote:
> > ...er, sorry, C. 2nd cup of coffee
hasn't kicked in...
> >
> > ----- Original Message -----
> > From: "JesterXL"
<[EMAIL PROTECTED]>
> > To: <[email protected]>
> > Sent: Wednesday, November 23, 2005 12:09
PM
> > Subject: Re: [flexcoders] event bubbling
Flex 1.5
> >
> >
> > I usually do:
> >
> > dispatchEvent({type:
"someEvent", target: this});
> >
> > Where this points to the component
dispatching the event. So, if A wants to
> > know who dispatched the event:
> >
> > function someEvent(o)
> > {
> > trace(o.target);
// this is A
> > }
> >
> > ----- Original Message -----
> > From: "Douglas Knudsen"
<[EMAIL PROTECTED]>
> > To: <[email protected]>
> > Sent: Wednesday, November 23, 2005 11:52
AM
> > Subject: Re: [flexcoders] event bubbling
Flex 1.5
> >
> >
> > drat! I read your blog entry on
this too, forgot about it. Ok, in
> > my scenario below, I have A catching the
event dispatched in C. But
> > the target in the event still points to
B the middleman. I need A to
> > be able to be able to reference C in the
event. Is the only way to
> > add a reference to C in the event
dispatch in C?
> >
> > DK
> >
> > On 11/23/05, JesterXL
<[EMAIL PROTECTED]> wrote:
> > > It IS supported:
> > > http://www.jessewarden.com/archives/2005/11/event_bubbling.html
> > >
> > > ----- Original Message -----
> > > From: "Douglas Knudsen"
<[EMAIL PROTECTED]>
> > > To: <[email protected]>
> > > Sent: Wednesday, November 23, 2005
11:29 AM
> > > Subject: [flexcoders] event
bubbling Flex 1.5
> > >
> > >
> > > not supportted I know, how to work
around?. Say I have 3 components
> > > A,B, and C. B is a child of A
and C is a child of B, each child among
> > > children possibly. Now,
if C fires an event called fooEvent, I can
> > > get A to catch it, but the
event.target points to B not C. The way I
> > > worked around this was in B I
caught the event then re-broadcast it so
> > > that A could catch it. In the
re-broadcast I added a reference to C
> > > in the event. How else can I
'bubble' up an event?
> > >
> > >
> > > --
> > > Douglas Knudsen
> > > http://www.cubicleman.com
> > > this is my signature, like it?
> > >
> > >
> > >
> > > --
> > > Flexcoders Mailing List
> > > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Flexcoders Mailing List
> > > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > --
> > Douglas Knudsen
> > http://www.cubicleman.com
> > this is my signature, like it?
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>
> --
> Douglas Knudsen
> http://www.cubicleman.com
> this is my signature, like it?
>
--
Douglas Knudsen
http://www.cubicleman.com
this is my signature, like it?
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
YAHOO! GROUPS LINKS