3 Replies Latest reply on Aug 15, 2010 9:52 PM by John Hall

    Why override custom event…and when to override it?

    jerry98225 Level 1

      Hi guys..

         I always have a question about override custom event. I am not sure why or what do to inside override function. I searched google but didn't get too many feedbacks.

       

      Also, my projects seem work fine even though I use my custom event without override. Anyone could explain it? I appreciate if someone can light me up.

        • 1. Re: Why override custom event…and when to override it?
          John Hall Level 4

          I don't think I've ever overridden a custom event, though you might consider including a clone handler if you want the event to bubblier. I suppose there would be occasions but I generally attach proper tie to custom events to differentially accomplice work.

          1 person found this helpful
          • 2. Re: Why override custom event…and when to override it?
            jerry98225 Level 1

            Really? I thought override custom event is a must in every custom event class.

             

            They usually do something like

             

            override public function clone():Event{

                 return new MyCustomEvent(this.type, this.data)

            }

            • 3. Re: Why override custom event…and when to override it?
              John Hall Level 4

              Yes, it's a good practice to override the clone function of the superclass but you're not really overriding your custom event. Guess I didn't say it well before. Just google something like "Flex override clone function" and you'll be taken to the livedocs, most likely, where you'll find this paragraph

               

              ----------------

              You are required to override the Event.clone() method in your subclass. The clone() method returns a cloned copy of the event object by setting the type property and any new properties in the clone. Typically, you define the clone() method to return an event instance created with the new

              operator.

              ----------------

               

              I've not really thought about it before but I assume that's in case you want to extend your class. Anyway, you can pretty blindly just include that override of the clone function and not get into trouble. It's just saying, hey, if something is dealing with this custom event, don't return a copy of the superclass - the Event class - return a copy of this custom event that I've created to extend the Event class to add special functionality.