Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
XMLProxy loading XML (finished) -> ImageLoadCommand -> ImageProxy (for each Image) -> ImageVo (SaveData) -> ?Is that logic right? And how can I send a Notification to a ImageMediator which was created after the XML had been loaded? How should I mange the Names of ImageProxys and ImageMediators
override public function setData(data:Object):void { super.setData(data); sendNotification(GlobalConstants.NEW_DATA, data, proxyName);}
Anyway, your mediators might all respond to the NEW_DATA notification, then check if the type (ie proxyName) matches a proxy name they care about, and then finally process the data appropriately.
public class StartupCommand extends SimpleCommand implements ICommand{ private var _monitor : LoadupMonitorProxy; override public function execute(note : INotification):void{ var stage : Stage = note.getBody() as Stage; facade.registerMediator(new StageMediator(stage)); facade.registerProxy(new LoadupMonitorProxy()); _monitor = facade.retrieveProxy(LoadupMonitorProxy.NAME) as LoadupMonitorProxy; var styleSheetProxy : ILoadupProxy = new StyleSheetProxy(); var siteDataProxy : ILoadupProxy = new SiteDataProxy(); facade.registerProxy(styleSheetProxy); facade.registerProxy(siteDataProxy); var rStyleSheetProxy : LoadupResourceProxy = makeAndRegisterStartupResource(StyleSheetProxy.SRNAME, styleSheetProxy); var rSiteDataProxy : LoadupResourceProxy = makeAndRegisterStartupResource(SiteDataProxy.SRNAME, siteDataProxy); rSiteDataProxy.requires = [rStyleSheetProxy]; _monitor.loadResources(); } private function makeAndRegisterStartupResource(proxyName : String, appresourceProxy : ILoadupProxy) : LoadupResourceProxy { var r : LoadupResourceProxy = new LoadupResourceProxy(proxyName, appresourceProxy); facade.registerProxy(r); _monitor.addResource(r); return r; } }
public class StageMediator extends Mediator implements IMediator { public static const NAME : String = "stageMediator"; public function StageMediator(viewComponent : Object = null) { super(NAME, viewComponent); } override public function listNotificationInterests() : Array { return[LoadupMonitorProxy.LOADING_PROGRESS, LoadupMonitorProxy.LOAD_RESOURCE_TIMED_OUT, LoadupMonitorProxy.LOADING_FINISHED_INCOMPLETE, LoadupMonitorProxy.CALL_OUT_OF_SYNC_IGNORED, LoadupMonitorProxy.LOADING_COMPLETE, ApplicationFacade.STYLE_SHEET_FAILED, ApplicationFacade.STYLE_SHEET_LOADED, ApplicationFacade.STYLE_SHEET_LOADING, ApplicationFacade.SITE_DATA_FAILED, ApplicationFacade.SITE_DATA_LOADED, ApplicationFacade.SITE_DATA_LOADING]; } override public function handleNotification(note : INotification):void{ switch(note.getName()){ case ApplicationFacade.STYLE_SHEET_LOADING: trace("Loading StyleSheet..."); break; case ApplicationFacade.STYLE_SHEET_LOADED: trace("StyleSheetLoaded"); break; case ApplicationFacade.SITE_DATA_LOADING: trace("Loading Site Date..."); break; case ApplicationFacade.SITE_DATA_LOADED: trace("Site Data Loaded"); break; case LoadupMonitorProxy.CALL_OUT_OF_SYNC_IGNORED: trace("Abnormal State, Abort"); break; case LoadupMonitorProxy.LOADING_PROGRESS: var percent : Number = note.getBody() as Number; trace("Loading Progress: " + percent + "%"); break; case LoadupMonitorProxy.LOADING_COMPLETE: trace(">>Loading Complete"); initializeView(); break; case LoadupMonitorProxy.LOADING_FINISHED_INCOMPLETE: trace("Loading Finished Incomplete"); break; } } private function initializeView() : void { sendNotification(ApplicationFacade.PREPARE_GALLERY); } public function get stage():Stage{ return viewComponent as Stage; }
override public function execute(note : INotification) : void { var stageMediator : StageMediator = facade.retrieveMediator(StageMediator.NAME) as StageMediator; var siteDataProxy : SiteDataProxy = facade.retrieveProxy(SiteDataProxy.NAME) as SiteDataProxy; var gallery : Gallery = new Gallery(); for (var i : int = 0; i < siteDataProxy.images.length; i++) { gallery.addImage(new Image(String(i), siteDataProxy.urls[i])); } stageMediator.stage.addChild(gallery); facade.registerMediator(new GalleryMediator(gallery)); }
It have not to listen to the LOADING_COMPLETE but the LoadupUtility dispatchs the Notification twice. First, when the data is loaded and second, when the images are loaded.