Quick Flash Remoting Fix (and simple Flex Sample) for Tartan Sample Application

The HelloWorld sample application that ships with Tartan has a small bug that might leave you scratching your head when you try to access them via Flash Remoting. It's a minor path issue which you can fix in two ways.

Taking the helloWorld example, either:
  1. Copy the config folder in tartanSamples\helloWorld to tartanSamples\helloWorld\remote, or
  2. Alter line 28 of tartanSamples\Application.cfc to read configFileLocation="#ExpandPath('../config/service.xml')#" (note the added "../" at the start of the path.)
Also, I don't believe that there are any Flash or Flex samples for using Tartan with Flash Remoting (it's actually dead simple) so here's the simplest possible Flex example:

MXML:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*" load="initForm()">
  3. <mx:Button label="Get greeting" click="getGreeting()" />
  4. <mx:Label id="status" />
  5. <mx:Script>
  6. <![CDATA[
  7. import mx.remoting.Service;
  8. import mx.remoting.PendingCall;
  9. import mx.rpc.RelayResponder;
  10. import mx.rpc.ResultEvent;
  11. import mx.rpc.FaultEvent;
  12.  
  13. import mx.remoting.debug.NetDebug;
  14.  
  15. var helloWorldService:Service;
  16.  
  17. function initForm()
  18. {
  19. NetDebug.initialize();
  20. var gatewayURL:String = "http://localhost:8500/flashservices/gateway";
  21. helloWorldService = new Service ( gatewayURL, null, "tartanSamples.helloWorld.remote.HelloWorldFlashService", null, null );
  22. status.text="Initialized.";
  23. }
  24.  
  25. function getGreeting()
  26. {
  27. var pendingCall = helloWorldService.getGreeting ( "English" );
  28. pendingCall.responder = new RelayResponder(this, "onResult", "onStatus");
  29. }
  30. function onResult (resultObj:ResultEvent)
  31. {
  32. status.text = resultObj.result;
  33. }
  34. function onStatus ( faultObj:FaultEvent )
  35. {
  36. status.text = "There was an error getting the greeting.";
  37. }
  38. ]]>
  39. </mx:Script>
  40. </mx:Application>

I look forward to working with Tartan on our current Flex/CF project. We will be using it in conjunction with Model-Glue on the server side and, of course, Arp on the client :)

Comments