6 Replies Latest reply on Feb 22, 2008 10:24 AM by UberError

    Passing a Flex object to CFC

      I have no problem passing a query object to my Flex app and use it to populate a datagrid (arraycollection).... however, I want to use this same data to update the database when the user clicks on save, and instead of looping through each row (calling my remoteobject each time) is there a way I can format this information into an array, array collection or some other form of flex object and pass ti back to another cfc function to do the update?????

      I've read elsewhere that its possible to do with a remoteobject, however, my attempts were futile and I cannot find an example anywhere.

      I cant find a solution anywhere so and help would be appreciated.
        • 1. Re: Passing a Flex object to CFC
          Gregory Lafrance Level 6
          I would think using a model with data binding would be the way to provide this kind of two way data update. The FB 2.0.1 help topic "Storing Data" has several sub-topics that seem relevant.
          • 2. Re: Passing a Flex object to CFC
            UberError Level 1
            I read through it but didn't find anything that would point me in the right direction.

            I'm amazed no one else tried to do this.

            I've googled and came up with nothing... apparently everyone just sends simple datatypes to their cfc's

            • 3. Re: Passing a Flex object to CFC
              Garyl Woolworth Level 1
              Arrays work the same way when passing between Flex and Coldfusion aside from the item in 0 on Flex is at 1 when it hits Coldfusion. The only tricky part is passing an Object from Flex to Coldfusion, say you have var credentials:Object = {username:"test", password:"pass123"}; You would think Coldfusion would treat this as a struct and you could do credentials.username however what it ends up doing is passing them as seperate parameters so your Coldfusion needs to have <cfargument name="username" type="string"/>,<cfargument name="password" type="string"/>. I pass complex data types all the time so yes "someone has tried to do this before." I use RemoteObjects as well for remoting.
              • 4. Re: Passing a Flex object to CFC
                UberError Level 1
                I've done that as well (using an Object with multiple vars)... I need the complex object in my cfc function to loop through... cfargument of type array, list, query, etc

                Ive tried the following:

                <mx:RemoteObject ....
                <mx:method name="updateData" ...

                Your first sentence implies that this should work... if it does, can you please provide a quick code sample?

                • 5. Re: Passing a Flex object to CFC
                  Garyl Woolworth Level 1
                  Here is a simple example I just wrote real quick. This is how I normally go about passing something an array of items to Coldfusion. Hope this helps.

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">


                  import mx.controls.Alert;
                  import mx.managers.CursorManager;
                  import mx.rpc.events.ResultEvent;
                  import mx.rpc.events.FaultEvent;

                  [Bindable] private var apples:Array = new Array(
                  {name:"Normal Apple", color:"Red"},
                  {name:"Sweet Apple", color:"Ged"},
                  {name:"Rotten Apple", color:"Brown"});

                  private function createApples():void {

                  private function createApplesResult(event:ResultEvent):void {
                  Alert.show("You have successfully added some apples into our system.", "System Notice");


                  endpoint="Your endpoint here"
                  fault="CursorManager.removeBusyCursor();Alert.show(event.fault.message, 'System Notice')">
                  <mx:method name="Create_Apples" result="createApplesResult(event)"/>

                  <mx:Button x="10" y="10" label="Create Apples" click="createApples()"/>
                  <mx:DataGrid left="10" right="10" top="40" bottom="10" dataProvider="{apples}">
                  <mx:DataGridColumn headerText="Apple Name" dataField="name"/>
                  <mx:DataGridColumn headerText="Apple Color" dataField="color"/>
                  • 6. Re: Passing a Flex object to CFC
                    UberError Level 1
                    Thanks, that worked!!!

                    In several of my tests I tried to pass an ArrayCollection instead of just the array.

                    Thanks again!