Create your Value objects in AS 3 and .NET e.g.
ActionScript 3.0 :
- Code: Select all
package vo
{
public class ActivityVO
{
public function ActivityVO()
{
}
private var activitySubject:String;
private var activityEvent:String;
public function get ActivitySubject():String
{
return activitySubject;
}
public function set ActivitySubject(value:String):void
{
activitySubject = value;
}
public function get ActivityEvent():String
{
return activityEvent;
}
public function set ActivityEvent(value:String):void
{
activityEvent = value;
}
}
}
.NET (C#):
- Code: Select all
namespace TimeLineServices.vo
{
public class ActivityVO
{
private string activitySubject;
public string ActivitySubject
{
get { return activitySubject; }
set { activitySubject = value; }
}
private string activityEvent;
public string ActivityEvent
{
get { return activityEvent; }
set { activityEvent = value; }
}
}
}
In your FluorineFx service or RPC create something like this example which has two methods, one that returns an object of type ActvityVO and another which returns an Array of ActivityVO objects:
- Code: Select all
public ActivityVO GetActivity()
{
ActivityVO activityTest = new ActivityVO();
activityTest.ActivityEvent = "test event";
activityTest.ActivitySubject = "test subject";
return activityTest;
}
public Array GetActivities()
{
ArrayList list = new ArrayList();
ActivityVO activityTest = new ActivityVO();
activityTest.ActivityEvent = "test event";
activityTest.ActivitySubject = "test subject";
list.Add(activityTest);
string query = "SELECT * FROM Activities";
using (SqlConnection connection = new SqlConnection(connString))
{
SqlCommand command = new SqlCommand(query, connection);
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
ActivityVO activity = new ActivityVO();
if (!reader.IsDBNull(reader.GetOrdinal("Subject")))
activity.ActivitySubject = reader.GetString(reader.GetOrdinal("Subject"));
if (!reader.IsDBNull(reader.GetOrdinal("Event")))
activity.ActivityEvent = reader.GetString(reader.GetOrdinal("Event"));
list.Add(activity);
}
}
}
return list.ToArray();
}
In your ActionScript class, call the RPC using something like this:
- Code: Select all
package services
{
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
import flash.net.Responder;
import flash.net.registerClassAlias;
import vo.ActivityVO;
public class TestDAO
{
private var _connection:NetConnection;
private var _responder:Responder;
public function TestDAO()
{
registerClassAlias("TimeLineServices.vo.ActivityVO", ActivityVO);
_connection = new NetConnection();
_connection.objectEncoding = ObjectEncoding.AMF3;
_connection.connect(Main.SERVICE_URL);
}
public function GetActivities():void
{
var responder:Responder = new Responder(onResult, onFault);
//_connection.call("TimeLineServices.Sample.GetActivity", responder);
_connection.call("TimeLineServices.Sample.GetActivities", responder);
}
private function onResult(result:Object):void
{
var activities:Array = result as Array;
var activity:ActivityVO = activities[0] as ActivityVO;
//var activity:ActivityVO = result as ActivityVO;
trace(activity.ActivitySubject);
}
private function onFault(error:Object):void
{
trace("error: " + error.description);
}
}
}
Notice the line registerClassAlias("TimeLineServices.vo.ActivityVO", ActivityVO); inside the AS 3.0 class TestDAO. This is how you link up the ActionScript Value Objects to the Remote versions in .NET.
In AS2.0 you would have used Object.registerClass but this has been dropped in AS 3.0.
Notice also that the .NET service GetActivities returns an Array. Even though I build the items in an ArrayList inside the service, I still have to return an Array so I use return list.ToArray(); this is because Flash doesn't know about complex objects such as ArrayCollection which is what you would have cast to in Flex 2/3.
If I there is a better way to do that above PLEASE let me know as I am still learning how to integrate FluorineFx with AS 3.0 and Flash CS3 and I have probably made mistakes.
Also, I haven't yet tried an example of sending a Value Object back to .NET to update the database so I will try that now.
Hope this helps anyone!

