ParamsProxy for PureMVC


/ Published in: ActionScript 3
Save to your folder(s)

Nabbed this from the PureMVC forums.


Copy this code and paste it in your HTML
  1. package com.me.myapp.model
  2. {
  3.  
  4. import org.puremvc.as3.multicore.patterns.proxy.Proxy;
  5.  
  6. /**
  7. * Parameters Proxy.
  8. * <P>
  9. * Maintains the parameters object that corresponds to
  10. * the <code>FlashVars</code> passed into the Application
  11. * via the OBJECT/EMBED tag in the HTML wrapper.</P>
  12. */
  13. public class ParamsProxy extends Proxy
  14. {
  15. public static const NAME:String = "ParamsProxy";
  16.  
  17. /**
  18. * Constructor.
  19. */
  20. public function ParamsProxy( params:Object )
  21. {
  22. super ( NAME, params );
  23. }
  24.  
  25.  
  26. /**
  27. * Get the vendorName parameter.
  28. */
  29. public function get vendorName():String
  30. {
  31. return params.vendorName as String;
  32. }
  33.  
  34. /**
  35. * Get the appName parameter.
  36. */
  37. public function get appName():String
  38. {
  39. return params.appName as String;
  40. }
  41.  
  42. /**
  43. * Get the appVersion parameter.
  44. */
  45. public function get appVersion():String
  46. {
  47. return params.appVersion as String;
  48. }
  49.  
  50. /**
  51.   * The parameters supplied to the main application.
  52.   * <P>
  53.   * There are two sources of parameters: the query
  54.   * string of the Application's URL, and the value
  55.   * of the FlashVars HTML parameter.</P>
  56.   */
  57. public function get params():Object
  58. {
  59. return data as Object;
  60. }
  61.  
  62. }
  63. }
  64.  
  65. ///"In the StartupCommand, since I have a reference to the Application, and parameters is a direct public property, I just register a ParamsProxy at that time:"
  66.  
  67. package com.me.myapp
  68. {
  69. import com.me.myapp.MyApp;
  70. import com.me.myapp.model.ParamsProxy;
  71. import com.me.myapp.view.ApplicationMediator;
  72.  
  73. import org.puremvc.as3.multicore.interfaces.INotification;
  74. import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
  75.  
  76. /**
  77. * Startup.
  78. *
  79. * Creates and registers the initial Proxies and Mediators
  80. *
  81. * @param note the STARTUP notification
  82. */
  83. public class StartupCommand extends SimpleCommand
  84. {
  85. override public function execute(note:INotification):void
  86. {
  87. // Retrieve the Application reference and register the ApplicationMediator
  88. var myApp:MyApp = note.getBody() as MyApp;
  89.  
  90. // Register the ParamsProxy
  91. // It maintains the FlashVars and initial QueryString parameters
  92. facade.registerProxy( new ParamsProxy( myApp.parent.loaderInfo.parameters ) );
  93.  
  94. // Register the ApplicationMediator
  95. facade.registerMediator( new ApplicationMediator( myApp ) );
  96.  
  97. }
  98.  
  99. }
  100. }

URL: http://forums.puremvc.org/index.php?topic=622.0

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.