开发者

Messaging between Java and Flex with Flerry

I'm currently working on a project that need to communicate with java from air without the use of a server like Tomcat. For this i found and use Flerry.

Communicating between Java and Air is no problem, as long as I try to send a message from the class that I initially instantiated from Air.

What I try to do is subscript to messages from a Message Class in java and use that class to send info and errors to Air from Java.

MessageController.java:

public class MessageController 
{

    public MessageController()
    {

    }

    public static void sendErrorMessage(String errorMessage)
    {
        NativeObject.sendMessage(errorMessage, "error");
    }

    public static void sendInfoMessage(String infoMessage)
    {
        NativeObject.sendMessage(infoMessage, "info");
    }
}   

In Air I create a NativeObject on the messaging class and subscribe to the messages:

var messageController:NativeObject = new NativeObject();
messageController.source = "controller.MessageController" ;
messageController.singleton = true;
mes开发者_高级运维sageController.debug = false;
messageController.addEventListener(FaultEvent.FAULT, onFileControllerFault, false, 0, true);

messageController.subscribe("info", infoMessageHandler);
messageController.subscribe("error", errorMessageHandler);

As you would have guessed, this doesn't work. It seems that I am only able to dispatch messages from the class that I subscribe to directly, for example if I do this:

messageController.start();

and in my MessageController.java i put this:

public void start()
{
NativeObject.sendMessage("test message", "info");
}

the infoMessageHandler receives an message containing test message, as it should.

How can I dispatch messages from whatever class in Java and catch them on the Air side?


I'm not sure I fully understand the issue yet, but is there a reason you can't simply send and receive all messages through a Java 'communication' class? If that's working, I'd just set up public methods in Java interfacing/communications class and be done with it.

(It's been awhile since I've dug into how Flerry works so I can't recall enough to point out the likely cause of the behavior you're seeing.) Also Flerry is open source, and not very big at all. If you really want to know why it's behaving in a certain way, I'd wager you could figure it out by looking at the source. (Won't take 6 months to learn like some Spring or Hibernate code base, or even BlazeDS, I promise.)

I do use Flerry in a small app, but now that I think about it, I only have one class which dispatches anything to Flex! But I feel like you may need to describe the problem you're facing differently, because it sounds like expected behavior to me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜