Sean,
I recently had a project that I had to implement the Clone Method when defining a custom cairngorm event. I downloaded the source code to the flex 2 Cairngorm store and looked at how they were doing the custom events. In that project the clone event was simply creating a new instance of the Event. So if your custom event class was defined as public class GetProductEvent extends CairngormEvent with a public var ItemID:int, the clone method was return new GetProductEvent(); I created all of my custom events in this manner and initially had no problems dispatching my events and assigning my event the ItemID. But then I ran into a problem. In my app I wanted to save the last attempted event in case the user's session has timed out. If a user times out, I wanted to re-dispatch the event once they log back in. This was important in my app because users could be doing a lot of things in the Flex App without ever hitting the Coldfusion server, but then they would lose all their work when they went to save. Since the Coldfusion server would have timed them out after 20 minutes. So I created a model variable tempPendingCommand:CairngormEvent and would assign the custom event to this variable before dispatching it. After the event is successful I clear this variable out. Upon testing this approach, I noticed my data (ItemID) was null when the event was fired after a timeout and successful login. It took a while to track down in the debugger and it came down to the Flash.Event Clone method. The override clone method I defined had no idea there was an ItemID. Luckily, the fix was easy. I changed my GetProduct clone method to; Var tempGetProductEvent = new GetProductEvent(); tempGetProductEvent.ItemID = ItemID; return tempGetProductEvent; This solved the problem. So it seems it is only an issue if you try caching or assigning your custom event to another variable. If you are directly dispatching the event, the clone method is never used, at least in my case. John ************************************************** John R. Piotrowski Programmer Analyst Wharton Computing Email: [EMAIL PROTECTED] ************************************************** ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Stembert Olivier (BIL) Sent: Friday, March 16, 2007 2:49 AM To: [email protected] Subject: RE: [flexcoders] Cairngorm: When / why override clone in Events Sean, You can read in the Flex doc: There are two utility methods in the Event class. The clone() method allows you to create copies of an event object. The toString() method allows you to generate a string representation of the properties of an event object along with their values. Both of these methods are used internally by the event model system, but are exposed to developers for general use. For advanced developers creating subclasses of the Event class, you must override and implement versions of both utility methods to ensure that the event subclass will work properly. Nothing to do with Cairngorm. Rgds, Olivier ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Sean Sell Sent: Wednesday, March 14, 2007 8:45 PM To: [email protected] Subject: [flexcoders] Cairngorm: When / why override clone in Events In one of the Cairngorm examples I learned Cairngorm from each event had defined an override for the clone method (of Flash.Event). Does anyone understand haw and when you should do this? Does Cairngorm clone the events behind the scenes somewhere that requires this be done? --Sean ________________________________ Be a PS3 game guru. Get your game face on with the latest PS3 news and previews at Yahoo! Games. <http://us.rd.yahoo.com/evt=49936/*http:/videogames.yahoo.com> --------------------- An electronic message is not binding on its sender. Any message referring to a binding engagement must be confirmed in writing and duly signed. --------------------- --------------------- An electronic message is not binding on its sender. Any message referring to a binding engagement must be confirmed in writing and duly signed. ---------------------

