flex air + java

简单扼要的说明一下怎么配置:用到技术 merapi

java:

main可以因为启动服务类。

package merapi.examples.helloworld;
import merapi.Bridge;
import merapi.examples.helloworld.handlers.HelloWorldHandler;
public class HelloWorldRunner
{
    //--------------------------------------------------------------------------
   //
    //  Static methods
   //
   //--------------------------------------------------------------------------
    /**
   *  The main method that starts the Bridge and instantiates the HelloWorldHandler instance.
     */

    public static void main( String[] args )
    {
       Bridge.open();
       new HelloWorldHandler();
    }
}


 message:消息类! 首先必须声明一下消息类型  public static final String HELLO="hello";这句话就是声明消息 字符创可以任意,其他是简单javabean

package merapi.examples.helloworld.messages;
import merapi.messages.Message;
public class HelloWorldMessage extends Message
{
    public static final String HELLO = "hello";
    public HelloWorldMessage() 
    {
        super();
    }
    private String helloText ;
	public String getHelloText() {
		return helloText;
	}
	public void setHelloText(String helloText) {
		this.helloText = helloText;
	}
} 

 handle:

package merapi.examples.helloworld.handlers;
import merapi.examples.helloworld.messages.HelloWorldMessage;
import merapi.handlers.MessageHandler;
import merapi.messages.IMessage;
public class HelloWorldHandler extends MessageHandler
{
//	这个类的第一部分是一个构造函数。
//	在这个构造函数里,我们调用super()这个函数,
//	并且从questionMessage类中传了一个静态变量给它。
//	这个变量是一个字符串类型的,
//	用于申明这个handler将会处理的消息类型的。
//	这个字符串的值可以是任意的,但是得和AIR应用程序中字符串的相匹配。
//	否则在handler将无法收到来自bridge中的消息。
    public HelloWorldHandler() 
    {
        super( HelloWorldMessage.HELLO );
    }
    public void handleMessage( IMessage message )
    {
        if ( message instanceof HelloWorldMessage )
        {
            HelloWorldMessage hwMessage = ( HelloWorldMessage ) message;
            System.out.println( hwMessage.getHelloText() );
            
            hwMessage.setHelloText( hwMessage.getHelloText() + " - response - " + 
                                    Long.toString( System.currentTimeMillis() ) );
            
//            ,然后调用send()函数。调用send()函数将消息返回给bridge,在bridge中消息会等待AIR应用程序来接受它。
            hwMessage.send();
        }
    }
}

 ActionScript: 主要映射java类! 也就这个作用! 一定要一样

package merapi.examples.helloworld.messages
{

import merapi.messages.Message;
//这句话就是映射
[RemoteClass( alias="merapi.examples.helloworld.messages.HelloWorldMessage" )]


public class HelloWorldMessage extends Message
{
    public static const HELLO : String = "hello";
    public function HelloWorldMessage() 
    {
        super( HELLO );
    }

    public var helloText : String = null;
    
    
} 
} 

 MXML:

<?xml version="1.0" encoding="utf-8"?>

<mx:WindowedApplication 
  xmlns:mx="http://www.adobe.com/2006/mxml" 
  xmlns:merapiproject="http://merapiproject.net/2009"
  xmlns:messages="merapi.examples.helloworld.messages.*"
  layout="vertical">
	
	<!-- ====  helloWorldMessage : The message sent accross the bridge 相当于new  ======================== -->
	<messages:HelloWorldMessage id="helloWorldMessage" helloText="Hello World!!!" />

	<!-- ====  helloWorldHandler : The message handler for the HelloWorld.HELLO message type  哪个字段接受数据== -->
	<merapiproject:MessageHandler id="helloWorldHandler"  type="{ HelloWorldMessage.HELLO }" 消息类型就是与java定义哪里一样  result="handleResult(event)" 回调函数可以这么认为
	  /> 

	<mx:Script>
		<![CDATA[
			import mx.rpc.events.ResultEvent;
			private function handleResult(e:ResultEvent):void{
				helloWorldMessage=e.result as HelloWorldMessage;
				aa.text=helloWorldMessage.helloText;
			}
		]]>
	</mx:Script>
	<mx:Button label="Say Hello" click="helloWorldMessage.send()" />
	<mx:Label text="" id="aa" />
	
</mx:WindowedApplication>

 jar swc 自己下!    swc打包了! 解压即可

建立的都是标准的java Flex AIR项目

air 需要运行环境 自己在adobe下吧!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值