When using RemoteObject to communicate with a server in an application served by the FDS, the RemoteObject is inherently looking to communicate back to the FDS server. If you followed the setup directions in the appendix, "Setup Instructions," you have installed the FDS server and the ColdFusion server to run as two separate servers. This setup can greatly simplify configuration issues with the servers, but it unfortunately requires a bit of extra work to enable the application to retrieve data from the ColdFusion server instead of the FDS server. Normally, Flex applications served by the FDS server will use channels as defined in the server's services-config.xml file. This file lacks the necessary information to connect to your ColdFusion server, so you can dynamically add a custom channel to your <mx:RemoteObject> instance instead. Here, you can see a sample of the ActionScript 3.0 code to create a custom channel: // Create a ChannelSet. private var cs:ChannelSet = new ChannelSet(); // Create a Channel. var customChannel:Channel = new AMFChannel("newAMF", URLtoGateway); // Add the Channel to the ChannelSet. cs.addChannel(customChannel); // Assign the ChannelSet to a RemoteObject instance. svc.channelSet = cs; ... <mx:RemoteObject ... /> To create a new channel, you first need to create an instance of the mx.messaging.ChannelSet class. A ChannelSet is a group of channels that are used to tell RemoteObject calls how to find their destination. Each ChannelSet can contain one or more channels (instances of classes in the mx.messaging.Channel package). In the example code, a new channel called customChannel is defined as a new AMFChannel; that is, a channel that would communicate over the Action Message Format (AMF) protocol. The constructor takes two arguments: a name for the channel and a URL to the Remoting Gateway. If you want to create a channel to talk to your local ColdFusion server, you can replace the URLtoGateway reference with http://localhost:8300/flex2gateway/. The customChannel is then added to the ChannelSet by using the ChannelSet's addChannel() method. Finally, the <mx:RemoteObject> tag has its channelSet specified with the newly created ChannelSet. In this next exercise, you will create a custom channel to allow the EComm application to continue to leverage the ColdFusion server, even though it is running through your FDS server.
|