Communicating with Modules

You’ve designed your modules to be independent, but there should be provisions to allow external applications to communicate with them, pass them some information and receive response notifications. From the user’s point of view, it may look like an innocent drag-and-drop action, but internally you must resort to one of the several available means of communication. We will start with direct references to the module variables and methods.

First, consider the method-based interfaces. We’ll assume that you have the IGreeting interface, as shown in Example 7-12.

Example 7-12. IGreeting interface

//IGreeting.as
package
{
   public interface IGreeting {
      function getGreeting():String;
      function setGreeting( value:String ):void;
   }
}

Further, suppose that a module, such as ModuleWithIGreeting in Example 7-13, is implementing this interface. Please notice that calling setGreeting() will modify the bindable variable greeting that affects the title of the module’s panel.

Example 7-13. Example of a module implementing the IGreeting interface

<?xml version="1.0"?>
<!- ModuleWithIGreeting.mxml -->
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
   implements="IGreeting" creationComplete="onCreationComplete()" > <mx:Script> <![CDATA[ [Bindable] private var greeting:String=""; public function setGreeting(value:String):void { greeting = value; } public function getGreeting():String { return greeting; } ]> </mx:Script> <mx:Panel id="panel" title="Module With Greeting{greeting}" ...

Get Agile Enterprise Application Development with Flex now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.