CCCC
Root and Roo



Root and Roo
Photo or Graphics by: CAST Cebu Animators Society for Talent
Voice or Sound by: Roo

Root and Roo
A Newsletter from the CCCC Cebu C Coders Club

The Marriage of Flash and Java

Hello! My name is Gary. I live in Cebu. This is my cat Roo and she lives there too.

The Marriage of Flash and Java The server side Java makes a connection with client side Flash.
Bedtime Story -- A little story to tickle your funny bone and to get you to think.
Conclusions -- Our opinion only. We welcome other views.

This month we take a look at how Flash MX has become the new girlfriend of Java. At the time of the lawsuit between Microsoft and Sun Microsystems, the loser was the Java applet. Since that time we have had several ways for the server to communicate with the browser. Some of these are HTML Form's, SOAP messages, RPC with Javabeans and CORBA. The latest new thing is Web Services.

We admit, this lady Flash is very attractive and has many more suitors other than Java. Of course there is "big daddy Microsoft", that must approve of this marriage. We'll cover these issues in our conclusions at the end of the newsletter.

The Marriage of Flash and Java

This love story begins at the end. The end of Java Applets and the feud between Microsoft and Sun Microsystems. Since then Sun has made several attempts to get Java married to some cute applet running in  Microsoft's IExplorer. In this time our little girl Flash was growing up and charming the Internet world with her RME - Rich Media Experience and Java has been the poor bachelor left outside the church.

About a year ago Macromedia had its debut in client/server commutation with the introduction of Flash MX and recently with the introduction of Flash Remoting. The Flash Remoting used a communication protocol call AMF or Action Message Format. This format is Macromedia proprietary. It is similar to SOAP messages and communicates to Macromedia components in J2EE, Coldfusion, JRun and .NET.

Flash Remoting consist of two parts. ActionScripts that run on the client and Java classes (or other server side applications. See our conclusions below.) that run on the server. The two parts are very tightly coupled. By this I mean that a Class defined in an ActionScript on the client, must have the same Class and methods defined on the server. The communication between the server and client is the serialization of this Class. The server executes the desired method, creates an appropriate class  and passes it back to the clients callback method. The server may send back a Hashmap, RecordSet or other Objects, depending on the needs of the application.

Callback methods have predefined endings in the ActionScript to help identify returned results and errors. For results the callback method name must be "calledMethod_Result(result)". For error and status returns the callback method name must be "calledMethod_Status(result)". The "calledMethod" part is the name of the method you called on the server. The returned "result" is an Object defined by the Java code.

Flash Remoting will let you invoke JavaBeans, Java classes, EJBs, servlets, JSPs and JMX Mbeans (JRun only). The data types that you can exchange between Macromedia Flash and Java are RecordSets, Objects, primitives, Strings, XML, EJB references, and Date objects. Flash Remoting will even maintain a session between the client and server by exchanging a jsessionid parameter.

The example below is a Flash ActionScript. The Directory class is defined in the client Flash ActionScript. The method getPeople(keyword) is a client ActionScript method sent to the server. The server response to the callback method getPeople_Results( result ). If there is an error the callback is to getPeople_Status( result ).

//A call to the server The server must have this method in a class
//called Directory with parameter String.
//A keyword is defined earlier as a String
Directory.prototype.getPeople = function(keyword) {
    ... Client getPeople code ...
}

//Method called when the server responds. A "result" is defined as
//extending ASObject which extends HashMap
//The ending  _Result is required so the server callback is to
//"server-called-method"_Result( returned-result ).
Directory.prototype.getPeople_Result = function(result) {
    ...Client getPeople_Result code ...
}

//Method called when the server response with and error.
//A "result" is defined earlier as a String
//The ending  _Status is required so the server callback is to
//"server-called-method"_Status( returned-result )
Directory.prototype.getPeople_Status = function( result ) {
    ... Client getPeople_Status code ...
}

The open source community has been very active in reverse engineering AMF. There is now two open source projects at sourceforge.org  The Java project is called "openamf" and can be found at http://sourceforge.org/projects/openamf We have downloaded this and spent some time to find out how it works. The documentation is nonexistent, making it hard to decipher what's going on. We were able to get the "RecordSetTest" and "Client2" samples to run locally. We also were able to modify the code and convert this into a "Cell Phone Directories". We have a web site setup that demonstrates a person using Flash Remoting to look up a person or cell number in a world wide cell phonebook. Check this out. Then click the link "Find a Person or Cell Num".

Are we now a Flash expert. Well no. We have worked with Flash MX for about 2 months and the "openamf" project for about 3 weeks. The point I want to make here, Flash is object oriented and actionScripts are like Java code but use loose type casting. The procedure to define class and class methods is different.. I contended that if you know Java you are also a Flash expert.

Bed Time Story

I was tempted to tell a story about my big one heart throb I had during high school and college. Then I changed my mind to save myself the embarrassment So I have turn to my more immediate love affairs. These includes my life style in the Philippines. The people I meet here and day to day interactions with the local people.

My most recent experience was the birthday party of a six year old boy I have claim as my son. He calls me "Daddy" and he has lived with me since he was a baby. His native language is English, but speaks two other languages fluently. His name is Ness Joelius Inocente. We call him NJ.

Actually we had two birthday parties. Party one was birthday cake and attended by the family. Party two was the kids on the street with 1 peso candy and games. Remembering my grade school days when the teacher would let the birthday person pass out a small treat to your classmates. This was only a three minute party and after you passed out your treat, it was back to your lessons.

For our street party NJ and I bought about 40 peaces of bubble gum and candy from the neighborhood store. All we had to do was walk a short distance and we had 20 kids following us. I put the candy in a larger plastic bag and NJ offered it to the kids. Have you ever seen 20 hands in a plastic grocery sack at the same time? Needless to say the candy was gone within seconds. Did NJ get any candy from the sack? No. Did he complain? No.

The older girls started to organize some games and we spent over an hour playing "Hide n Seek", "Tag", "You're It", "Hop Scotch" and some games I'm not familiar with. I do think NJ enjoyed his street birthday party the best. I know I did. And one thing that did help, I think NJ is in love with the girl next door. He won't admit it but he always speaks to her. Ahhh! to be young again -- and in love.

Conclusions

While we think we got Java and Flash married off and the story to write now is the "and they lived happily ever after". Well almost! We still have other suitors doing the same thing Java is doing. Sourceforge has another open source project called "amf-php". PHP is a server side scripting language and is major completion for Java on the server. You can find this project @ http://sourceforge.net/projects/amf-php. So now we have a threesome and a triangle relationship. Oh and don't forget that Macromedia provides the same solution using the "for fee software" including J2EE from Sun Microsystems.

Have we forgot something here? Ahhh! we forgot to ask the parents of Miss Flash if we could marry their daughter. Remember we reversed engineered the AMF protocol and that belongs to Macromedia. Ohh! and we also we need to ask "Rich Uncle Bill" if we can use his house for the party and reception after the wedding. We certainly know the answer to that question. If it's just a small party it's OK. But if the party gets to big or noisy we may find our self out on the street. The street scenario may not be that far off.

I have in the back of my mind that I had read something on the Internet that Microsoft is developing a Flash replacement, or look alike, for its upcoming new Windows version, code named Longhorn. Not sure about this but it would make since if you think about. Macromedia does have a stand along Flash player. Flash does request and display content from the server. Mmmm! Why don't we just use Flash as the browser for HTML pages and Rich Content. Who needs Microsoft's IExplorer? We'll just use Flash with a Java enabled web server.

To further this argument, recently Macromedia has introduced "Flash Communication Components". The components library includes Chat, Audio Conference, Video Conference, People List, Presentations and more. Lets see if IExplorer can do that. Ahh! Why don't we just have the party at my house and not invite Uncle Bill.