Avatar of Mike Waller
Mike Waller
Flag 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.
Web ServersApache FlexWeb Applications

Avatar of undefined
Last Comment
Jones911

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jones911

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lexxwern

Try this: http://www.adobe.com/devnet/flex/flex_cf.html
Videos, tutorials and code examples.. :)
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>
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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Mike Waller

ASKER
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?
Mike Waller

ASKER
I guess what I need is to create a webservice in flex that points to my cfc files.
Jones911

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>
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Waller

ASKER
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
Jones911

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/
Mike Waller

ASKER
yea, that doesn't work.  I get a page cannot be displayed error 404
Your help has saved me hundreds of hours of internet surfing.
fblack61
Mike Waller

ASKER
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?
Jones911

Did you hook in CF to IIS or are you running over port :8500 try http://localhost:8500/flex2gateway
Mike Waller

ASKER
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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Waller

ASKER
I'm using flex 3, not 2

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

I get a page cannot be displayed
Mike Waller

ASKER
this does not even work.. http://localhost:8500/
Jones911

You messed something up during the install.  I suggest re-isntallign Coldfusion or your local machine.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Jones911

Can you get to cfadmin?
Mike Waller

ASKER
yes, I can log into administrator.
Mike Waller

ASKER
Does RDS need to be installed?  That was not in the installation.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jones911

How do you get into cfadmin shoe me the exact url you use.
Mike Waller

ASKER
http://domain.com/CFIDE/administrator/index.cfm
Jones911

Oh you don't have coldfusion installed locally?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Mike Waller

ASKER
no, as I mentioned, my buddy has cf8 installed on his server.  I'm doing this directly on the server.
Mike Waller

ASKER
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?
Jones911

You need to install locally.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Waller

ASKER
Doyou recommend I do this locally first?

Ok, I'm installing cf8 locally now, using the built in web server (port 8501)
Mike Waller

ASKER
It's installing now.

Now, why install it locally?  For testing purposes?
Jones911

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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Mike Waller

ASKER
Ok, for my administrator, its now:

http://localhost:8501/CFIDE/administrator/index.cfm
Mike Waller

ASKER
Now for my coldfusion mapping, does the following look correct?

Logical Path: /flex
Directory Path: C:\ColdFusion8\wwwroot
Jones911

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jones911

Mike Waller

ASKER
ok, yes I get a white page now
Jones911

Perfect.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mike Waller

ASKER
Ok, now I need to set up my db table locally.  what do you suggest?
Jones911

mySQL or SQL Express either is fine.  Both are free.  

Probably SQL is easier: http://www.microsoft.com/Sqlserver/2005/en/us/express.aspx
Mike Waller

ASKER
Actually, I'll just use an access db.  will that work?  I just then to set up a datasource in cf admin, right?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jones911

That will work just fine,

Yep
Mike Waller

ASKER
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.
Mike Waller

ASKER
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

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Jones911

get rid of the HTTPservice stuff.
Mike Waller

ASKER
what should I use in place of it?  Should I use a webservice?  I've seen that used in other examples.
Jones911

I would use remote object as I initially.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Waller

ASKER
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?
Mike Waller

ASKER
source="flex.employees"> = [flex] is the mapping name and [employees] is the cfc name.  Is that what this dot notation means?
Jones911

thats fine

In the Coldfusion Admin that mapping shoudl be:


Logical Path: /flex
Directory Path: C:\MyFlexbuilderProject\src                <------------ Where the cfc is.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Mike Waller

ASKER
This is where the cfc is:

C:\ColdFusion8\wwwroot
Mike Waller

ASKER
when I try to run it, a popup comes up saying there's an error
Mike Waller

ASKER
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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jones911

SCRAP THE HTTPSERVICE.  

Use remote objects.  

he flexcf.com demo you showed has all the code you need.
Mike Waller

ASKER
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?
Jones911

Looks good to me.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Mike Waller

ASKER
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

Mike Waller

ASKER
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

Jones911

The name of the CFC is:  employees.cfc  just to check.  if yes then it should work.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Waller

ASKER
yes, that's the name.  The app just hangs (timer).  The datagrid does not populate data.
Mike Waller

ASKER
the table is in the db and the mdb file resides in the same place as employees.cfc
Jones911

Do u have the Flash debug player installed?  Run it in debug mode and take a look atthe errors.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Mike Waller

ASKER
where do I enable that?  In flex?
Mike Waller

ASKER
I believe everything is setup according to your instructions but I get the timer on the ouput page.  any more ideas?
Jones911

Do u have the Flash debug player installed?  

Run it in debug mode and take a look at the errors.
Untitled.png
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Waller

ASKER
I have flash player 10 installed and it can't find the debugger for it.
Jones911

Mike Waller

ASKER
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

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Jones911

When you created the Flex Project did you select Flash remoting?
Untitled.png
Mike Waller

ASKER
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?
Mike Waller

ASKER
Actually, I didn't.  I'll recreate the project now.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jones911

Re-create and move the files over.
Mike Waller

ASKER
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>
Jones911

The mapping is wrong.  Confirm in CFIDE
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mike Waller

ASKER
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?
Jones911

the mapping needs to point to the path of the cfc so CF knows where to reach the cfc from Flex
Jones911

I'll assume u put the cfc int he root to make it work?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Waller

ASKER
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?
Jones911

Whast the name of the mapping?
Mike Waller

ASKER
flex --> logical path
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Jones911

So your remote object looks liek this:

<mx:RemoteObject destination="ColdFusion" id="dataBaseRequest"
                   source="flex.DataBaseCFC">
Mike Waller

ASKER
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?

Jones911

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Waller

ASKER
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>
Jones911

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?
Mike Waller

ASKER
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!
Your help has saved me hundreds of hours of internet surfing.
fblack61
Mike Waller

ASKER
Thanks again!
Jones911

Good times.  7.7 I should have got a 10 :)
Mike Waller

ASKER
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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jones911

Oh ok thanks :)