override clone method

31 views
Skip to first unread message

Nitin Gopi

unread,
Feb 10, 2012, 1:35:52 PM2/10/12
to flex_...@googlegroups.com
Hi All
I am using cairngorm framework in my project. I do not override the clone() method in the event class. In fact I never use it whenever I create a custom event class. The application works fine.
But in the flex docs it is written that overriding clone() is necessary when we are creating a custom  event. Can somebody clarify on this.

With Regards,
Nitin Gopi

--
You can only depend on yourself. The cavalry ain't coming.

Sathis Kumar

unread,
Feb 11, 2012, 6:19:04 AM2/11/12
to flex_...@googlegroups.com
Hi Nitin,

As per my knowledge clone method will be used to re-broadcast your event. 
Consider you are having an application -> Container -> Custom Component -> UI Control.
So, the event from UI control will be listened in Custom Component. So, you want the container to have the same event object, you have forward that event to container like re-dispatching / re-broadcasting. 

This time you should be overridden the clone method in your custom method. Otherwise you will not able to do that. 

Thanks
Sathis

--
You received this message because you are subscribed to the Google Groups "Flex India Community" group.
To post to this group, send email to flex_...@googlegroups.com.
To unsubscribe from this group, send email to flex_india+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/flex_india?hl=en.

Shishir Vaghela

unread,
Feb 11, 2012, 8:48:20 PM2/11/12
to flex_...@googlegroups.com
Hello Nitin,

If you are required to redispatch your CustomEvent using dispatchEvent(event) in an handler that is handling the event, you need to override the clone() method.

When the CustomEvent is redispatched, the event framework behind the scenes will call the clone() method of CustomEvent (if overridden) else it will call the clone() method of base class flash.events.Event.
Now, clone() method of Event will return the object of type Event instead of CustomEvent, which will cause the object to truncate any additional information that was added to CustomEvent.
Also, the handler for your redispatched event will be expecting an object of type CustomEvent, which will now get an object of type Event (returned by clone() method). This will cause a Type Coercion Failed error stating that it cannot convert flash.events.Event to your CustomEvent type.
There won't be any runtime error if your handler for redispatched event is expecting an object of flash.event.Event type instead of CustomEvent, but your additional CustomEvent properties will be lost.


Regards
Shishir


--

Akki

unread,
Feb 11, 2012, 10:43:50 PM2/11/12
to Flex India Community
Hi Nitin,

If you want to catch your custom event somewhere and then again want
to dispatch then it will first check clone()method availability. If it
is not available it will create a new instance of this custom event
and then dispatch else it will clone same event.

Check out this blog for all doubts about events and Binding.
http://flex4java.blogspot.in/2012/02/flex-events-part-2.html

Thanks,
Akhil Mittal

Nitin Gopi

unread,
Feb 12, 2012, 5:57:12 PM2/12/12
to flex_...@googlegroups.com
Hi Shirish 
I read your reply and found it useful. I also found a link which has detailed example of using clone() method.

Nitin Gopi

unread,
Feb 12, 2012, 1:13:31 PM2/12/12
to flex_...@googlegroups.com
Hi All
I understand the purpose of the clone() method. But I still don't know when it is necessary to use clone() method.
Her is a link  http://livedocs.adobe.com/flex/3/html/help.html?content=intro_3.html . Look at the "Handling events from composite components".
In it redispatches the event but clone() method was not used. 

Gaurav Pandey

unread,
Feb 13, 2012, 8:18:49 AM2/13/12
to flex_...@googlegroups.com

Dear nitin,

Its very simple if u have reqirment to to trap ur event more then one level in parent display list and need to paas any property with that event , in this case without overriding clone dont have event's proprty value that I
u set while dispatching. This works fine if u listen ur event only at immidiate perent.
Happy flex development

Regards,
Gaurav

Reply all
Reply to author
Forward
0 new messages