View Single Post
mindtwitch's Avatar mindtwitch mindtwitch is offline 2008-04-22 #210 Old  
Sorry if this questions has already been asked and answered I've gone through the thread and didn't see anything related.

I'm using the original MVC sample files and have modified the AbstractView and AbstractController files to use accessors instead of straight methods (ie: getSomething()). Examples are below of changed files.

What I am having trouble with is I'm getting one Error on compile that I can't figure out. On the line in AbstractView controller.view = this in the set controller accessor, I am getting an error saying view is not a property. I was wondering if this is because of the changes I made to the IController and IView interfaces which are now empty since I don't use any of those methods now.

Any insight or help on this matter would be greatly appreciated.

Also, probably obvious but I am working in AS2. - Thanks - mt

Here are the changes I've made.

AbstractController.as
ActionScript Code:
  1. import patterns.mvc.*;
  2. import patterns.observer.*;
  3.  
  4. class patterns.mvc.AbstractController implements IController
  5. {
  6.     private var _model:Observable;
  7.     private var _view:IView;
  8.    
  9.    
  10.     public function AbstractController(m:Observable) {
  11.         // Set the model.
  12.         trace("AbstractController");
  13.         model = m;
  14.     }
  15.    
  16.    
  17.     //////////////////////////////
  18.     // ACCESSORS
  19.     //////////////////////////////
  20.     public function set model( m:Observable ):Void
  21.     {
  22.         _model = m;
  23.     }
  24.    
  25.     public function get model():Observable
  26.     {
  27.         return _model;
  28.     }
  29.    
  30.     public function set view( v:IView ):Void
  31.     {
  32.         _view = v;
  33.     }
  34.    
  35.     public function get view():IView
  36.     {
  37.         return _view;
  38.     }
  39.    
  40.    
  41.    
  42. }

AbstractView.as
ActionScript Code:
  1. import utils.error.AbstractError;
  2. import patterns.mvc.*;
  3. import patterns.observer.*;
  4.  
  5. class patterns.mvc.AbstractView implements IObserver, IView
  6. {
  7.    
  8.     private var _model:Observable;
  9.     private var _controller:IController;
  10.    
  11.    
  12.     public function AbstractView( m:Observable, c:IController )
  13.     {
  14.         model = m;
  15.        
  16.         if(c !== undefined)
  17.         {
  18.             controller = c;
  19.         }
  20.     }
  21.    
  22.     /**
  23.      * A do-nothing implementation of the Observer interface's
  24.      * update() method. Subclasses of AbstractView will provide
  25.      * a concrete implementation for this method.
  26.      */
  27.     public function update(o:Observable, infoObj:Object):Void
  28.     {
  29.         throw new AbstractError("update");
  30.     }
  31.    
  32.    
  33.     ///////////////////////////////////////////////
  34.     // ACCESSORS
  35.     ///////////////////////////////////////////////
  36.    
  37.    
  38.     //////////////
  39.     // MODEL
  40.     public function set model( m:Observable ):Void
  41.     {
  42.         _model = m;
  43.     }
  44.    
  45.     public function get model():Observable
  46.     {
  47.         return _model;
  48.     }
  49.    
  50.    
  51.     //////////////
  52.     // CONTROLLER
  53.     public function set controller( c:IController ):Void
  54.     {
  55.         _controller = c;
  56.         controller.view = this;
  57.     }
  58.    
  59.     public function get controller():IController
  60.     {
  61.         if( _controller === undefined )
  62.         {
  63.             controller = defaultController;
  64.         }
  65.        
  66.         return _controller;
  67.     }
  68.    
  69.     public function get defaultController():IController
  70.     {
  71.         return null;
  72.     }
  73.    
  74.    
  75.    
  76. }
Reply With Quote