Posted By

jonniespratley on 10/27/08


Tagged

textmate Flex as3 mxml cairngorm


Versions (?)

Cairngorm Command


 / Published in: Other
 

  1. /** *******************************************************************
  2. * MySnippets
  3. * Free for use
  4. *
  5. * @author Jonnie Spratley
  6. * @contact [email protected]
  7. ******************************************************************* */
  8. package
  9. {
  10. import com.adobe.cairngorm.commands.ICommand;
  11. import com.adobe.cairngorm.control.CairngormEvent;
  12.  
  13. import mx.collections.ArrayCollection;
  14. import mx.controls.Alert;
  15. import mx.rpc.IResponder;
  16. import mx.rpc.events.FaultEvent;
  17. import mx.rpc.events.ResultEvent;
  18. import mx.utils.ArrayUtil;
  19.  
  20. /**
  21. * For every feature or use case in your application, a corresponding custom command
  22. * and event must be created. Each command contains an execute() method that is run
  23. * by the framework when the user action has been executed.
  24. * These classes are occasionally referred to as worker classes because they carry
  25. * out the work for an application.
  26. *
  27. */
  28. public class GetCommand implements ICommand, IResponder
  29. {
  30. private var model:ModelLocator = ModelLocator.getInstance();
  31.  
  32. public function execute( event:CairngormEvent ) : void
  33. {
  34. var evt:SnippetGetEvent = event as SnippetGetEvent;
  35. var delegate:Delegate = new Delegate( this );
  36. delegate.getData();
  37. }
  38.  
  39. public function result( data:Object ) : void
  40. {
  41. var result:ResultEvent = data as ResultEvent;
  42.  
  43. model.collection = new ArrayCollection( ArrayUtil.toArray( data.result ) );
  44.  
  45. }
  46.  
  47. public function fault( fault:Object ):void
  48. {
  49. var faultEvt:FaultEvent = fault as FaultEvent;
  50.  
  51. Alert.show(faultEvt.fault.toString(), "Service Error");
  52.  
  53. trace(faultEvt.fault.faultString);
  54. }
  55.  
  56. private function initVO( resultArray:Array ):ArrayCollection
  57. {
  58. var tempArray:ArrayCollection = new ArrayCollection();
  59.  
  60. for ( var s:String in resultArray )
  61. {
  62. tempArray.addItem( new VO( resultArray[s] ) );
  63. }
  64. return tempArray;
  65. }
  66.  
  67. }
  68. }

Report this snippet  

You need to login to post a comment.