Hi Tom,
 
 
Your event object would need to implement the clone method. In clone you would create a new instance of the event object.
 
To your Cairngorm question: I'd suggest you dispatch a "view event" using standard Flex 2 event dispatching (no Cairngorm involved here) and in your view that decides to call the Cairngorm Command you create the Cairngorm event and dispatch that. I know this seems a bit tedious at first, but in my experience it's beneficial to keep Cairngorm events only for Cairngorm and don't mix them up with other other views that dispatch events to other views.
 
 
Best,
Alex
 
Alex Uhlmann
Consultant (Rich Internet Applications)
Adobe Consulting
Westpoint, 4 Redheughs Rigg, South Gyle, Edinburgh, EH12 9DQ, UK
p: +44 (0) 131 338 6969
m: +44 (0) 7917 428 951 
[EMAIL PROTECTED]

 


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Tom Bray
Sent: 01 June 2006 21:58
To: flexcoders@yahoogroups.com
Subject: [flexcoders] f2b3 events, cairngorm: Why do these custom events only work once?

There's something I don't understand about the event lifecycle in flex.  In my model, I setup a dataprovider for a popup menu like this:

        public var onlineUsersOptionsMenu:ArrayCollection =    new ArrayCollection([
                                                {label:"Chat", event:new OpenIMWindowEvent() },
                                                {label:"View profile", event:new ViewProfileEvent() },
                                                {label:"Add to contacts", event:new AddContactEvent()}
                                            ]);

The events you see above are Cairngorm events that bubble up and cause various commands to be executed.  I'm designing it this way so that my view doesn't have to know anything about the menu items -- it just handles the MenuEvent.CHANGE by dispatching the menu item's event like this:

private function handleMenuChange( e:MenuEvent ):void
{
    dispatchEvent( e.item.event );
}

I figured I could get away with reusing a single instance of each of these events because they just cause a command to be executed.  That's not the case -- it works the first time, but the second time throws the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::[EMAIL PROTECTED] to org.nevis.cairngorm.control.CairngormEvent.
at flash.events::EventDispatcher/dispatchEvent()

What's happening here?  What am I missing about the lifecycle of events?  Should I use a factory that creates new events each time there's a menu selection? I was orginally thinking of using the Command pattern directly by specifying commands for each menu item (instead of events) so my view would do this instead:

private function handleMenuChange( e:MenuEvent ):void
{
   e.item.command.execute();
}

Do you think that's a better approach?

Thanks,

Tom


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to