Title: What's the best practice for Flash Vars? Post by: jpwrunyan on February 25, 2010, 11:13:40 Ok, so I am currently trying to clean up the spaghetti that is our current ApplicationFacade and its immediate mediators. Our application is dependent upon settings that are located in the flashVars of the encapsulating HTML object tag (we use swfobject if you're curious). From those vars we determine what database the application should then retrieve its information from (these settings are downloaded from a url in flashVars).
Currently, flash vars are grabbed inside the facade class and then a url request is launched via URLLoader then and there. When the request comes back, more fun stuff is done where the facade--which kept a global reference to the Application instance it received in the startUp() command--passes the URLoader's result to the application view component (yeah! who needs a Mediator, right?). Well, all this works, but I feel like to is definitely not correct (correct me if I am wrong). The place where I am particularly facing a moral conundrum is the flashvars itself. Here's part one of my question: I feel as though the flash vars should have its own proxy (registered in the new StartUpCommand) but flashvars comes directly from the view component via: view.root.loaderInfo.parameters. I could just pass that object in the StartUpCommand: facade.registerProxy(new FlashVarsProxy("FlashVarsProxy", body.root.loaderInfo.parameters)) //body is an instance of Application But since its bound directly to the application instance, should it be handled inside the Mediator as a sort of public var? And now for part two of my question: Once I decide what to do with the flash vars, who/what should be responsible for the URLLoader request for remote variables based on those flash vars? Again, I am leaning towards just declaring a proxy for that in the StartUpCommand and setting a search parameter based on the flash vars. Perhaps via the FlashVarsProxy I register on the line just before it (or not)? var systemConfigProxy = SystemConfigProxy(facade.registerProxy(new SystemConfigProxy())); Any thoughts much appreciated, no matter how detailed or specific! Title: Re: What's the best practice for Flash Vars? Post by: jpwrunyan on February 26, 2010, 12:03:44 Ok, well, here's my proposed solution to the above (irrelevant code elided):
<?xml version="1.0" encoding="utf-8"?> public class ApplicationFacade extends Facade { public class AppStartUpCommand extends SimpleCommand { public class FlashVarsProxy extends Proxy { systemURL is just a url to download from (I made it a package variable) public class SystemConfigProxy extends Proxy { Well, that's about the best I can come up with (until Monday anyway).Title: Re: What's the best practice for Flash Vars? Post by: puremvc on February 26, 2010, 10:56:29 Here's a link to a description of the way I handle it. Regarding parameters passed to the application, I don't worry about where the data is coming from, it's data. A ParameterProxy is easily done:
http://forums.puremvc.org/index.php?topic=622.msg2781#msg2781 -=Cliff> Title: Re: What's the best practice for Flash Vars? Post by: jpwrunyan on February 28, 2010, 06:42:03 awesome.
thanks for the link. that's actually how I ended up doing it after I posted the code above. and as always, thanks for the feedback! Since I'm re-writing our framework level classes, everything I rewrite gets challenged (as it should) so it's nice to have an expert opinion to fall back on when justifying my changes! The problem I have with my original source above is that the flash vars proxy assumes it has access to the Application singleton. That works inside of Flex, but it would not work for any other framework. Therefore it is better to grab the parameters from the actual instance as you did and pass them to the FlashVarsProxy constructor. The fact that that instance is the Application view component is irrelevant. Anyway, just thinking out loud here... |