PureMVC XML DataProxy Class Template


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2. * Base PureMVC Project
  3. */
  4. package model
  5. {
  6. import flash.events.Event;
  7. import flash.net.URLLoader;
  8. import flash.net.URLRequest;
  9.  
  10. import org.puremvc.as3.interfaces.IProxy;
  11. import org.puremvc.as3.patterns.proxy.Proxy;
  12.  
  13. import ApplicationFacade;
  14.  
  15. public class DataProxy extends Proxy implements IProxy
  16. {
  17. public static const NAME:String = "DataProxy";
  18.  
  19. public function DataProxy()
  20. {
  21. trace ("DataProxy instantiated");
  22. /**
  23. * Here, we initialize DataProxy with a var named "data"
  24. * of type Object(), a built-in property of the Proxy class.
  25. * This var will be used for storing data retrieved from the xml document.
  26. */
  27. super( NAME, new Object() );
  28.  
  29. var loader:URLLoader = new URLLoader();
  30. loader.addEventListener( Event.COMPLETE, onDataLoaded );
  31. loader.load( new URLRequest( "data.xml" ) );
  32.  
  33. }
  34.  
  35. private function onDataLoaded( evt:Event ):void
  36. {
  37. trace ("DataProxy.onDataLoaded()");
  38.  
  39. var xml:XML = new XML( evt.target.data );
  40. xml.ignoreWhitespace = true;
  41.  
  42.  
  43. /**
  44. * When DataProxy is done loading and parsing data, it
  45. * sends an INITIALIZE_SITE notification back to the framework.
  46. */
  47. sendNotification( ApplicationFacade.INITIALIZE_SITE );
  48. }
  49. }
  50. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.