Tremendously illuminating. Thanks, guys.

-- David

--- In [email protected], "Tracy Spratt" <tspr...@...> wrote:
>
> One more thing.  A custom event is not always required.  Any public
> property on the dispatching object can be read via the target or
> currentTarget properties of the standard Event.
> 
>  
> 
> Folks will argue OOP principles about this, but the choice is yours.
> 
>  
> 
> Tracy
> 
>  
> 
> ________________________________
> 
> From: [email protected] [mailto:[email protected]] On
> Behalf Of Tracy Spratt
> Sent: Monday, January 05, 2009 6:56 PM
> To: [email protected]
> Subject: RE: [flexcoders] Re: why I can not dispatchEvent with
> creationComplete?
> 
>  
> 
> SystemManager is the parent of Application.  Set the listener on that
> and it will hear all events, including from Application and from
> pop-ups.
> 
>  
> 
> But events propagate *up*.  If you dispatch an event in a child
> component, its siblings will not be able to listen for it.  Huh, as Josh
> just beat me to the punch.
> 
>  
> 
> You could also set the listener on a reference to
> Application.application instead of SystemManager:
> 
> creationComplete="Application.application.addEventListener(FoodEvent.FOO
> D_EVENT, foodEventhandler)"
> 
> that will not hear events from pop-ups, though.
> 
>  
> 
> Tracy
> 
>  
> 
> ________________________________
> 
> From: [email protected] [mailto:[email protected]] On
> Behalf Of stldvd
> Sent: Monday, January 05, 2009 6:05 PM
> To: [email protected]
> Subject: [flexcoders] Re: why I can not dispatchEvent with
> creationComplete?
> 
>  
> 
> Thanks for the help so far.
> 
> In the application from which this simple sample is derived, I'm not
> actually in Application, so I definitely want to make them bubble (if
> that's the solution). I tried changing bubbles:Boolean=true but that
> didn't do anything. What does it mean to 'listen on the SystemManager'?
> 
> --- In [email protected] <mailto:flexcoders%40yahoogroups.com>
> , "Josh McDonald" <dznuts@> wrote:
> >
> > If you want to listen to events that are dispatched from
> Application, you
> > need to listen at either Application.application or (better) make them
> > bubble, and listen on the SystemManager.
> > 
> > -Josh
> > 
> > On Tue, Jan 6, 2009 at 8:58 AM, stldvd <stldvd@> wrote:
> > 
> > > OK, here's a little app to demonstrate the problem. I'm sure the
> > > answer is obvious, but... can someone point it out?
> > >
> > > The Application and the Canvas go in the src folder; the custom
> event
> > > (FoodEvent) goes in an 'events' folder inside src.
> > >
> > > I made the canvas because I wanted the event to be heard in a
> > > different component from the Application itself.
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> "
> > > layout="horizontal" xmlns:food = "*">
> > > <mx:Script>
> > > <![CDATA[
> > >
> > > import events.FoodEvent;
> > >
> > > [Bindable]
> > > public var food_supply:Array = [{label:"Pizza Pie",
> > > data:"Pizza"},{label:"Buffalo Wings", data:"Wings"}];
> > >
> > > private function onFoodCBChange():void
> > > {
> > > var item:Object = foodCB.selectedItem;
> > > if(item == null)
> > > return;
> > >
> > > var event:FoodEvent = new
> FoodEvent(FoodEvent.FOOD_EVENT);
> > > event.selectedItemFromFoodCB = item.data;
> > > this.dispatchEvent(event);
> > > }
> > > ]]>
> > > </mx:Script>
> > > <mx:Canvas height="167" width="200">
> > > <mx:ComboBox x="40" y="20"
> > > dataProvider="{food_supply}"
> > > id="foodCB" textAlign="left" change="onFoodCBChange()"/>
> > > </mx:Canvas>
> > > <food:testCanvas />
> > > </mx:Application>
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> "
> > > creationComplete="this.addEventListener(FoodEvent.FOOD_EVENT,
> > > foodEventhandler)"
> > > borderStyle="solid" borderColor="red" borderThickness="3"
> x="300"
> > > y="300" width="200" height="200">
> > > <mx:Script>
> > > <![CDATA[
> > > import events.FoodEvent;
> > > import mx.controls.Alert;
> > >
> > > private function
> foodEventhandler(e:FoodEvent):void
> > > {
> > > Alert.show(e.selectedItemFromFoodCB);
> > > }
> > >
> > > ]]>
> > > </mx:Script>
> > > </mx:Canvas>
> > >
> > > package events
> > > {
> > > import flash.events.Event;
> > >
> > > public class FoodEvent extends Event
> > > {
> > >
> > > public static const FOOD_EVENT:String = 'food.event';
> > >
> > > public var selectedItemFromFoodCB:String; 
> //Used to
> > > pass selection value
> > >
> > > public function FoodEvent(type:String,
> > > bubbles:Boolean=false,
> > > cancelable:Boolean=false)
> > > {
> > > super(type, bubbles, cancelable);
> > > }
> > >
> > > }
> > > }
> > >
> > > --- In [email protected]
> <mailto:flexcoders%40yahoogroups.com> , "Tracy Spratt" <tspratt@> wrote:
> > > >
> > > > It will depend on where and how the listener is declared.
> > > > CreationComplete fires at different times for different
> components. As
> > > > I recall, it is bottom up, so creationComplete for a parent will
> fire
> > > > after creationComplete for a child. If the parent creationComplete
> > > > handler declares the listener, then there would be a problem.
> > > >
> > > >
> > > >
> > > > This should only be an issue on start-up. Certainly the
> listener would
> > > > be available when the app was ready to receive user input, via
> ComboBox
> > > > or button click, as the original poster noticed.
> > > >
> > > >
> > > >
> > > > Remember that events flow through the DOM. It is possible for a
> > > > dispatched event to "miss" a component. Pop-ups are a particular
> > > > problem.
> > > >
> > > >
> > > >
> > > > Tracy
> > > >
> > > >
> > > >
> > > > ________________________________
> > > >
> > > > From: [email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
> ] On
> > > > Behalf Of stldvd
> > > > Sent: Monday, January 05, 2009 4:48 PM
> > > > To: [email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> > > > Subject: [flexcoders] Re: why I can not dispatchEvent with
> > > > creationComplete?
> > > >
> > > >
> > > >
> > > > I'm having a similar issue. Event is dispatched (I can step
> through
> > > > code and see it) but the event listener is never hearing it, and
> so
> > > > the listener function is never being fired.
> > > >
> > > > How does one tell if the listener is ready or not? If you add the
> > > > listener on the creationcomplete or initialize event of an mxml
> > > > component, it should in theory be ready to fire, for the duration
> of
> > > > the app, right? And if you're dispatching a custom event when an
> item
> > > > is selected in a combobox, it should certainly work. What could
> be the
> > > > reason for a 'deaf' event listener? :)
> > > >
> > > > -- David
> > > >
> > > > --- In [email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com<flexcoders%2540yahoogroups.com>
> > > >
> > > > , "Tracy Spratt" <tspratt@> wrote:
> > > > >
> > > > > Perhaps the listener is not yet ready when the canvas
> creationComplete
> > > > > fires?
> > > > >
> > > > > Tracy
> > > > >
> > > > >
> > > > >
> > > > > ________________________________
> > > > >
> > > > > From: [email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com<flexcoders%2540yahoogroups.com>
> > > >
> > > > [mailto:[email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com<flexcoders%2540yahoogroups.com>
> > > >
> > > > ] On
> > > > > Behalf Of markflex2007
> > > > > Sent: Monday, January 05, 2009 2:08 PM
> > > > > To: [email protected]
> <mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com<flexcoders%2540yahoogroups.com>
> > > >
> > > > > Subject: [flexcoders] why I can not dispatchEvent with
> > > > creationComplete?
> > > > >
> > > > >
> > > > >
> > > > > I try the following code, But I can not dispatchEvent.
> > > > >
> > > > > <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml
> <http://www.adobe.com/2006/mxml> 
> > > > <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> >
> > > > > <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml>
> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > > "
> > > > > creationComplete="justLogin()" >
> > > > > <mx:Metadata>
> > > > > [Event(name="loginEvent", type="flash.events.Event")]
> > > > > </mx:Metadata>
> > > > > <mx:Script>
> > > > > <![CDATA[
> > > > >
> > > > >
> > > > > private function justLogin():void{
> > > > >
> > > > > dispatchEvent(new Event("loginEvent", false));
> > > > >
> > > > > }
> > > > > ]]>
> > > > > </mx:Script>
> > > > >
> > > > > </mx:Canvas>
> > > > >
> > > > > I can dispatchEvent with button click, please let me know how to
> > > > > automatic dispatchEvent in page start.
> > > > >
> > > > > Thanks
> > > > >
> > > > > Mark
> > > > >
> > > >
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > --
> > > Flexcoders Mailing List
> > > FAQ:
> 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-
> 1e62079f6847
> <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> ! Groups
> > > Links
> > >
> > >
> > >
> > >
> > 
> > 
> > -- 
> > "Therefore, send not to know For whom the bell tolls. It tolls for
> thee."
> > 
> > Like the cut of my jib? Check out my Flex blog!
> > 
> > :: Josh 'G-Funk' McDonald
> > :: 0437 221 380 :: josh@
> > :: http://flex.joshmcdonald.info/ <http://flex.joshmcdonald.info/> 
> > :: http://twitter.com/sophistifunk <http://twitter.com/sophistifunk> 
> >
>



Reply via email to