19 Replies Latest reply on Aug 25, 2006 2:40 PM by GeorgeWS

    flex 2.0 RemoteObject

    GeorgeWS Level 1
      have a remoteObject that calls in cfc data. I want to send a variable along with the remoteObject to the cfc. What is the syntax in the remoteObject to send the variable? and what does the WHERE part of the cfc look?

      Thanks
      George

      I did try this inside the remote object but I get an error saying element SUPPLIERID is: undefined in ARGUMENTS

      <mx:method name="SupplierID">
      <mx:agruments>
      <SupplierID>
      {Application.application.parameters.SupplierID}
      </SupplierID>
      </arguments>
      </method>
        • 1. Re: flex 2.0 RemoteObject
          peterent Level 2
          Using the Application.application.parameters means the SupplierID would have to be coming from the URL which is invoking the Flex SWF. More than likely the value you want to send to the CFC is already a variable in your application.

          I find it easier to call remote object methods as if they were local functions and avoid the <mx:arguments> and data binding thing.

          If ro is your RemoteObject and your CFFunction is updateSupplier, then:

          ro.updateSupplier( supplierID );

          will do the trick. You just have to know where the value for the argument is coming from.
          • 2. Re: flex 2.0 RemoteObject
            GeorgeWS Level 1
            Thanks, but I dont understand. The variable does come in from the URL to the SWF as in test.swf?SupplierID=30

            I can display the variable SupplierID just fine, using the Application.application.parameters. I want to send that variable along with the RemoteObject call so the query fills the grid with just the SupplierID = 30. What would this look like. My cfc works good if I set the param = 30 or some other number.
            • 3. Re: flex 2.0 RemoteObject
              peterent Level 2
              Sorry, I forgot.

              ro.updateSupplier( Application.application.parameters.SupplierID );

              should work.
              • 4. Re: flex 2.0 RemoteObject
                GeorgeWS Level 1
                Since im a complete dumby. Where do I put that line?

                and does ro = the same as remoteObject?
                What ios the updateSupplier and where does that come from?

                Thanks alot
                • 5. Re: flex 2.0 RemoteObject
                  peterent Level 2
                  ro means the ID of your RemoteObject tag:

                  <mx:RemoteObject id="whatever" ... > so ro would be whatever in this case.

                  and since I didn't carefully read your question, I meant to use SupplierID as the method name (I put updateSupplier).

                  You put this line of code where you want to make the call to the CFC:

                  whatever.SupplierID( Application.application.parameters.SupplierID );

                  I would recommend not naming your CFFunction that as the parameter, but this should work.
                  • 6. Re: flex 2.0 RemoteObject
                    GeorgeWS Level 1
                    Peter,
                    Thank you; but believe it or not im still stummped I need complete visual examples.

                    I have this:

                    <mx:RemoteObject
                    id="qResult"
                    destination="ColdFusion"
                    source="Inventory"
                    showBusyCursor="true">

                    WHAT GOES HERE? (do I need the mx:method? do I need the mx:arguments? do I need the <SupplierID></SupplierID>

                    </mx:RemoteObject>
                    • 7. Re: flex 2.0 RemoteObject
                      peterent Level 2
                      George,

                      Before your level of frustration gets too high, I recommend you take a step back and go through the Flex tutorials. This will get you a foundation for ActionScript and how Flex is put together. Here's the link:

                      Flex Developer Center, Quick Starts Page

                      On the lower right side of the page, in the bar on the edge, you'll see a heading called "Flex Tutorials and Samples". In that section there is additional information and specifically, "Data Integration and Services".

                      If you've done the tutorials, then skip over to the "Data Integration and Services" section. After going through this, I hope you find what I've been saying to make more sense.
                      • 8. Re: flex 2.0 RemoteObject
                        GeorgeWS Level 1
                        Peter,
                        thanks for the advice. But I have gone through the ultra confusing data tutorials. Where hardly any deals with simple stuff like passing a variable using the Remote Object. I follow the livedocs RO sample and it makes sence but does not work yes very frustrating.

                        anyone else,
                        This is what I have I hard coded the variable. Im thinking this is sending 430 to the CFC
                        <mx:RemoteObject
                        id="qResult"
                        destination="ColdFusion"
                        source="Inventory"
                        showBusyCursor="true">

                        <mx:method name="SupplierID">
                        <mx:agruments>
                        <SupplierID>430</SupplierID>
                        </mx:arguments>
                        </mx:method>
                        </mx:RemoteObject>

                        What could be wrong with this?

                        The CFC has a query with a WHERE SupplierID = #SupplierID#

                        Thanks
                        • 9. Re: flex 2.0 RemoteObject
                          peterent Level 2
                          Let's see if this helps (it is unfortunate that this editor does not allow whitespace to make this easier to read):

                          <mx:RemoteObject id="qResult" destination="ColdFusion" source="Inventory" showBusyCursor="true">
                          <mx:method name="SupplierID" />
                          </mx:RemoteObject>

                          Notice that I took out the arguments. I did that because it is awkward to use that syntax when dealing with the Application parameters.

                          Now suppose you have a Button that when you click it, invokes the SupplierID request on the inventory CFC:

                          <mx:Button label="Test It" click="makeInventoryRequest()" />

                          Now you have to define the makeInventoryRequest function in a Script block:

                          <mx:Script>
                          private function makeInventoryRequest() : void
                          {
                          qResult.SupplierID( Application.application.parameters.SupplierID );
                          }

                          This will make the call, passing the value of the query parameter, SupplierID, to the SupplierID function of the inventory CFC.

                          Somewhere in your code you are doing qResult.SupplierID.send() - replace that with the contents of my function and you should be good to go.
                          • 10. Re: flex 2.0 RemoteObject
                            GeorgeWS Level 1
                            I am sorry I have to keep asking questions but I can not fail on this, I need to know how to change my apps from cfform's to flex. In cfforms its easy you use th cfinvoke and and argument done!

                            I try this and I get an error when I press the button (is says The method SupplierID could not be found in component). I dont have a button in my app to call data so im not sure about that part. And I dont see anywhere in my code that has a send(). Maybe Im not making sence. I am using the RemoteObject to fill in a grid with ALL of the inventory (so I can see it all). I also have suppliers that login and I want to use the variable SupplierID (we got that part using the Application.application.parameters.SupplierID). I want the RemoteObject to call ALL of the data that is equal to that supplier number so the supplier will only see their data. What could I be missing? I dont see why the call goes to a function that is using the qResults. Thats to late all of the data has been pulled already right? I just want to pull a suppliers part of data.

                            Thanks
                            George
                            • 11. Re: flex 2.0 RemoteObject
                              peterent Level 2
                              OK, one step at a time. From what you've written, you have a CFC called "inventory" - that is what you have in your RemoteObject definition. Is that correct?

                              If not, what is the CFC you are trying to use and what is the CFFunction within that CFC you are trying to invoke. From what you wrote, I thought it was "SupplierID" because that is what name you gave the <mx:method>.

                              In RemoteObject, source= names your CFC (the full path to it without the .cfc extension) and the <mx:method name= is the CFFunction within that CFC.
                              • 12. Re: flex 2.0 RemoteObject
                                GeorgeWS Level 1
                                My CFC is called "Inventory" and the function in the CFC is called "Inventory". The variable I want passed into the CFC is called SupplierID.

                                This is what I have to get the data for the grid.

                                <mx:RemoteObject
                                id="qResult"
                                destination="ColdFusion"
                                source="Inventory"
                                showBusyCursor="true">

                                <mx:method name="Inventory" result="handleQueryResult(event)"/>

                                </mx:RemoteObject>

                                above works to fill the grid.

                                Now before filling the grid with ALL of the data I just want to get the data that is related to the SupplierID of say 430 (that comes from the URL like test.swf?SupplierID=430). How do I do that part of sending the 430 to the CFC so only the SupplierID = 430 items are showing in the grid?

                                Thanks for helping me.
                                • 13. Re: flex 2.0 RemoteObject
                                  peterent Level 2
                                  How is the remote object being called? Something has to be triggering it to make the request.
                                  • 14. Re: flex 2.0 RemoteObject
                                    GeorgeWS Level 1
                                    I have this:

                                    <mx:Script>
                                    <![CDATA[
                                    import mx.rpc.events.ResultEvent;
                                    import mx.controls.Alert;
                                    import mx.collections.ArrayCollection;

                                    [Bindable]
                                    public var myData:ArrayCollection;

                                    [Bindable]
                                    public var SupplierID:String;

                                    [Bindable]
                                    public var aReturnTypes: Array = [ {label:"query", data:"query"} ];

                                    [Bindable]
                                    public var returnType:String="string";

                                    public function clearAll():void{

                                    myData=new ArrayCollection();
                                    }

                                    public function handleQueryResult(event:ResultEvent):void{
                                    myData=event.result as ArrayCollection;
                                    myData.filterFunction=processFilter;
                                    }

                                    public function processFilter(item:Object):Boolean
                                    {
                                    var result:Boolean=false;
                                    var pattern:RegExp= new RegExp("^"+txtFilter.text,"i");
                                    if (!item.PDES5W.length
                                    || item.PDES5W.match(pattern))
                                    result=true;

                                    return result;
                                    }

                                    [Bindable]
                                    public var myfilter: Array = [ {label:"Description", data:"PDES5W"},
                                    {label:"Product ID", data:"PNUM5W"}, {label:"Size", data:"SDIVDE"}, {label:"Pack", data:"ISCF3W"}, {label:"Rank", data:"DIVN5W"} ];

                                    [Bindable]
                                    public var selectedItem:Object;

                                    private function initVars() : void {
                                    SupplierID = Application.application.parameters.SupplierID;
                                    }

                                    private function gotoURL() : void {
                                    var url:URLRequest = new URLRequest(" http://www.youngsmarket.com/youngsmarket/programs/inventory/Inventory.cfm?SupplierID="+App lication.application.parameters.SupplierID);
                                    navigateToURL(url);
                                    }

                                    ]]>
                                    </mx:Script>
                                    • 15. Re: flex 2.0 RemoteObject
                                      peterent Level 2
                                      Where is your RemoteObject tag? I see that you have a result handler, I just don't see your RemoteObject.

                                      I do notice that you have navigateToURL - did you intend to just take the user to a new page and leave the Flex application?
                                      • 16. Re: flex 2.0 RemoteObject
                                        GeorgeWS Level 1
                                        Peter,
                                        I did not sent the whole app. just the part you wanted to see. The Remote object is just like the one I copied and pasted above. In my app it is right below the script part.
                                        The second part with the navigateToURL does leave the page and goes to a CF page that I use to put the data into EXCEL. works perfect. Funny thing is that page recieves the variable SupplierID no problem. You can see the app as it is now here. http://www.youngsmarket.com/youngsmarket/programs/inventory/inventory/bin/inventory.swf?su pplierid=430

                                        when the download word on the right is pressed, you leave the flex app with the variable SupplierID that hits the query and pulls only the SupplierID = to say 430, Works great!

                                        my whole code is here:

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

                                        <mx:Script>
                                        <![CDATA[
                                        import mx.rpc.events.ResultEvent;
                                        import mx.controls.Alert;
                                        import mx.collections.ArrayCollection;

                                        [Bindable]
                                        public var myData:ArrayCollection;

                                        [Bindable]
                                        public var SupplierID:String;

                                        [Bindable]
                                        public var aReturnTypes: Array = [ {label:"query", data:"query"} ];

                                        [Bindable]
                                        public var returnType:String="string";

                                        public function clearAll():void{

                                        myData=new ArrayCollection();
                                        }

                                        public function handleQueryResult(event:ResultEvent):void{
                                        myData=event.result as ArrayCollection;
                                        myData.filterFunction=processFilter;
                                        }

                                        public function processFilter(item:Object):Boolean
                                        {
                                        var result:Boolean=false;
                                        var pattern:RegExp= new RegExp("^"+txtFilter.text,"i");
                                        if (!item.PDES5W.length
                                        || item.PDES5W.match(pattern))
                                        result=true;

                                        return result;
                                        }

                                        [Bindable]
                                        public var myfilter: Array = [ {label:"Description", data:"PDES5W"},
                                        {label:"Product ID", data:"PNUM5W"}, {label:"Size", data:"SDIVDE"}, {label:"Pack", data:"ISCF3W"}, {label:"Rank", data:"DIVN5W"} ];

                                        [Bindable]
                                        public var selectedItem:Object;

                                        private function initVars() : void {
                                        SupplierID = Application.application.parameters.SupplierID;
                                        }

                                        private function gotoURL() : void {
                                        var url:URLRequest = new URLRequest(" http://www.youngsmarket.com/youngsmarket/programs/inventory/Inventory.cfm?SupplierID="+App lication.application.parameters.SupplierID);
                                        navigateToURL(url);
                                        }

                                        private function makeInventoryRequest() : void
                                        {qResult.SupplierID(Application.application.parameters.SupplierID);}
                                        ]]>
                                        </mx:Script>

                                        <mx:RemoteObject
                                        id="qResult"
                                        destination="ColdFusion"
                                        source="Inventory"
                                        showBusyCursor="true"
                                        >

                                        <mx:method name="Inventory" result="handleQueryResult(event)" fault="Alert.show(event.fault.message)"/>
                                        <mx:method name="SupplierID" />
                                        </mx:RemoteObject>

                                        <mx:Panel title="Inventory" height="90%" width="100%"
                                        paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5" cornerRadius="10" roundedBottomCorners="true">


                                        <mx:HBox width="100%">
                                        <mx:Button label="test it" click="makeInventoryRequest()" />
                                        <mx:Label text="Filter:"/>
                                        <mx:TextInput width="100" id="txtFilter" change="myData.refresh()" />
                                        <mx:ComboBox id="columnfilter" dataProvider="{myfilter}" width="125"
                                        close="selectedItem=ComboBox(event.target).selectedItem"/>
                                        <mx:RadioButton label="Warehouse" click="accordion.selectedIndex=0;" selected="true"/>
                                        <mx:RadioButton label="Cash / Carry" click="accordion.selectedIndex=1;"/>
                                        <mx:RadioButton label="Storage" click="accordion.selectedIndex=2;"/>
                                        <mx:Spacer width="100%" height="20"/>
                                        <mx:LinkButton label="Download" click="gotoURL()" />
                                        </mx:HBox>

                                        <mx:Accordion id="accordion" width="100%" height="100%" headerHeight="5">
                                        <mx:VBox height="100%" >
                                        <mx:DataGrid dataProvider="{myData}" initialize="qResult.Inventory()" width="100%" height="100%">
                                        <mx:columns>

                                        <mx:DataGridColumn dataField="PNUM5W" headerText="Prod ID" width="55"/>
                                        <mx:DataGridColumn dataField="PDES5W" headerText="Desc" width="163"/>
                                        <mx:DataGridColumn dataField="SDIVDE" headerText="Size" width="50"/>
                                        <mx:DataGridColumn dataField="ISCF3W" headerText="Pac" width="35"/>
                                        <mx:DataGridColumn dataField="DIVN5W" headerText="Rnk" width="35"/>

                                        <mx:DataGridColumn dataField="INV_11" headerText="Or Inv" width="50"/>
                                        <mx:DataGridColumn dataField="ORD_11" headerText="Or Ord" width="50"/>
                                        <mx:DataGridColumn dataField="DAT_11" headerText="Or Due" width="50"/>
                                        <mx:DataGridColumn dataField="INT_11" headerText="Or InT" width="50"/>

                                        <mx:DataGridColumn dataField="INV_31" headerText="Ch Inv" width="50"/>
                                        <mx:DataGridColumn dataField="ORD_31" headerText="Ch Ord" width="50"/>
                                        <mx:DataGridColumn dataField="DAT_31" headerText="Ch Due" width="50"/>
                                        <mx:DataGridColumn dataField="INT_31" headerText="Ch InT" width="50"/>

                                        <mx:DataGridColumn dataField="INV_41" headerText="MH Inv" width="50"/>
                                        <mx:DataGridColumn dataField="ORD_41" headerText="MH Ord" width="50"/>
                                        <mx:DataGridColumn dataField="DAT_41" headerText="MH Due" width="50"/>
                                        <mx:DataGridColumn dataField="INT_41" headerText="MH InT" width="50"/>

                                        </mx:columns>
                                        </mx:DataGrid>
                                        </mx:VBox>

                                        I did remove 2 other datagrids so i could post all of this

                                        </mx:VBox>
                                        </mx:Accordion>
                                        </mx:Panel>
                                        </mx:Application>
                                        • 17. flex 2.0 RemoteObject
                                          GeorgeWS Level 1
                                          post deleted sorry i posted to many times
                                          • 18. flex 2.0 RemoteObject
                                            GeorgeWS Level 1
                                            same as above
                                            • 19. flex 2.0 RemoteObject
                                              GeorgeWS Level 1
                                              sorry again