7 Replies Latest reply on Feb 20, 2007 11:23 AM by blastbeat

    Cannot find CFC

    blastbeat
      All, I am receiving a CANNOT FIND CFC error when trying to run this app. This is my first Flex app and I am simply trying to bind a query result from a CFC to a datagrid.

      Here's my code. I have verified the CFC is there and works.

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

      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;

      public function initApp():void{
      qryUsers.selectAll();

      }
      [Bindable]
      public var myResult:Object;
      public function myMethodResult(event):void {
      myResult = event.result;
      }
      ]]>
      </mx:Script>

      <mx:RemoteObject id="qryUsers" source="employees" destination="ColdFusion">
      <mx:method name="selectAll" result="myMethodResult(event)" />
      </mx:RemoteObject>

      <mx:Panel width="90%" height="90%" cornerRadius="5" title="Employee Phone List" horizontalAlign="center" verticalAlign="middle" horizontalCenter="3" verticalCenter="5">
      <mx:DataGrid x="10" y="10" width="100%" height="100%" id="employeeList" dataProvider="{myResult}">
      <mx:columns>
      <mx:DataGridColumn headerText="First Name" dataField="column1" />
      <mx:DataGridColumn headerText="Last Name" dataField="column2"/>
      <mx:DataGridColumn headerText="E-Mail" dataField="column3"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Panel>


      </mx:Application>
        • 1. Re: Cannot find CFC
          Robert S
          This simply means that it can't find the employees.cfc file. Based on the above source="employees" - your employees.cfc file would have to be in the same folder directory as your mxml application.
          • 2. Cannot find CFC
            blastbeat Level 1
            I thought it was, so I removed all the CFC's and re-copied them to the directory, as well as to the root of my wwwroot and it is not erroring now. However, it's not returning data either.

            I don't believe Flex Data Services is installed correctly as I cannot access the samples directory from my wwwroot. Is it supposed to install in there? It put everything inside c:\fds Any tips?
            • 3. Re: Cannot find CFC
              Robert S Level 1
              I am assuming you are not using Flex Builder for this as it would be throwing a lot of "Warnings" to the lack of type-casting/association.

              1. Your DataGridColumn dataFields should be the same as your database column names - not 'column1' 'column2', etc (unless that's what they are actualy named in the database).

              2. Your variable and function are scoped as "public", this works, but is not good coding - they should be private unless OTHER components or classes in the application are going to access them.

              3. Your data variable (myResult) is cast as an "Object". This should be cast as an ArrayCollection as that is what the DataGrid is looking for and the result from the RemoteObject will return in it's native format.

              4. Your assignment of event.result to myResult needs type coercion like: myResult = event.result as ArrayCollection;

              5. I like to put my [Binding] metatags in front of my variable declaration as opposed to above it... putting it above always makes me assocated a "package". But that's just preference like;

              [Bindable] private var _myResult:ArrayCollection;

              I hope this helps you get started. There are a number of posts for both getting the ColdFusion server ready for Flex use and cross-domain policies and such... pretty easy stuff - just search the forum.
              • 4. Re: Cannot find CFC
                Robert S Level 1
                I figure it's best to show the full sample as below. Notice that I scope private variables with the '_'... this you will appriciate as you get more advanced. I can't confirm the actual run of this as I do not have the cfc nor the database you have. Also, check those column dataFields.

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

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

                [Bindable] private var _myResult:ArrayCollection;

                private function initApp():void{
                qryUsers.selectAll();
                }

                private function myMethodResult(event:ResultEvent):void {
                _myResult = event.result as ArrayCollection;
                }
                ]]>
                </mx:Script>

                <mx:RemoteObject id="qryUsers" source="employees" destination="ColdFusion">
                <mx:method name="selectAll" result="myMethodResult(event)" />
                </mx:RemoteObject>

                <mx:Panel width="90%" height="90%" cornerRadius="5" title="Employee Phone List" horizontalAlign="center" verticalAlign="middle" horizontalCenter="3" verticalCenter="5">
                <mx:DataGrid x="10" y="10" width="100%" height="100%" id="employeeList" dataProvider="{_myResult}">
                <mx:columns>
                <mx:DataGridColumn headerText="First Name" dataField="column1" />
                <mx:DataGridColumn headerText="Last Name" dataField="column2"/>
                <mx:DataGridColumn headerText="E-Mail" dataField="column3"/>
                </mx:columns>
                </mx:DataGrid>
                </mx:Panel>

                </mx:Application>
                • 5. Re: Cannot find CFC
                  blastbeat Level 1
                  Thanks for the thorough response Robert, I will try this when I get back in the office. Thanks again for taking the time to help a newb!
                  • 6. Re: Cannot find CFC
                    phi2265 Level 1
                    what compile method are you using on your project? do you view an html or do you view the mxml? i'm not sure about the html option but i know for the mxml you have to access it on port 8700 ex: http://localhost:8700/flex/project_name/index.mxml
                    • 7. Re: Cannot find CFC
                      blastbeat Level 1
                      Hi Robert,

                      I am not getting an error now but 0 rows are being returned to my datagrid and I am getting an error when trying to sort because of it. My CFC does indeed return results. Here's the code for that, not sure what's up?

                      <cfcomponent>
                      <cffunction name="selectAll" access="remote">

                      <cfstoredproc procedure="uspGetUsers" datasource="PeopleDeliverySD">
                      <cfprocresult name="qryGetUsers" resultset="1">
                      </cfstoredproc>

                      <cfreturn qryGetUsers>

                      </cffunction>
                      </cfcomponent>