Flash, ActionScript 3.0 and FluorineFx example

Discussions relating to the examples & Your samples

Flash, ActionScript 3.0 and FluorineFx example

Postby hobbis » Tue Mar 04, 2008 11:50 am

Returning Value Objects in Flash CS3 from FlourineFx....

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!
hobbis
 
Posts: 26
Joined: Tue Feb 05, 2008 3:47 pm
Location: Kent, UK

Re: Flash, ActionScript 3.0 and FluorineFx example

Postby Support » Thu Mar 06, 2008 3:23 pm

If the client is Flash only you can use the useLegacyCollection tag in the service-config file. If useLegacyCollection is set to true all list types will be serialized as arrays and not as ArrayCollections.
(Of course this can be set for Flex clients too if required)
Support
Site Admin
 
Posts: 271
Joined: Thu Jan 24, 2008 12:45 pm

Re: Flash, ActionScript 3.0 and FluorineFx example

Postby sm3gh34d » Thu Jul 17, 2008 1:28 pm

Hi there!

I loved your sample solution. Could I ask if you possible have put this together in a little
magic zip file with the .fla´s and the .cs etc?

I am stuck implementing an app that uses a classfile.cs file in the app_code folder of
my project, a gateway.aspx file and a a myflashfile.html file that loads the .swf. If you
could help me with uploading that example of your as a zip, then maybe this could help
me out, because simply cutting and pasting and tweaking hasnt worked out for me.

I am sure I am only missing out on a stupid little thing, but nevertheless, without getting
it working, I cant move forward with my project right now.

Best Regards

/Peter
sm3gh34d
 
Posts: 3
Joined: Thu Jul 17, 2008 1:20 pm

Re: Flash, ActionScript 3.0 and FluorineFx example

Postby hobbis » Thu Jul 17, 2008 1:31 pm

I'm afraid it's a bunch of files inside a huge development project now. It might be better to send me your stuff and I can take a look?
hobbis
 
Posts: 26
Joined: Tue Feb 05, 2008 3:47 pm
Location: Kent, UK

Re: Flash, ActionScript 3.0 and FluorineFx example

Postby sm3gh34d » Thu Jul 17, 2008 8:31 pm

Hi again,

Thanks for the suggestion, and I totally understand that if its a part of a big project you
cant send the files. ;) Do you maybe have a simple example using c#, flash and fluorine
perhaps? My files are also a big hubbleflubble right now, so there is no real use to sending
them. The fluorine examples are good and all, but a super simplified app that;

has a .cs file (in the app_code directory) that has a namespace, class and a method
a gateway.aspx that loads the .cs namespace
a swf file that simply runs the method and shows it in a label or textfield or something in
the swf

Cheers and thanks for your time!

/Peter
sm3gh34d
 
Posts: 3
Joined: Thu Jul 17, 2008 1:20 pm

Re: Flash, ActionScript 3.0 and FluorineFx example

Postby hobbis » Fri Jul 18, 2008 8:33 am

hobbis
 
Posts: 26
Joined: Tue Feb 05, 2008 3:47 pm
Location: Kent, UK


Return to FluorineFx Examples

Who is online

Users browsing this forum: No registered users and 1 guest

cron