Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
public function WorldProxy(){ super( NAME, null );}
facade.registerProxy( new QuestionsProxy() );
public function QuestionMediator(viewComponent:Object) { // pass the viewComponent to the superclass where // it will be stored in the inherited viewComponent property super(NAME, viewComponent); // Proxy _questionProxy = facade.retrieveProxy( QuestionsProxy.NAME ) as QuestionsProxy; _questionProxy.getQuestions( null ); // CANT access getQuestions object reference is null why>????? trace(_questionProxy); // Returns NULL}
/*Proxy - PureMVC*/package com.jer.voting.model { import org.puremvc.as3.interfaces.IProxy; import org.puremvc.as3.patterns.proxy.Proxy; import lib.jer.as3.net.RemoteObject; import lib.jer.as3.events.RemoteObjectEvent; import com.jer.voting.ApplicationFacade; /** * A proxy */ public class QuestionsProxy extends Proxy implements IProxy { public static const NAME:String = "QuestionsProxy"; private var connection:RemoteObject; private var gateway:String = ApplicationFacade.GATEWAY; public function QuestionsProxy(data:Object = null) { super(NAME, data); init(); } private function init():void { connection = new RemoteObject(gateway); connection.addEventListener(RemoteObjectEvent.RESULT, onRemoteResult); connection.addEventListener(RemoteObjectEvent.FAULT, onRemoteFault); } private function onRemoteResult(event:RemoteObjectEvent):void { sendNotification(ApplicationFacade.REMOTE_RESULT, event.data); } private function onRemoteFault(event:RemoteObjectEvent):void { trace("FAULT : " + event); } public function getQuestions(s:Object):void { trace( "Question" ); if (connection) { trace("SENDING : " + s); connection.method = "getPoll"; connection.send(); } } }}
// ApplicationStartup command (partial) public class ApplicationStartup extends SimpleCommand implements ICommand { // inherit constructor from SimpleCommand override public function execute (note:INotification):void { // get a reference to the main application object through the notification body var application:Object = note.getBody(); // set up the main mediator that will handle all our sub views // we have to do this before we initialize the model because the mediator listens to model notifications facade.registerMediator (new ApplicationMediator (application.stage)); // set up all the different data sources that we'll be using facade.sendNotification (ApplicationFacade.INIT_MODEL); } }
// Application Mediator (partial code)private var pConfigData:PConfigData; public function ApplicationMediator(viewComponent:DisplayObject) { super (NAME, viewComponent); } override public function listNotificationInterests():Array { return [ ApplicationFacade.CONFIG_DATA_LOADED ]; } override public function handleNotification (note:INotification):void { switch (note.getName()) { case ApplicationFacade.CONFIG_DATA_LOADED: pConfigData = facade.retrieveProxy(PConfigData.NAME) as PConfigData; trace(pConfigData); break; } }
// PConfigData proxy (partial code) public class PConfigData extends Proxy implements IProxy { public static const NAME:String = 'PConfigData'; private var initData:Object = { language: 'en' } public function PConfigData() { super(NAME, initData); sendNotification(ApplicationFacade.CONFIG_DATA_LOADED); } // getters and setters to access the data public function get language():String { return data.language; } public function set language(lang:String):void { // read-only, but data-bindable } }
we have to do this before we initialize the model because the mediator listens to model notifications
override public function execute (note:INotification):void { // get a reference to the main application object through the notification body var application:Object = note.getBody(); // set up all the different data sources that we'll be using facade.sendNotification (ApplicationFacade.INIT_MODEL); // set up the main mediator that will handle all our sub views facade.registerMediator (new ApplicationMediator (application.stage)); }
override public function execute (note:INotification):void { facade.registerProxy(new PConfigData()); // configuration data (language etc) }
facade.sendNotification(ApplicationFacade.CONFIG_DATA_LOADED);
override public function onRegister():void { pConfigData = facade.retrieveProxy(PConfigData.NAME) as PConfigData; pConfigData.populate(); } override public function listNotificationInterests():Array { return [ ApplicationFacade.CONFIG_DATA_LOADED ]; } override public function handleNotification (note:INotification):void { switch (note.getName()) { case ApplicationFacade.CONFIG_DATA_LOADED: trace("Config language: " + pConfigData.language); break; } }
I guess I'm a little concerned because the Mediator is calling a method directly on the Proxy. Is this allowed / correct? Or does that still mean they are too tightly coupled?