Link to home
Start Free TrialLog in
Avatar of Mike Waller
Mike WallerFlag for United States of America

asked on

web services with flex 3

I'm building an app in flex 3 using coldfusion 8.  Does anyone know of an example app I can work with?  The app needs to do data exchange using cfc queries.
ASKER CERTIFIED SOLUTION
Avatar of Jones911
Jones911

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this: http://www.adobe.com/devnet/flex/flex_cf.html
Videos, tutorials and code examples.. :)
Avatar of Mike Waller

ASKER

Ok, so I found a CRUD example.  Now, I have my own cfc file on my own server.  Do I just change the source parameter in this line to point to my cfc file? .. <mx:RemoteObject id="ro" destination="ColdFusion" showBusyCursor="true" source="FlexCf.11.crud">

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="ro.getData()"  viewSourceURL="srcview/index.html">
      <mx:RemoteObject id="ro" destination="ColdFusion" showBusyCursor="true" source="FlexCf.11.crud">
            <mx:method name="getData" result="getDataResult(event)" />
            <mx:method name="saveNewData" result="getDataResult(event)" />
            <mx:method name="saveOldData" result="getDataResult(event)" />
            <mx:method name="deleteData" result="getDataResult(event)" />
      </mx:RemoteObject>
      <mx:Script>
            <![CDATA[
                  import mx.collections.ArrayCollection;
                  import mx.rpc.events.ResultEvent;
                  
                  private var isNew:Boolean = true;
                  
                  public function getDataResult(e:ResultEvent):void{
                        dg.dataProvider = e.result as ArrayCollection;
                        makeNew();
                  }
                  private function makeNew():void{
                        aName.text = "";
                        type.text = "";
                        isNew = true;
                  }
                  private function save():void{
                        if(isNew){
                              ro.saveNewData(aName.text,type.text);
                        }else{
                              ro.saveOldData(aName.text,type.text,dg.selectedItem.id);
                        }
                  }
                  private function deleteData():void{
                        if(dg.selectedIndex > -1 )ro.deleteData(dg.selectedItem.id);
                  }
            ]]>
      </mx:Script>
      <mx:DataGrid id="dg" change="isNew = false" width="366">
      </mx:DataGrid>
      <mx:Panel width="372" height="146" layout="absolute">
            <mx:Form top="0" bottom="0" right="0" left="0">
                  <mx:FormItem label="Name">
                        <mx:TextInput id="aName" text="{dg.selectedItem.name}"/>
                  </mx:FormItem>
                  <mx:FormItem label="Type">
                        <mx:TextInput id="type" text="{dg.selectedItem.type}"/>
                  </mx:FormItem>
            </mx:Form>
      </mx:Panel>
      <mx:Button label="New" click="makeNew()"/>
      <mx:Button label="Save" click="save()" />
      <mx:Button label="Delete" click="deleteData()" />  
</mx:Application>   1: <?xml version="1.0"?>
   2: <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="ro.getData()" viewSourceURL="srcview/index.html">
   3:     <mx:RemoteObject id="ro" destination="ColdFusion" showBusyCursor="true" source="FlexCf.11.crud">
   4:         <mx:method name="getData" result="getDataResult(event)" />
   5:         <mx:method name="saveNewData" result="getDataResult(event)" />
   6:         <mx:method name="saveOldData" result="getDataResult(event)" />
   7:         <mx:method name="deleteData" result="getDataResult(event)" />
   8:     </mx:RemoteObject>
   9:     <mx:Script>
  10:         <![CDATA[
  11:             import mx.collections.ArrayCollection;
  12:             import mx.rpc.events.ResultEvent;
  13:            
  14:             private var isNew:Boolean = true;
  15:            
  16:             public function getDataResult(e:ResultEvent):void{
  17:                 dg.dataProvider = e.result as ArrayCollection;
  18:                 makeNew();
  19:             }
  20:             private function makeNew():void{
  21:                 aName.text = "";
  22:                 type.text = "";
  23:                 isNew = true;
  24:             }
  25:             private function save():void{
  26:                 if(isNew){
  27:                     ro.saveNewData(aName.text,type.text);
  28:                 }else{
  29:                     ro.saveOldData(aName.text,type.text,dg.selectedItem.id);
  30:                 }
  31:             }
  32:             private function deleteData():void{
  33:                 if(dg.selectedIndex > -1 )ro.deleteData(dg.selectedItem.id);
  34:             }
  35:         ]]>
  36:     </mx:Script>
  37:     <mx:DataGrid id="dg" change="isNew = false" width="366">
  38:     </mx:DataGrid>
  39:     <mx:Panel width="372" height="146" layout="absolute">
  40:         <mx:Form top="0" bottom="0" right="0" left="0">
  41:             <mx:FormItem label="Name">
  42:                 <mx:TextInput id="aName" text="{dg.selectedItem.name}"/>
  43:             </mx:FormItem>
  44:             <mx:FormItem label="Type">
  45:                 <mx:TextInput id="type" text="{dg.selectedItem.type}"/>
  46:             </mx:FormItem>
  47:         </mx:Form>
  48:     </mx:Panel>
  49:     <mx:Button label="New" click="makeNew()"/>
  50:     <mx:Button label="Save" click="save()" />
  51:     <mx:Button label="Delete" click="deleteData()" />
  52: </mx:Application>
Avatar of Jones911
Jones911

source="FlexCf.11.crud"   is a mapping.    I'll assume you have access to cfadmin?

crud is the cfc and flex is the base mapping probably to d:\com  for flex is a mappign to d:\com  and in there is a director 11 and in there is the cfc

ie

d:\com\11\crud.cfc

You also need to enable mapping.  Let me know if you need help with that.
so you do that in cf administrator?  yes, how would you do that?  so then if we set up the mapping in administrator, then we would adjust the source path in the mxml file accordingly, correct?
I guess what I need is to create a webservice in flex that points to my cfc files.
Yep.

In cfadmin add the mapping.  This can be what ever you want but it needs to match in the MXML.

Then in:


C:\ColdFusion8\wwwroot\WEB-INF\flex

Open remoting-config.xml and change the mappings from false to true.  Open a close Flexbuilder to pickup the changes adn re-compile and try it.


 <access>
                <!-- Use the ColdFusion mappings to find CFCs, by default only CFC files under your webroot can be found. -->
                <use-mappings>true</use-mappings>
                <!-- allow "public and remote" or just "remote" methods to be invoked -->
                <method-access-level>remote</method-access-level>
            </access>
ok, I think I need to back up a bit.  I found an example that uses a httpservice call.  Which is more ideal.. using a httpService call or webservice call?  The code in the example file I found that uses the httpservice call is:

<mx:HTTPService
        id="employeesService"
        url="http://localhost:8501/FxGSE/employees.cfc"
        resultFormat="e4x"
        useProxy="false"/>

I'm trying to do this on my buddy's servers.  He has 2 servers, both of which have coldfusion 8 installed.  Do I still use localhost:8501 for the path?  Here is how I have the files located:

ColdFusion8 (directory off of root)
Flex example (directory off of root)   <--  This is where the example code is
  .flexProperties
  .actionScriptProperties
  .project
  -- .settings
  -- bin-debug
  -- CFML (in here is employees.cfc)
  -- db
  -- libs
  -- html-template
  -- src (in here is CFCRUD.mxml and EmployeesCRUD.as)
 
I've set up the database table but I don't have the path right to the employees.cfc file
Hmm like I said using RemotObject is far far better.  The over head is less which makes commincation much faster.  Webservice is XML based which is verbose.

http://localhost/flex2gateway <---- Try this if you get a white page you know Flash remoting is working.

Then setup the mapping to myMapping.crud   to c:\Flex example (directory off of root)\crud\src    ( where the .cfc is )

And then run the example.

Take a look at this Flash remoting with CF8 web cast:  https://admin.na3.acrobat.com/_a204547676/p23785014/
yea, that doesn't work.  I get a page cannot be displayed error 404
Ok, maybe we should take a step back..

1) ColdFusion 8 is installed on server
2) Flex 3 installed on my local computer
3) Downloaded example flex 3 example to local machine
4) db table created on server
5) now what?
Did you hook in CF to IIS or are you running over port :8500 try http://localhost:8500/flex2gateway
Ok, I enabled use mappings to true in E:\ColdFusion8\wwwroot\remoting-config.xml
then in coldfusion administrator I created a mapping called flex.  The directory path is E:\ColdFusion8\wwwroot

Is that correct?
I'm using flex 3, not 2

this doesn't work: http://localhost:8500/flex2gateway

I get a page cannot be displayed
this does not even work.. http://localhost:8500/
You messed something up during the install.  I suggest re-isntallign Coldfusion or your local machine.
Can you get to cfadmin?
yes, I can log into administrator.
Does RDS need to be installed?  That was not in the installation.
How do you get into cfadmin shoe me the exact url you use.
http://domain.com/CFIDE/administrator/index.cfm
Oh you don't have coldfusion installed locally?
no, as I mentioned, my buddy has cf8 installed on his server.  I'm doing this directly on the server.
Ok, I enabled use mappings to true in E:\ColdFusion8\wwwroot\remoting-config.xml
then in coldfusion administrator I created a mapping called flex.  The directory path is E:\ColdFusion8\wwwroot

Is that correct?
You need to install locally.
Doyou recommend I do this locally first?

Ok, I'm installing cf8 locally now, using the built in web server (port 8501)
It's installing now.

Now, why install it locally?  For testing purposes?
Yep for developing you need to install locally.  Well you don't "need" to but its 100* easier to work that way.  Then u can just copy it to the webserver and set the mapping up and it will work.  Initially the setup can be a bit confusion but once you understand how it works it really comes together.  Check out the webcast I posted above its a great example.
Ok, for my administrator, its now:

http://localhost:8501/CFIDE/administrator/index.cfm
Now for my coldfusion mapping, does the following look correct?

Logical Path: /flex
Directory Path: C:\ColdFusion8\wwwroot
Logical Path: /flex
Directory Path: C:\ColdFusion8\wwwroot\someplace where thecfc is

The Directory Path: can be anywhere u want  ie   c:\Flex\cfcs   Aslong as its the folder to the cfc's
ok, yes I get a white page now
Perfect.
Ok, now I need to set up my db table locally.  what do you suggest?
mySQL or SQL Express either is fine.  Both are free.  

Probably SQL is easier: http://www.microsoft.com/Sqlserver/2005/en/us/express.aspx
Actually, I'll just use an access db.  will that work?  I just then to set up a datasource in cf admin, right?
That will work just fine,

Yep
Ok, I can connect to the db.

Now, in the example app I have,  I can insrt a record into my db table.  However, i can't display the records in my table into my datagrid.
I know it works because it works on the example site.
This is my mxml file:
 
<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
// ADOBE SYSTEMS INCORPORATED
// Copyright 2007 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the 
// terms of the Adobe license agreement accompanying it.  If you have received this file from a 
// source other than Adobe, then your use, modification, or distribution of it requires the prior 
// written permission of Adobe.
////////////////////////////////////////////////////////////////////////////////
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="absolute" 
	backgroundAlpha="0" backgroundColor="#FFFFFF">
	<mx:Script>
        <![CDATA[
            include "EmployeesCRUD.as";
        ]]>
	</mx:Script>
	
	<!--  [various URLs for HTTPService below]	
	url="http://examples.adobe.com/flex3/workingwithdata/employees.php"
	url="http://www.tipsandapps.com/CRUD/employees.asp"
	url="http://localhost:8100/flex3samples-war/workingwithdata/employees.jsp"
	url="http://examples.adobe.com/flex3app/flex3samples/workingwithdata/employees.jsp"
	Local CF server:
	url="http://localhost:8501/FxGSE/employees.cfc"
	-->
	<mx:HTTPService 
        id="employeesService"
 		url="http://localhost:8501/employees.cfc"
        resultFormat="e4x"
        useProxy="false"/>
        
	<mx:ViewStack id="viewstack1" width="100%" height="100%" >
		<mx:Canvas label="Form View" width="100%" height="100%">
			<mx:Form horizontalCenter="0" verticalCenter="0" backgroundColor="#FFFFFF">
				<mx:FormItem label="Query Employees ">
					<mx:Button label="Submit" click="fill()" width="100"/>
				</mx:FormItem>
			</mx:Form>
		</mx:Canvas>
		<mx:Panel label="DataGrid View" width="100%" height="100%">
			<mx:DataGrid width="100%" height="100%" dataProvider="{listData}">
				  <mx:columns>
                     <mx:DataGridColumn dataField="firstName" headerText="First Name"/>
                	<mx:DataGridColumn dataField="lastName" headerText="Last Name"/>
                	<mx:DataGridColumn dataField="officePhone" headerText="Phone"/>
  				</mx:columns>
			</mx:DataGrid>
			<mx:Form backgroundColor="#FFFFFF">
				<mx:FormItem label="Add New Employee">
					<mx:Button label="Add..." click="{viewstack1.selectedIndex = 2}" width="100"/>
				</mx:FormItem>
			</mx:Form>			
		</mx:Panel>
		<mx:Canvas label="Add New Employee View" width="100%" height="100%">
			<mx:Form horizontalCenter="0" verticalCenter="0" backgroundColor="#FFFFFF">
				<mx:FormItem label="First Name">
					<mx:TextInput id="inputFirst"/>
				</mx:FormItem>
				<mx:FormItem label="Last  Name">
					<mx:TextInput id="inputLast"/>
				</mx:FormItem>
				<mx:FormItem label="Phone">
					<mx:TextInput id="inputPhone"/>
				</mx:FormItem>
				<mx:FormItem label="Add Employee ">
					<mx:Button label="Add" click="insertEmployee()" />
				</mx:FormItem>
			</mx:Form>
		</mx:Canvas>
	</mx:ViewStack>	
</mx:Application>
 
This is my .as file:
 
/*
////////////////////////////////////////////////////////////////////////////////
// ADOBE SYSTEMS INCORPORATED
// Copyright 2007 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the 
// terms of the Adobe license agreement accompanying it.  If you have received this file from a 
// source other than Adobe, then your use, modification, or distribution of it requires the prior 
// written permission of Adobe.
////////////////////////////////////////////////////////////////////////////////
*/
import mx.rpc.events.ResultEvent;
import mx.collections.XMLListCollection;
 
private var params:Object = new Object();
[Bindable]
private var listData:XMLListCollection;
 
public function resultHandler(event:ResultEvent):void {	
	var result:XML = XML(event.result);  
    var xmlList:XMLList = result.data.children();	
	listData = new XMLListCollection(xmlList); 
}
 
public function insertItemHandler(event:ResultEvent):void {	
	fill();
}
 
public function fill():void{
	employeesService.removeEventListener(ResultEvent.RESULT,insertItemHandler);
	employeesService.addEventListener(ResultEvent.RESULT,resultHandler);
	employeesService.method = "GET";
	params['method'] = "FindAll";
	employeesService.cancel();
	employeesService.send(params);
	viewstack1.selectedIndex=1;
}
 
public function insertEmployee():void{
	employeesService.removeEventListener(ResultEvent.RESULT,resultHandler);
	employeesService.addEventListener(ResultEvent.RESULT,insertItemHandler);
	employeesService.method = "POST";
    params = {"method": "InsertEmployee", "id": NaN, "firstName": inputFirst.text,
    			 "lastName": inputLast.text, "officePhone": inputPhone.text}; 
	employeesService.cancel();
	employeesService.send(params);
	clearInputFields();
}
 
private function clearInputFields():void{
    inputFirst.text = "";
    inputLast.text = "";
    inputPhone.text = "";
}

Open in new window

get rid of the HTTPservice stuff.
what should I use in place of it?  Should I use a webservice?  I've seen that used in other examples.
I would use remote object as I initially.
hmm, I guess I'm not understanding.  I did find this..

<mx:RemoteObject
        id="userRequest"
        destination="ColdFusion"
        source="flex.employees">

Now, employees is my cfc and it is in the same place as my mxml file.  Would that be the correct source path?  What would go in destination?
source="flex.employees"> = [flex] is the mapping name and [employees] is the cfc name.  Is that what this dot notation means?
thats fine

In the Coldfusion Admin that mapping shoudl be:


Logical Path: /flex
Directory Path: C:\MyFlexbuilderProject\src                <------------ Where the cfc is.
This is where the cfc is:

C:\ColdFusion8\wwwroot
when I try to run it, a popup comes up saying there's an error
Actually, there was an error in the code and I fixed so no popup.

Ok, I'm back to using httpService call.  Why wouldn't the remote object work?  How can I replace the httpService call with remoteObject using the above example code?
SCRAP THE HTTPSERVICE.  

Use remote objects.  

he flexcf.com demo you showed has all the code you need.
ok, I'll scrap that other example.  Ok, going with remoteObjects..

Now, in the mxml, I have:

<mx:RemoteObject id="ro" destination="ColdFusion" showBusyCursor="true" source="flex.employees">

[flex] is the name of the mapping (Logical Path)
[employees] is the name of the cfc.. this is the directory path to that cfc:

C:\Documents and Settings\My Documents\Flex Builder 3\Flex3GSEIII_a_WorkingWithData_CF\src

Does that look correct?
Looks good to me.
Now, this is the msml file:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="ro.getData()"  viewSourceURL="srcview/index.html">
      <mx:RemoteObject id="ro" destination="ColdFusion" showBusyCursor="true" source="flex.employees">
            <mx:method name="getData" result="getDataResult(event)" />
            <mx:method name="saveNewData" result="getDataResult(event)" />
            <mx:method name="saveOldData" result="getDataResult(event)" />
            <mx:method name="deleteData" result="getDataResult(event)" />
      </mx:RemoteObject>
      <mx:Script>
            <![CDATA[
                  import mx.collections.ArrayCollection;
                  import mx.rpc.events.ResultEvent;
                  
                  private var isNew:Boolean = true;
                  
                  public function getDataResult(e:ResultEvent):void{
                        dg.dataProvider = e.result as ArrayCollection;
                        makeNew();
                  }
                  private function makeNew():void{
                        aName.text = "";
                        type.text = "";
                        isNew = true;
                  }
                  private function save():void{
                        if(isNew){
                              ro.saveNewData(aName.text,type.text);
                        }else{
                              ro.saveOldData(aName.text,type.text,dg.selectedItem.id);
                        }
                  }
                  private function deleteData():void{
                        if(dg.selectedIndex > -1 )ro.deleteData(dg.selectedItem.id);
                  }
            ]]>
      </mx:Script>
      <mx:DataGrid id="dg" change="isNew = false" width="366">
      </mx:DataGrid>
      <mx:Panel width="372" height="146" layout="absolute">
            <mx:Form top="0" bottom="0" right="0" left="0">
                  <mx:FormItem label="Name">
                        <mx:TextInput id="aName" text="{dg.selectedItem.name}"/>
                  </mx:FormItem>
                  <mx:FormItem label="Type">
                        <mx:TextInput id="type" text="{dg.selectedItem.type}"/>
                  </mx:FormItem>
            </mx:Form>
      </mx:Panel>
      <mx:Button label="New" click="makeNew()"/>
      <mx:Button label="Save" click="save()" />
      <mx:Button label="Delete" click="deleteData()" />  
</mx:Application>

Open in new window

And this is the cfc:
<cfcomponent output="false">
<cfset mstest = "media">
	<cffunction name="getData" access="remote" returntype="Query">
		<cfset var local = {} />
		<cfquery name="local.q" datasource="#mstest#">
			select		id, name, type
			from		test
		</cfquery>
		<cfreturn local.q/>
	</cffunction>
	
	<cffunction name="saveNewData" access="remote" returntype="Query">
		<cfargument name="name" type="string" required="true"/>
		<cfargument name="type" type="string" required="true"/>
		
		<cfquery datasource="#mstest#">
			insert		
			into		test
						( name, type )
			values		( <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.name#"/>,
						  <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.type#"/> )
		</cfquery>
		<cfreturn getData() />
	</cffunction>
	
	<cffunction name="saveOldData" access="remote" returntype="Query">
		<cfargument name="name" type="string" required="true" />
		<cfargument name="type" type="string" required="true" />
		<cfargument name="id" type="Numeric" required="true" />
		
		<cfquery datasource="#mstest#">
			update		test		
			set			name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.name#" />,
						type = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.type#" />
			where		id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" />
		</cfquery>
		<cfreturn getData() />
	</cffunction>
	
	<cffunction name="deleteData" access="remote" returntype="Query">
		<cfargument name="id" type="string" required="true">
		
		<cfquery datasource="#mstest#">
			delete
			from		test
			where		id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" />
		</cfquery>
		<cfreturn getData() />
	</cffunction>
		
</cfcomponent>

Open in new window

The name of the CFC is:  employees.cfc  just to check.  if yes then it should work.
yes, that's the name.  The app just hangs (timer).  The datagrid does not populate data.
the table is in the db and the mdb file resides in the same place as employees.cfc
Do u have the Flash debug player installed?  Run it in debug mode and take a look atthe errors.
where do I enable that?  In flex?
I believe everything is setup according to your instructions but I get the timer on the ouput page.  any more ideas?
Do u have the Flash debug player installed?  

Run it in debug mode and take a look at the errors.
Untitled.png
I have flash player 10 installed and it can't find the debugger for it.
Thanks for that.

Ok, I find a more simple flex 3 app that uses remoteObject.

So, this is how I have workstation setup:

cfadmin mapping:
Logical Path: /flex
Directory Path: C:\Documents and Settings\My Documents\Flex Builder 3\DataBaseUsingRemoteObject

cfadmin datasource:
CF Data Source Name: media
Database File: C:\Documents and Settings\My Documents\Flex Builder 3\DataBaseUsingRemoteObject\media.mdb

project, mxml files:
C:\Documents and Settings\My Documents\Flex Builder 3\DataBaseUsingRemoteObject\

cfc file:
C:\Documents and Settings\My Documents\Flex Builder 3\DataBaseUsingRemoteObject\cfc\DataBaseCFC.cfc

You'll see the code for both the mxmml and cfc below.  When I run it, I get this error in the debugger:

[RPC Fault faultString="[MessagingError message='Destination 'ColdFusion' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to 'ColdFusion'"]
mxml:
 
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
	 creationComplete="dataBaseRequest.myDataBaseFunction();" viewSourceURL="srcview/index.html">
	
	<!--=====The Source for RemoteObject needs to be from the wwwroot Folder
								I have my WorkSpace under the wwwroot Folder
								so you have to start from after the wwwroot folder and work
								down until you hit the cfc file
		-->
	
	<mx:RemoteObject destination="ColdFusion" id="dataBaseRequest"
			 source="flex.cfc.DataBaseCFC">
		<mx:method name="myDataBaseFunction" result="onResultService(event)"
		 fault="onFaultService(event)"/>
	  </mx:RemoteObject>
	 	
	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			/**
			 * @Private
			 * Since we are returning a query from the DataBase in ColdFusion
			 * and we are using remoting then Flex will recieve the Query as 
			 * an ArrayCollection
			 */
			[Bindable]
			private var remoteCollection:ArrayCollection;
			/**
			 * @private
			 * event.result will be where the data is stored
			 */			
			private function onResultService(event:ResultEvent):void
			{
				remoteCollection=event.result as ArrayCollection;
			}
			private function onFaultService(event:FaultEvent):void
			{
				mx.controls.Alert.show(event.fault.toString());
			}
			
		]]>
	</mx:Script>
	
	<mx:DataGrid id="RemotedataGrid" dataProvider="{remoteCollection}"
		       width="500" height="500"/>
 
	
	
	
	
	
	
</mx:Application>
 
 
cfc:
 
<cfcomponent output="no">
	<cffunction name="myDataBaseFunction" access="remote" returntype="query">
			<cfquery datasource="media" name="simpleQuery" >
        		S firstName, lastName
                F employees
                
 
        	</cfquery>
	<cfreturn simpleQuery>
   
	</cffunction>
</cfcomponent>

Open in new window

When you created the Flex Project did you select Flash remoting?
Untitled.png
I don't know.  Can I go in and change a setting in the project now that is's created?  What does that error indicate?
Actually, I didn't.  I'll recreate the project now.
Re-create and move the files over.
Ok, I did that, and now I get this error in my output:

[RPC Fault faultString="Unable to invoke CFC - Could not find the ColdFusion Component or Interface flex.cfc.DataBaseCFC." faultCode="Server.Processing" faultDetail="Ensure that the name is correct and that the component or interface exists."]

I did change my mapping so now the directory path in cf admin is:

C:\Documents and Settings\My Documents\Flex Builder 3\RemoteObject\src

What else could it be.. in the mxml file, the RemoteObject is:

<mx:RemoteObject destination="ColdFusion" id="dataBaseRequest"
                   source="flex.cfc.DataBaseCFC">
            <mx:method name="myDataBaseFunction" result="onResultService(event)"
             fault="onFaultService(event)"/>
        </mx:RemoteObject>
The mapping is wrong.  Confirm in CFIDE
Got it to work!!

I change that source path in RemoteObject to:

source="DataBaseCFC"

I guess I'm not understanding why that change did it.  Could you explain?
the mapping needs to point to the path of the cfc so CF knows where to reach the cfc from Flex
I'll assume u put the cfc int he root to make it work?
no, actually, the path to the cfc is:

C:\Documents and Settings\My Documents\Flex Builder 3\RemoteObject\src\cfc\DataBaseCFC.cfc

The mapping in cf admin is:

C:\Documents and Settings\My Documents\Flex Builder 3\RemoteObject\src

How does it know to look in the cfc dir?  I don't reference it anywhere?
Whast the name of the mapping?
flex --> logical path
So your remote object looks liek this:

<mx:RemoteObject destination="ColdFusion" id="dataBaseRequest"
                   source="flex.DataBaseCFC">
Ok, I think I was looking at the wrong directory.  The cfc that it's looking at is in here:

C:\ColdFusion8\wwwroot

I renamed the cfc and it broke so that's the file.  I guess I don't understand the whole output thing and why it's looking in the localhost root for the cfc and not in the path I specifed in cf admin?

The mapping needs to match the source on the remote object I feel like I am repeating this many times.  Once the mapping matches remoting works.  That is presuming you turned on mappings in the config xml file.
I nevr made any changes to a config.xml file.  Just turned to 'true' that file you mentioned above..

remoting-config.xml:
<use-mappings>true</use-mappings>
Yep that's the one I am referring to.

After you made that change did you open and close FlexBuilder then force it to re-compile?
yes, did that.

Well, it appears the datagrid is populating results so that's great.   I'm still a little foggy on the whole mapping thing but I will learn it.

Thanks a lot for your help!
Thanks again!
Good times.  7.7 I should have got a 10 :)
I gave all high remarks.  How did you wind up with 7.7?  I'm not sure those are tallied.  I just gave you excellent on everything.
Oh ok thanks :)