"...listener in the same component that dispatches the event..." No, not
quite.   When you do Component.addEventListener(), you are telling the
current component to listen to Component for an event and run a method.

 

The declaration happens where you have the handler method, but you call
addListener using a reference to the component dispatching the event.

 

To set a listener for a non-bubbling event, you must have a reference to
the dispatching object.

 

For bubbling events, you only need to have a reference to some component
in the dispatching conponent's parent chain.  Application.application is
at the top, except for Popups.  Then SystemManager is the top.

 

Tracy Spratt 
Lariat Services 

Flex development bandwidth available 

________________________________

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of stldvd
Sent: Thursday, February 12, 2009 2:32 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Events and Child SWFs

 

Hi Tracy,

Thanks for responding.

Here is my understanding:

1) The idea behind events and event listeners is that you can dispatch
an event anywhere in the app and listen for it anywhere else in the
app, assuming that bubbling is set correctly, and/or that you've used
Application.application.addEventListener() or
SystemManager.addEventListener(). What you're saying, then, is that
the preferred way to accomplish this is by having the listener in the
same component that dispatches the event, and have it call a method
that is in the second component. But you *could* just have the
listener in the second component, right?

2) Then, to do it as you suggest, the issue becomes how to reference
the second component from the first.

I've got the main app with a popup that holds the delete button. Since
the child swf is not loaded there, I'm not sure how to refer to it.
Elsewhere in the main app we load the swf with a load function:

load(url)

Inside the load() function are:
_loader = new SWFLoader();
...
_loader.addEventListener("complete", onChildLoaded );
_loader.load( url );
addChild( _loader );

So perhaps I could add the eventlistener there. I also think (correct
me if I'm wrong) that I need to refer to the loader's content, not the
loader itself. So the syntax would be:

_loader.content.addEventListener("inDeleteMode",
_loader.content.deleteModeHandler);

Do I have this right or am I completely confused? :)

Thanks,

David

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "Tracy Spratt" <tspr...@...> wrote:
>
> You are misunderstanding how listeners work. You add the listener to
> the component that *dispatches* the event, and have it call a method
> where you want the action to take place.
> 
> 
> 
> "parent" just goes up one component. The surest way to do this is to
> use Application.application.addEventListener().
> 
> 
> 
> A bubbling event will hot help you going in this direction (down to
the
> child) 
> 
> 
> 
> Tracy Spratt 
> Lariat Services 
> 
> Flex development bandwidth available 
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of stldvd
> Sent: Thursday, February 12, 2009 1:02 PM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] Re: Events and Child SWFs
> 
> 
> 
> Hi Steve,
> 
> But I need the child swf to react, not the parent. So I think the
> listener has to be in the child, not the parent.
> 
> David
> 
> --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> , Steve Mathews <happydog@> wrote:
> >
> > You are assigning the listener to the wrong object. "this" is your
> child
> > swf, but it is the parent that dispatches the event. Depending on
> the rest
> > of the app "this.parent" might work. So:
> > this.parent.addEventListener("inDeleteMode", deleteModeHandler);
> > 
> > Steve
> > 
> > On Thu, Feb 12, 2009 at 10:44 AM, stldvd <stldvd@> wrote:
> > 
> > > Hi guys,
> > >
> > > I've got a parent application with a 'delete' button. When it's
> > > clicked, I want to set a flag in a child swf, which is loaded via
> SWF
> > > loader.
> > >
> > > So in the parent app on the button's click event I'm dispatching
> an event:
> > >
> > > dispatchEvent(new Event("inDeleteMode"));
> > >
> > > In the child SWF's init function I've got this:
> > >
> > > this.addEventListener("inDeleteMode", deleteModeHandler);
> > >
> > > And then the deleteModeHandler function (stubbed in for testing):
> > >
> > > private function deleteModeHandler():Boolean
> > > {
> > > Alert.show("got it!");
> > > return true;
> > > }
> > >
> > > It ain't working. Can someone see what I'm doing wrong?
> > >
> > > Thanks,
> > >
> > > David
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > --
> > > Flexcoders Mailing List
> > > FAQ:
> http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
<http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> 
> <http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
<http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt> > 
> > > Alternative FAQ location:
> > >
>
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-
<https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf
-> 
> 1e62079f6847
>
<https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf
<https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf
> 
> -1e62079f6847> 
> > > Search Archives:
> > > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo
<http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo> 
> <http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo
<http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo> > !
Groups
> > > Links
> > >
> > >
> > >
> > >
> >
>



Reply via email to