Groups | Blog | Home
all groups > macromedia flash flash remoting > august 2004 >

macromedia flash flash remoting : Passing objects to .NET...Here's how!


Rooster60602
8/31/2004 3:40:52 PM
After a lot of digging around, I ran across a post in Tom Muck's blog about
passing generic objects from Flash to a .NET assembly. Documentation for
FR/.NET states that objects can be passed "back and forth" between Flash and
..NET, and MacroMedia provides some info on getting objects from .NET into Flash
using the ASObject, BUT no mention is made about getting generic objects from
Flash into .NET. Previous workarounds dealt with converting generic object
(which is handy for a lot of things, particularly in a cookieless ecomm app
I've been developing) to an array, but I've found a way to pass the object
itself...

The key is understanding that ASObject inherits from the Hashtable class in
..NET (even with "using FlashGateway.IO;" I was getting errors when declaring
ASObject in my method), but declaring Hashtable works fine. Here are a couple
examples...

FLASH
-----------------------------------------------
#include "NetServices.as"
#include "NetDebug.as"
if (init == null)
{
gateway = "http://mysite.com/gateway.aspx";
NetServices.setDefaultGatewayUrl(gateway);
var conn = NetServices.createGatewayConnection();
classService = conn.getService("mysite.FormHandler", this);
}
butTest.onRelease = function()
{
var myObject = [];
myObject.from = "test@fromJohn.com";
myObject.myMessage = "test message from john in FLASH...";
classService.myFormHandlerOBJECT(myObject);
};

.NET CLASS
--------------------------------------
public void myFormHandlerOBJECT(Hashtable myObject)
{
MailMessage mailMsg = new MailMessage();
//ASObjects from flash inherit from HashTable class, so use Key to get
value IDictionaryEnumerator myEnum = myObject.GetEnumerator();
string a = (string) myObject["from"];
string b = "";
while (myEnum.MoveNext())
{
b = myEnum.Key + " : " + myEnum.Value; //another way to grab hashtable
values..."b" not used in this sample
}
//get value using key (generic object property name in Flash)
string c = (string) myObject["myMessage"];
mailMsg.From = a;
mailMsg.To = "testemail@test.com";
mailMsg.Subject = "Web inquiry";

StringBuilder sbMailMsg = new StringBuilder();
sbMailMsg.Append("\n");
sbMailMsg.Append(c); //value (retrieved using key above) from object passed
from Flash
SmtpMail.SmtpServer = "192.168.1.2";
string strMessage = sbMailMsg.ToString();
mailMsg.Body = strMessage;
SmtpMail.Send(mailMsg);
}
mrism
9/1/2004 11:17:14 AM
hi rooster, this looks good. unfortunately i'm done with 80% of project by now
so can't change much and array has worked alright for me upto now... but i'll
surely try to transfer generic object this way next time around. thanks..
cheers.
AddThis Social Bookmark Button