Previous Page
Next Page

Tripod >> 3pod Tips & Learning and manuals for educations

Recipe 19.6. Calling Flash Remoting Methods with Components

Problem

You want to call a Flash Remoting method without having to write much Action-Script.

Solution

Use the RemotingConnector component.

Discussion

Flash Remoting is a technology that enables incredibly effective and efficient client server communications with Flash applications. Flash Remoting works in a manner similar to that of web services in many respects. It allows Flash clients to call methods of services that may be written in Java, PHP, .NET, or other languages. However, Flash Remoting uses a binary messaging format called AMF that is native to Flash Player. Thus Flash Remoting is often significantly faster than web services.

Flash Remoting requires a server-side gateway that is capable of receiving the AMF requests, delegating the requests to the appropriate services, and returning the AMF responses. ColdFusion ships with a Flash Remoting gateway by default. So does JRun. Macromedia also sells Flash Remoting gateway products for J2EE application servers and .NET. You can learn more about the Macromedia Flash Remoting products at . In addition, there are non-Macromedia Flash Remoting gateway products. WebOrb () is available in both standard (free) and professional editions. WebOrb is available in both J2EE and .NET versions. FLAP () is an open source product for Perl and Python. AMFPHP () is an open source product for PHP. And OpenAMF () is an open source product for J2EE.

Although to utilize Flash Remoting fully it's recommended that you use Action-Script, the necessary ActionScript may involve a relatively steep learning curve for a Flash developer with little ActionScript experience. For basic Flash Remoting operations, you can use the RemotingConnector component that requires little to no Action-Script. The RemotingConnector component is the focus of this recipe.

The RemotingConnector component does not ship with Flash. However, if you have Flash Professional, you can download the RemotingConnector component for free from . When you've installed the component, it will be available from the Data Components folder of the Components panel.

The first step is to add an instance of RemotingConnector to the stage. You can drag an instance from the Components panel to the stage, and then assign the component an instance name (exp 3pod.com). After you've assigned an instance name (exp 3pod.com), you can assign values to parameters. To do so, select the instance and open the Component Inspector panel. Then assign values to the following parameters:


gatewayUrl

The URL to the gateway. The gateway is the server resource that parses AMF and delegates the requests to the appropriate services. It's a servlet, ASP.NET page, PHP page, and so on, and it's always the same regardless of what service you are requesting.


servicename (exp 3pod.com)

The name (exp 3pod.com) of the service you are requesting. Generally, it's the fully qualified class name (exp 3pod.com).


methodname

The name (exp 3pod.com) of the method from the service that you want to call.

Unlike the WebServiceConnector component, the RemotingConnector component doesn't automatically populate the schema. That means that you have to correctly define the schema. With the RemotingConnector component, you generally have to define the schema by way of the add and delete field buttons in the Schema tab. From the Component Inspector panel, select the Schema tab. Then use the add and delete buttons in the upper-left corner of the tab. The button on the far left adds a new top-level field. Generally that is unnecessary, as Flash Remoting operations consist of requests (params) and responses (results). You can use the second button to define new fields nested under params and/or results. For example, if a Flash Remoting method requires two parameters, you would want to define two fields nested under params. For each field you can use the name (exp 3pod.com)/value portion of the panel to define the correct name (exp 3pod.com) and data type.

As with the XMLConnector and WebServiceConnector components, you need to tell Flash when to make the Flash Remoting request. You can accomplish that with the trigger( ) method. The RemotingConnector class defines a trigger( ) method that you can call from the instance. Place the ActionScript code on the first keyframe if you want to make the call as soon as the application starts. Place the code within a button event handler method if you want to make the call when the user clicks a button.

You can download a working example file from .


Previous Page
Next Page

 

bluedot bluedots greydots pinkdots

Tripod >> 3pod Tips & Learning and manuals for educations