Flash Remoting 101: Setup and First Invoke
This post continues the "Flash Remoting 101" mini-tutorial series. Previous post describing what Flash Remoting is is available here. To get started you will need to install the following products:
- Flash 8 (or any previous version)
- Flash Remoting Components for Flash 8 ActionScript 2.0
- WebORB for Java or .NET
- IDE of your choice. (Visual Studio 2005 for .NET, any Java IDE for Java)

Paste the following code into the Actions panel:
import mx.remoting.Service;
import mx.remoting.PendingCall;
import mx.rpc.RelayResponder;
import mx.rpc.ResultEvent;
import mx.rpc.FaultEvent;
// if using WebORB for Java, the URL should be:
// http://localhost:8080/weborb
var webORBURL = "http://localhost/weborb/weborb.aspx";
var serviceProxy = new Service( webORBURL, null,
"weborb.tests.PrimitiveTest",
null, null);
var callObj:PendingCall = serviceProxy.echoInt( 21 );
callObj.responder = new RelayResponder( this, "echoIntResponse", "echoIntFailure" );
function echoIntResponse( resultEventObj:ResultEvent )
{
trace( "server returned - " + resultEventObj.result );
}
function echoIntFailure( fault:FaultEvent )
{
trace( "received error - " + fault.fault );
}
The code above creates a proxy for a server-side object of the weborb.tests.PrimitiveTest class. The code then invokes the echoInt() method and passes a hardcoded argument (21). The RelayResponder object specifies two methods: one receives a result from the successful method invocation and the other to be called if an error occurs.
On the server side, create a class with the following code:
Java:
package weborb.tests;
public class PrimitiveTest
{
public int echoInt( int i )
{
return i;
}
}
.NET (C#)
namespace weborb.tests
{
public class PrimitiveTest
{
public int echoInt( int i )
{
return i;
}
}
}
Compile the code and deploy it into WebORB. If you are running Java, PrimitiveTest.class must be copied into [WEBORB HOME]\webapp\WEB-INF\classes\weborb\testsTo run WebORB for Java, open a command prompt window, change directory to [WEBORB HOME] and run the following command: "java -jar weborb.jar".
With .NET, you can compile the class in a separate "class library" project and copy the project output assembly into \Inetpub\wwwroot\weborb\bin. The class will be automatically deployed and exposed to Flash client.
Now the server side is ready to accept a Flash Remoting method invocation. To run the client return to Flash 8 and press Ctrl + Enter. Flash runs the movie and invokes the method on the server object.
If you would like to bypass server-side configuration and run the example against a WebORB installation on our server, use the following as the WebORB URL:
"http://www.themidnightcoders.com/examples/weborb.aspx"







0 Comments:
Post a Comment
<< Home