20.13. Calling Java or JSP Functions from Flash

Problem

You want to invoke J2EE service functions using Flash Remoting.

Solution

Use public Java class methods. Alternatively, use servlets/JSPs that have been modified to work with Flash Remoting.

Discussion

Although Flash Remoting for J2EE enables you to invoke public methods of Java classes or servlets/JSPs, invoking Jave class methods is the preferable option. You can invoke any public method of a Java class without having to modify the Java code at all. This is an obvious advantage. To access the methods of a Java class from Flash Remoting, you should create an ActionScript service object that maps to the fully qualified Java class name:

// Create a service that maps to the Book class in the oreilly.ascb package.
myService = myConnection.getService("oreilly.ascb.Book");

If you must use servlets/JSPs instead of invoking Java class methods, you need to modify the servlet/JSP code for it to work properly with Flash Remoting. Values are passed to and from the servlet/JSP by way of attributes of the request object. Parameters are passed from Flash to the servlet/JSP using the attribute named FLASH.PARAMS. You can retrieve the attribute value using the getAttribute( ) method of the request object. For example:

Object myFlashParams = request.getAttribute("FLASH.PARAMS");

The value of the FLASH.PARAMS attribute is a List object. However, if you want the servlet/JSP to be accessible from a web browser as well as from Flash Remoting, you should ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.