0 Replies Latest reply: Aug 18, 2009 1:26 AM by nick.doyle RSS

    Static event listener modifying object's variables

    nick.doyle Community Member

      Hi all

      Generally:
      I have a class, which will be instantiated as an object.
      He needs to contain an event listener, which apparently must be static to be seen/assigned as an event listener.
      However because the listener is static, he can't modify the object's properties?

      What is the correct pattern here?

      Specifically:
      This is an implementation of a media player which is using the NCManager class from Will Law here:
      http://www.adobe.com/devnet/flashcom/articles/firewall_streaming_print.html
      (ported to AS3)
      to find, in parallel, the best connection to the media server (rtmp/rtmpt/diff ports)
      and use that to start playing.

      Code extract:

      package blabla {
        public class RTMPModel extends AbstractModel {

         public static function ncConnected(evt:Object) :void {
           trace("Successfully connected using "+evt.protocol+":"+evt.port);
           connection = evt.connection; // store the successful connection ... as one of the object's properties ....
           // start playing ...
         }

         var ncm:NCManager = new NCManager();
         ncm.addEventListener("ncConnected", ncConnected);
         ncm.connect( item['streamer'], appName, username, password);


        }
      }


      Thanks in advance,
      Nick