O'Reilly logo

Agile Enterprise Application Development with Flex by Tony Hillerson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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}" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required