• Decrease font size
  • Reset font size to default
  • Increase font size
Banner
Article Index
Introduction to Merapi
Why Merapi Was Created
Building a Bridge between AIRâ„¢ and the OS
How Merapi Works
Merapi Project Team
All Pages

How Merapi Works


Merapi is a framework that bridges an AIR application with a Java application, both running on the desktop. This communication is accomplished through a class that exists in Java and ActionScript called merapi.Bridge.

 

The simplest way to interact from AIR to Java is by sending and receiving messages though the bridge.

 

Merapi: A Bridge between Adobe AIR and Java

Sending a message from ActionScript:

 

var message : Message = new Message();

message.data = "Hello from Merapi Flex.";

message.type = "Reply";

Bridge.instance.sendMessage( message );

 

 

Sending a message from Java:

 

Bridge bridge = Bridge.getInstance();

Message message = new Message();

message.setData("Hello from Merapi Java.");

bridge.sendMessage(message);

 

 

Receiving a message in Flex:

<merapi:BridgeInstance

id="bridge" result="handleResult(event)" />

 

<mx:Script>

<![CDATA[

private function handleResult( event : ResultEvent ) : void

{

var message : IMessage = event.result as IMessage;


 

Receiving a message in Java:

Bridge.getInstance().registerMessageHandler("Reply", messageHandlerInstance );

public void handleMessage( IMessage message )

{

System.out.println( message.getData() );

}

 

More advanced features are available in the framework for creating proxy objects in ActionScript or Java that automatically cause a mirrored instantiations and invocations on the corresponding side of the bridge. This functionality is essentially an abstraction of the basic messaging framework described above.