Problema
Configurar sua conexão com Flex & ColdFusion.
Solução
Me perguntaram algumas vezes como conectar Flash & ColdFusion para acesso remoto.
Detailed explanation
Configurar Flash Remoting com ActionScript 3.0 eColdFusion é fácil.
Crie um fla, chame-o connection e cria um componente ColdFusion e chame-o getTest.cfc.
No getTest.cfc us o código abaixo
<cfcomponent displayName="getTest"> <cffunction name="getTestConn" access="remote" returnType="string" output="true"> <cfreturn "connection to localhost was made!"> </cffunction> </cfcomponent>
Este CFC inicia a conexão, e retorna uma string.
Coloque este CFC no seu webroot.
No painel actions do seu fla, entre o seguinte código:
import flash.net.NetConnection; import flash.net.Responder; var gateway:NetConnection = new NetConnection(); var responder:Responder=new Responder(onResult,onFault); function onResult(responds:Object):void { trace("cfc result "+" --"+" "+responds.toString()); //message.text= "cfc result "+"-- "+" "+responds.toString(); } function onFault(responds:Object):void { //loop over the fault structure for (var i:String in responds) { trace( i + ":" + responds[i] ); } } // name the default gateway on this machine. if you are using the default ColdFusion server use port 8500 gateway.connect("http://localhost/flashservices/gateway/"); // name of the cfc and the function gateway.call("getTest.getTestConn", responder);
No actions nós estamos importando as classes necessárias, configurando variáveis. E, criamos as funções onResult e onFault. Então, definimos o gateway, que está em http://localhost/flashservices/gateway/ ou http://localhost:8500/flashservices/gateway/ para o servidor ColdFusion default.
Finalmente chamamos a função que queremos para retornar no CFC. No exemplo acima eu tenho o campo de texto com a mensagem comentado, mas no download ele está funcionando para que voce possa ver o exemplo rodando.
Sinta-se à vontade em baixar o zip, e se tiver alguma dúvida, deixe um comentário ou contate-me 🙂