Using functions defined in other MXML files

I have a Main.mxml file and a RoutePlanner.xmlm file. RoutePlanner defines custom Canvas components, and Main.mxml uses this custom component.

The problem is that RoutePlanner components contain many events like Click () and MouseMove () etc. However, the functions referenced by all events are specified in Main.mxml.

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

Is it possible for include

Main in a component, so I can use the methods? Or should I move all methods to the AS file and just include this in both Main and Component? (This will take a quiet little more work)

Or is it possible to create placeholder components in a component rather than forcing those placeholders to bind, and after creating the component in Main.mxml, bind the actual methods defined in Main.xml with events in the component?

Thanks in advance,

Kwaak

+1


a source to share


2 answers


As your application grows in complexity, you should learn a microarchitecture framework like Cairngorm or Pure MVC.

This will really help you organize your application.



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

+1


a source


Found it 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);" />

      

0


a source







All Articles