Using Flash Remoting MX, you can invoke .NET assembly files (*.dll) from Flash. In your ActionScript code, you use the fully qualified assembly or class file name in the getService function, and for the service function name, you use an assembly or class method name. On the server, you must place your DLL and class files in the local assembly cache.
In the class file, you reference the Flash Remoting assembly namespace FlashGateway.IO with the using directive, as the following C# example shows:
using System;
using FlashGateway.IO;
namespace FlashRemoting.EchoTests
{
public class EchoClass
{
public EchoClass()
{
///Public constructor... initialize any member fields here if need be.
}
public string echoString(string s)
{
return s;
}
}
}
In the ActionScript, you use the namespace and public class name defined in the class file, as the following example shows:
#include "NetServices.as"
#include "NetDebug.as"
if (inited == null)
{
inited = true;
NetServices.setDefaultGatewayUrl("http://localhost/myASPApp/default.aspx");
gatewayConnection = NetServices.createGatewayConnection();
classService = gatewayConnection.getService("FlashRemoting.EchoTests.EchoClass");
classService.echoString(input.text);
}
function echoString_Result(result)
{
stringDisplay.text = result;
}
function echoString_Status(result)
{
stringDisplay.text = error.description;
}
In the code, you use the fully qualified class name (FlashRemoting.ClassService.EchoClass) in the getService function. To call an assembly method, you use the class method name (echoString) as defined in the class file.
You can use the ASObject class of the FlashGateway.IO namespace to create and populate ActionScript objects in ASP.NET and return the object to Flash. By passing ActionScript objects back and forth between the remote service and the Flash application, you can describe the data being passed with the ASType property of the ASObject class.
In the assembly, you create an instance of the ASObject class of the FlashGateway.IO namespace and return it to Flash. The ASType property lets you assign a name to the object for identification in Flash. To add values to the object, you use the Add method common to instances of the .NET Collections class, as the following C# example shows:
using System;
using FlashGateway.IO;
namespace FlashRemoting.ObjectTests
{
public class ObjectClass
{
public ObjectClass()
{
///Public constructor... initialize any member fields here if need be.
}
public ASObject returnObject()
{
ASObject aso = new ASObject();
aso.ASType = "Calculator";
aso.Add("x", 100);
aso.Add("y", 300);
Flash.Result = aso;
}
}
}
In the code, an instance of the ASObject object, named aso, is created, and the ASType property is used to identify the object as Calculator. The Add method inserts key-value pairs into the object. Finally, the aso object is returned to Flash using the Flash.Result variable.
The following ActionScript handles the ActionScript object returned by the assembly:
#include "NetServices.as"
#include "NetDebug.as"
if (inited == null)
{
inited = true;
NetServices.setDefaultGatewayUrl("http://localhost/myASPApp/gateway.aspx");
gatewayConnection = NetServices.createGatewayConnection();
dataService = gatewayConnection.getService("FlashRemoting.ObjectTests.ObjectClass", this);
}
//Ask the server for some raw data...
dataService.returnObject();
//Provide a callback for getNumbers() when the data returns from the server
function returnObject_Result ( result )
{
/*
Because we expect the result to represent the state of a Calculator instance
back from the server, we can assume the result will have an add() method.
*/
resultBox.text = result.add();
}
/*
Rich Client Business Logic
*/
calc = function()
{
this.x = 0;
this.y = 0;
}
calc.prototype.subtract = function()
{
return this.x - this.y;
}
calc.prototype.add = function()
{
return this.x + this.y;
}
Object.registerClass("Calculator", calc);
stop();
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/usingFRNET6.htm
Comments
ritzcoder said on Feb 5, 2003 at 1:39 PM : csabi said on Jun 20, 2003 at 10:38 AM : csabi said on Jun 23, 2003 at 9:52 AM : agentofchange said on Sep 30, 2003 at 7:49 PM : Lim Hoe Keat said on Nov 13, 2003 at 8:07 PM : No screen name said on Nov 26, 2003 at 2:15 PM : pete said on Dec 3, 2003 at 10:06 AM : No screen name said on Jan 19, 2004 at 8:13 AM : troublesome96 said on Feb 18, 2004 at 7:41 PM : Rooster60602 said on Aug 31, 2004 at 6:53 AM : No screen name said on May 8, 2005 at 10:36 PM :