Ok, the code below calls a cfc that returns a query companies and 
other company related information.

1) In the mx:Application tag I call a function initApp() which in 
turn calls my remote object myService.getActive()
 a) myService is the id of my remoteobject and getActive is the name 
of the method which is also the function inside of my CFC  on my 
website at /Cleantech/admin_AllCompanies.cfc

2) I am handling the result (whatever is returned from my cfc inside 
of the function resultHandler()
 a) I am simply setting the result to an arraycollection that I've 
made bindable called activeMembers

3) I've made activeMembers the dataProvider for my datagrid: 
dataProvider="{activeMembers}"
 a) Note the dataField properties match my column names from my CFC 
query (and yes, capitalization counts here you must match the field 
name)

4) I've also added a click handler for the datagrid that calls 
function clickHandler()


5) Inside click handler I evaluate the value of companyID in the row 
that was clicked and pass it on to a URLRequest which opens a new 
browser window.

_____________________________________________________________

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
backgroundColor="#FFFFFF" height="415" width="820" layout="absolute" 
creationComplete="initApp();" backgroundGradientColors="[#ffffff, 
#ffffff]">

<mx:Script>
<![CDATA[
 import mx.controls.Text;
 import mx.collections.ArrayCollection;
 import mx.utils.ObjectUtil;
 import mx.rpc.events.*;
 import mx.controls.Alert;
 import flash.net.*;
         
 [Bindable]
 public var activeMembers:ArrayCollection;

public function initApp():void {
 myService.getActive();
}
                
public function clickHandler():void
{
 var myvalueName:int = myGrid.selectedItem.companyID;
 var sendtoWebsite:URLRequest = new URLRequest
("http://cleantech.com/index.cfm?pageSRC=CompanyMain&companyID="; + 
myvalueName);
 navigateToURL(sendtoWebsite, "_blank");
 myGrid.selectedIndex = -1;
}
                
private function resultHandler(event:ResultEvent):void { 
 activeMembers = event.result as ArrayCollection;
}
         
]]>
</mx:Script>

<mx:RemoteObject id="myService" destination="ColdFusion" 
source="Cleantech.admin_AllCompanies" showBusyCursor="true">
 <mx:method name="getActive" result="resultHandler(event)" 
fault="Alert.show(event.fault.message)"/>
</mx:RemoteObject>
   
<mx:DataGrid name="myActiveMembers" id="myGrid" width="820" 
height="390" x="0" y="0" dataProvider="{activeMembers}" 
click="clickHandler()">
 <mx:columns>
 <mx:DataGridColumn headerText="ID" dataField="companyID" 
visible="false"/>
 <mx:DataGridColumn headerText="Company" dataField="vcompanyName" 
width="160"/>
 <mx:DataGridColumn headerText="Address" 
dataField="cvcompanyAddress1" width="92"/>
 <mx:DataGridColumn headerText="City" dataField="vcompanyCity" 
width="92"/>
 <mx:DataGridColumn headerText="State" dataField="vstateAB" 
width="40"/>
 <mx:DataGridColumn headerText="Zip" dataField="vcompanyZip" 
width="85"/>
 <mx:DataGridColumn headerText="Country" dataField="vcountryName" 
width="119"/>
 <mx:DataGridColumn headerText="Industry" dataField="industryName" 
width="92"/>
 <mx:DataGridColumn headerText="Reg" dataField="companysummaryCDate" 
width="80"/>
 <mx:DataGridColumn headerText="Last Sum" 
dataField="contactcompanyReg" width="80"/>
 </mx:columns>
</mx:DataGrid>
   
<mx:Button name="refreshApp" label="Refresh Active" click="initApp
()" height="20" width="110" x="710" y="391"/>

</mx:Application>

--- In flexcoders@yahoogroups.com, "Stephen Adams" 
<[EMAIL PROTECTED]> wrote:
>
> Hi,
> 
> I'm trying to get my head around using Flex with ColdFusion, but 
I'm really
> getting stuck with how Flex works with CF.
> 
> I'm trying to create a application which has several forms in 
which the user
> enters, save and update user details, simple stuff really. I can 
create the
> CF code (using DAO's, gateways and Beans. But linking the methods 
in my CF
> to Flex is melting my brain. Every example I've seen says it easy, 
and then
> uses tons of ActionScript, which I get lost in.
> 
> SO what's the basic steps in linking CF and Flex, are they:
> 
> 
>    1. Create your CF code (DAO's, Bean's and Gateways)
>    2. Create your flex layout
>    3. Call the CF Gateway using <mx:RemoteObject>
>    4. Then link the results of the methods to the layout (this is 
the bit
>    I'm lost at, passing data back and forth to CF methods)
> 
> Any help will be great and stop me running down the road screaming.
> 
> Thanks
> 
> Stephen
>


Reply via email to