Custom event

posted by iup85 on 2009-11-11 01:42:18
Hi Everyone,
I was a new to flex.
I have a doubt. How to create a custom event and what is the use of the custom event.
Can anyone of you please explain with real time example.
Thanks,
Sal avatar
Sal
0
Hi,
Custom events are user defined event, consider a simple example like Flex button control have click event, if you want to extends the button control of flex and create your own then you might also want to have your own event like myClick event.
to create a custom event you have to
- Extend the Event class
- dispatch that Custom event from your MXML or AS component
- listen to that event
and you are done.
What I use as Custom event class is
package events { 
   import flash.events.Event; 
   public class CustomEvent extends Event 
   { 
      public static const customClickEvent:String = "customClickEvent"; 
      public var data:Object = null; 
      public function CustomEvent(type:String, data:Object=null, bubbles:Boolean=false, cancelable:Boolean=false) 
      { 
         super( type , bubbles , cancelable ); 
         this.data = data; 
      } 
      override public function clone():Event 
      { 
         return new CustomEvent( type , data , bubbles , cancelable); 
      } 
   } 
} 
 
and dispatch using
dispatchEvent(new CustomEvent (CustomEvent.customClickEvent, null, false, false) ); 
if you are using this event inside MXML component then you have to define
your CustomEvent by using metadata tags.
Hope this helps you.
1 answers - 0 questions
  Positive        Negative



Answer the question



Top Users
  • dail (12)
  • livin52 (3)
  • camu (3)
  • softweb (2)
  • Nadine (1)
  • Josware (1)
  • lfelipecr (1)
  • gregoriohc (1)
  • Mitu (1)
  • ryan714 (1)