When you pass a Flash object in a service function call, the object's properties are sent to the gateway. In Java environments, an instance of the flashgateway.io.ASObject class (which implements java.util.Map) represents a Flash object. In .NET environments, an instance of the FlashGateway.IO.ASObject class (which implements the ICollection interface) represents a Flash object. Therefore, you can pass Flash objects to any service function that accepts a Map or ICollection argument.
Because Flash Remoting MX transmits data only, the object methods are not available on the server. Similarly, the object properties must be of types that Flash Remoting MX can handle. For example, you cannot include a Flash RecordSet object in an object that you pass to a service function, because Flash Remoting MX cannot convert the RecordSet object to a data type on the server.
When you return an object from the server to Flash, Flash Remoting MX sends the contents of the object's data properties to Flash as a Flash object. In Flash, you can access any of the object's properties that are of types that can be converted to Flash types.
The following sections cover two special cases of objects: ActionScript typed objects and Serializable Java objects.
If you use the Object.RegisterClass method to register an object in ActionScript, you create a typed object. Typed objects are useful in Flash applications for creating subclasses of Flash objects. You can use typed objects in calls to Flash Remoting service functions.
If you use an instance of the object type in a service function call, the Flashgateway.IO.ASObject object represents the argument on the server includes the object type name.
For example, the following ActionScript creates a typed object and uses it in a service function:
//Make a class (Class constructor)
myClass = function()
{
this.Value1 = "Test1";
}
//Register the class definition
Object.registerClass("testClass", myClass);
//Send instance of registered class to a Flash Remoting gateway service
myService.myFunction(new testClass());
When the service function on the application server receives this request, the argument is an object of type flashgateway.io.ASObject in Java and ColdFusion, or FlashGateway.IO.ASObject in .NET environments. The service function can access the class type name, testClass, using the object's getType method in Java or ColdFusion or the ASType property in .NET.
When a service function must create a new typed object to return to Flash Remoting MX, it creates an object of type flashgateway.io.ASObject in Java or ColdFusion, or of type FlashGateway.IO.ASObject in .NET environments. The service function uses the object's constructor or setType method in Java, setType method in ColdFusion, or the ASType property in .NET to set the class type name to the type specified in the ActionScript Object.registerClass method.
When the Flash client receives the typed object from the service function, Flash runs the constructor for the type and attaches all the object's prototype functions.
The following example shows a Java class service function that creates a typed object and returns it to Flash:
package mycompany.flash;
import flashgateway.io.ASObject;
public class MyFlashService
{
public MyFlashService()
{
}
public ASObject getFlashObject()
{
ASObject aso = new ASObject("MyFlashObject");
aso.put("first", "apple");
aso.put("second", "banana");
return aso;
}
}
Note that this example specifies the object type, MyFlashObject, in the constructor.
To create a Flash typed object in ColdFusion, use the cfobject tag or the CreateObject function, specifying the type as Java and class as flashgateway.io.ASObject. Then use the object's setType method to set the Flash object type name. The following CFML is the equivalent to the Java code:
<cffunction access="remote" name="getFlashObject">
<cfobject type="JAVA" class="flashgateway.io.ASObject" name="myOb
" action="CREATE" >
<cfset myobj.setType("MyFlashObject")>
<cfset myobj.put("first", "apple")>
<cfset myobj.put("second", "banana")>
<cfreturn myobj>
</cffunction>
If a service function returns an object that implements the Java Serializable interface, its public and private properties are available as ActionScript properties. For example, a Java service method might return the following JavaBean as the result of a Flash Remoting method invocation. In this case, all three private properties, text, recipient, and server, are available to Flash.
public class Message implements java.io.Serializable
{
private String text;
private String recipient;
private String server;
public Message()
{
this.text = "Default message";
this.recipient = "user@macromedia.com";
this.server = "smtp.macromedia.com";
}
public String getText(){return this.text;}
public void setText(String t){this.text = t;}
public String getRecipient(){return this.recipient;}
public void setRecipient(String r){this.recipient = r;}
public Message getMessage()
{
return this;
}
}
You can use the following ActionScript to set and get the result object's properties. (For brevity, this example omits the code that configures the network connection and service object.)
myBeanService.setText("Hello from Me.");
myBeanService.setRecipient("me@macromedia.com");
myBeanService.getMessage();
function getMessage_Result(result)
{
myMessageText.text = result.text;
myServerInfo.text = result.server
In this case, ActionScript does not get the value of the Message.text property by explicitly calling the getMessage method, but directly from the properties returned from the Flash gateway on the server.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flashremoting/mx/Using_Flash_Remoting_MX/UseASData5.htm
Comments
sgilson102 said on Dec 9, 2002 at 8:37 PM : jaronlambert said on Sep 3, 2003 at 8:12 AM : No screen name said on Nov 15, 2004 at 5:22 PM : No screen name said on Feb 21, 2005 at 3:04 AM :