MyObject is not a DisplayObject so the event will not bubble.  The
application should be explicitly adding a listener to MyObject

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Saturday, June 28, 2008 8:56 AM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Custom Event Not Dispatched

 

But dear event is still not dispatching after making all this changes,
----- Original Message -----
From: "Daniel Gold" <[EMAIL PROTECTED]
<mailto:danielggold%40gmail.com> >
To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
Sent: Sat, 28 Jun 2008 10:47:50 -0500
Subject: Re: [flexcoders] Custom Event Not Dispatched

> right, I'm only half awake on Saturday monring
> 
> The bubbles property is the second parameter on the Event constructor,
so
> your MyEvent changes should have done the trick. Sorry about the slip
up
> there, a lot of times if I'm writing something quick and dirty I would
do it
> like
> 
> displatchEvent(new Event("MY_EVENT",true));
> 
> your custom Event class is definitely the best practice as you get the
const
> for the event name to ensure listener's register for the correct
event.
> 
> On Sat, Jun 28, 2008 at 10:37 AM, <[EMAIL PROTECTED]
<mailto:parjan%40softpak.com> > wrote:
> 
> > Ok dear i chanaged MyEvent Class with this
> >
> > public class MyEvent extends Event
> > {
> > public static var MY_EVENT:String = "MY_EVENT" ;
> >
> > public function MyEvent()
> > {
> > super ( MY_EVENT , true );
> > }
> > }
> >
> > but what about " dispatchEvent( new MyEvent(), true ); "
> > dispatchEvent does not accept second argument , it only accepts one
> > argument of Type Event
> >
> >
> > ----- Original Message -----
> > From: "Daniel Gold" <[EMAIL PROTECTED]
<mailto:danielggold%40gmail.com>  <danielggold%40gmail.com>>
> > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
<flexcoders%40yahoogroups.com>
> > Sent: Sat, 28 Jun 2008 10:16:29 -0500
> > Subject: Re: [flexcoders] Custom Event Not Dispatched
> >
> > > If you're not listening for the event directly on the component
that will
> > be
> > > dispatching it, you need to toggle the 'bubbles' property so that
the
> > event
> > > will will trigger handlers up the display list from where it was
> > dispatched.
> > >
> > > So in your case change your dispatch line to:
> > > dispatchEvent( new MyEvent(), true );
> > >
> > > On Sat, Jun 28, 2008 at 10:11 AM, <[EMAIL PROTECTED]
<mailto:parjan%40softpak.com> <parjan%40softpak.com>>
> > wrote:
> > >
> > > > HI can any one tell me what is wrong with this code.
> > > >
> > > > I wrote a custom event and dispatched this event from my entity
class
> > and
> > > > am listening for this event on main application but the listener
is not
> > > > listening for event. Please help me.
> > > >
> > > > here is my Event class
> > > > public class MyEvent extends Event
> > > > {
> > > > public static var MY_EVENT:String = "MY_EVENT" ;
> > > >
> > > > public function MyEvent()
> > > > {
> > > > super ( MY_EVENT );
> > > > }
> > > > }
> > > >
> > > > This class dispatches an event of type MyEvent from setter
method
> > > > public class MyObject extends EventDispatcher
> > > > {
> > > > [Bindable(event="MyEvent")]
> > > > private var _name:String;
> > > >
> > > > public function set name( _pname:String ):void
> > > > {
> > > > _name = _pname ;
> > > > trace( "Dispatching Event" );
> > > > dispatchEvent( new MyEvent() );
> > > >
> > > > }
> > > > }
> > > >
> > > > and here is code for my main application .
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
> > > > layout="vertical" creationComplete="{init()}" >
> > > >
> > > > <mx:Script>
> > > > <![CDATA[
> > > > import com.MyEvent;
> > > > import com.MyObject;
> > > >
> > > > private var obj:MyObject ;
> > > >
> > > > public function init():void
> > > > {
> > > > obj = new MyObject();
> > > > this.addEventListener(MyEvent.MY_EVENT , propertyChangeListener
) ;
> > > >
> > > > }
> > > >
> > > > public function propertyChangeListener( evt:MyEvent ):void
> > > > {
> > > > // This Function never gets called
> > > > trace( 'Listining for MyEvent......' );
> > > > }
> > > > public function btnClickHandler():void
> > > > {
> > > > obj.name = 'Changing Value' ;
> > > > trace( obj.name );
> > > > }
> > > >
> > > > ]]>
> > > > </mx:Script>
> > > > <mx:Button click="{btnClickHandler()}"/>
> > > > </mx:Application>
> > > >
> > > >
> > > >
> > 
> >

 

Reply via email to