Flex - Module간의 통신
Posted 2009/09/24 20:08|
|
|
댓글 하나가 운영자에겐 커다란 힘이 됩니다!
Accessing modules from other modules
You can access properties and methods of other modules by using references to the other modules through the parent application. You do this by using the ModuleLoader child property. This property points to an instance of the module's class, which lets you call methods and access properties.
The following example defines a single application that loads two modules. The InterModule1 module defines a method that returns a String. The InterModule2 module calls that method and sets the value of its Label to the return value of that method.
Main application:
<?xml version="1.0"?>
<!-- modules/InterModuleLoader.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script><![CDATA[
]]></mx:Script>
<mx:ModuleLoader url="InterModule1.swf" id="m1"/>
<mx:ModuleLoader url="InterModule2.swf" id="m2"/>
</mx:Application>
Module 1:
<?xml version="1.0"?>
<!-- modules/InterModule1.mxml -->
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
<mx:Script><![CDATA[
// Defines the method that the other module calls.
public function getNewTitle():String {
return "New Module Title";
}
]]></mx:Script>
</mx:Module>
Module 2:
<!-- modules/InterModule2.mxml -->
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
<mx:Script><![CDATA[
[Bindable]
private var title:String;
// Call method of another module.
private function changeTitle():void {
title = parentApplication.m1.child.getNewTitle();
}
]]></mx:Script>
<mx:HBox>
<mx:Label id="l1" text="Title: "/>
<mx:Label id="myTitle" text="{title}"/>
</mx:HBox>
<mx:Button id="b1" label="Change Title" click="changeTitle()"/>
</mx:Module>
The application in this example lets the two modules communicate with each other. You could, however, define methods and properties on the application that the modules could access. For more information, see Accessing the parent application from the modules.
As with accessing the parent
application's properties and methods directly, using the technique
described in this section can make your modules difficult to reuse and
also can create dependencies that can cause the module to be larger
than necessary. Instead, you should use interfaces to define the
contract between modules. For more information, see Using interfaces for module communication. [출처] Flex. Module간의 통신|작성자 유소꾸냥
위의 정보가 도움이 되셨나요? 그렇다면 댓글 하나만 남겨주세요.
댓글 하나가 운영자에겐 커다란 힘이 됩니다!
- Filed under : 프로그래밍/Flex
- Comment Trackback

