home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Beez.swf / scripts / org / puremvc / as3 / patterns / observer / Observer.as < prev   
Encoding:
Text File  |  2008-09-03  |  1.3 KB  |  52 lines

  1. package org.puremvc.as3.patterns.observer
  2. {
  3.    import org.puremvc.as3.interfaces.INotification;
  4.    import org.puremvc.as3.interfaces.IObserver;
  5.    
  6.    public class Observer implements IObserver
  7.    {
  8.        
  9.       
  10.       private var notify:Function;
  11.       
  12.       private var context:Object;
  13.       
  14.       public function Observer(notifyMethod:Function, notifyContext:Object)
  15.       {
  16.          super();
  17.          setNotifyMethod(notifyMethod);
  18.          setNotifyContext(notifyContext);
  19.       }
  20.       
  21.       private function getNotifyMethod() : Function
  22.       {
  23.          return notify;
  24.       }
  25.       
  26.       public function compareNotifyContext(object:Object) : Boolean
  27.       {
  28.          return object === this.context;
  29.       }
  30.       
  31.       public function setNotifyContext(notifyContext:Object) : void
  32.       {
  33.          context = notifyContext;
  34.       }
  35.       
  36.       private function getNotifyContext() : Object
  37.       {
  38.          return context;
  39.       }
  40.       
  41.       public function setNotifyMethod(notifyMethod:Function) : void
  42.       {
  43.          notify = notifyMethod;
  44.       }
  45.       
  46.       public function notifyObserver(notification:INotification) : void
  47.       {
  48.          this.getNotifyMethod().apply(this.getNotifyContext(),[notification]);
  49.       }
  50.    }
  51. }
  52.