views:

351

answers:

2

Dears, how can I let an SWF file to retrieve values immediately from Java application that does live calculations (Speed is a necessity).

question in other form : how can I give my website browser immediate data - that are bean calculated now - as fast as i can ?

+1  A: 

I'm going to assume the calculations are being done in a Java applet in the same browser where the flash is running.

You can call Javascript from within the applet using the following code. This code could then update the values in the flash animation.

import netscape.javascript.JSObject;

JSObject win = JSObject.getWindow(applet);
win.eval("window.alert('Hello from Java')");

If my assumption is incorrect, then where is the Java application running? On the client or server?

If it's on the server then you need Flash remoting. I believe there are a few different Flash remoting techniques. Try searching for java flash remoting. You can make it call the server every 2 seconds or so to get the latest data.

If it's running on the client I doubt you can connect to it from Flash because of security. A signed Java applet could connect anywhere it wants to. You could retrieve the data using it, then push it into Flash using the method described above. Would be a crazy hack though. Can you do the same thing with Flex? (I've never used Flex before).

sjbotha
+1  A: 

If the speed is crucial, you would probably want to do it via some kind of socket connection. Usually signed applet or a WebStart Java application is able to open a listening socket. Flash application then would be able to connect to this socket and as a result you will have very fast bidirectional communication.

There are some caveats however.

  • You should bear in mind that user might get suspicious about weird socket activity on his machine, or it would be just blocked by a firewall - so you'll need to warn user.
  • In order to be able to connect from Flash to Java, you must dispatch crossdomain policy file from the listening socket (or any other below 1024 - see documentation for details; keywords: crossdomain, policy-file-request, loadPolicyFile). Also your Flash application might need to request such file manually from the Java application.

Couple of useful links on how to get certificate for your Java application: how to get free code signing certificate (Russian), similar but less detailed description in English.

However, if you are able (read: the speed is sufficient) to use Java Applet <-> JavaScript <-> Flash combination I'd advice to take advantage of it.

dragonfly