views:

242

answers:

2

Hello,

I've got a Main.mxml file and a RoutePlanner.xmlm file. The RoutePlanner defines a custom Canvas components, and the Main.mxml uses that custom component.

The problem is the RoutePlanner componetns contains alot of events, such as Click() and MouseMove() etc. However the functions those events reference to are all defined in Main.mxml.

Main.mxml was a giant file I'm trying to split up. I can't just move the function from Main to the custom Components, because of used class variables in the functions.

It it possible to include the Main in the component, so I can use the methods? Or should I move all the methods to a AS file, and simply include that in both the Main and the component? (That will require quiet a bit more work though)

Or is it possible to create placeholder functions in the component, and than make those placeholders bindable, and than after creating the component in the Main.mxml, bind the actual methods defined in Main.xml to the events in the component?

Thanks in advance,

Kwaak

A: 

Found it out myself using events:

CustomComponent.mxml:

[Event(name="onCreateRoute", type="Event")]
...  
<mx:Button label="Plan Route" click="dispatchEvent(new Event('onCreateRoute'))"/>

Main.mxml

<custom:CustomComponent onCreateRoute="CreateRoute(event);" />
+1  A: 

As your application grows in complexity you should look into using a micro architecture framework like Cairngorm or Pure MVC.

These really help organize your application.

Check out these introductions to Cairngorm: http://www.davidtucker.net/2008/04/01/cairngorm-videos-available-as-flv-downloads/

robmcm