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.
我有一个Main.mxml文件和一个RoutePlanner.xmlm文件。 RoutePlanner定义了自定义Canvas组件,Main.mxml使用该自定义组件。
The problem is the RoutePlanner components contains a lot of events, such as Click() and MouseMove() etc. However the functions those events reference to are all defined in Main.mxml.
问题是RoutePlanner组件包含很多事件,例如Click()和MouseMove()等。但是这些事件引用的函数都是在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.
Main.mxml是一个巨大的文件,我正试图分手。我不能只将函数从Main移动到自定义组件,因为函数中使用了类变量。
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)
它可以在组件中包含Main,所以我可以使用这些方法吗?或者我应该将所有方法移动到AS文件,并将其包含在Main和组件中? (这需要安静一点工作但是)
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?
或者是否可以在组件中创建占位符函数,并使这些占位符可绑定,并且在Main.mxml中创建组件之后,将Main.xml中定义的实际方法绑定到组件中的事件?
Thanks in advance,
提前致谢,
Kwaak
2 个解决方案
#1
As your application grows in complexity you should look into using a micro architecture framework like Cairngorm or Pure MVC.
随着应用程序的复杂性增加,您应该考虑使用像Cairngorm或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/
查看Cairngorm的这些介绍:http://www.davidtucker.net/2008/04/01/cairngorm-videos-available-as-flv-downloads/
#2
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
As your application grows in complexity you should look into using a micro architecture framework like Cairngorm or Pure MVC.
随着应用程序的复杂性增加,您应该考虑使用像Cairngorm或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/
查看Cairngorm的这些介绍:http://www.davidtucker.net/2008/04/01/cairngorm-videos-available-as-flv-downloads/
#2
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);" />