0

I know I can use the addEventListener method to handle one:

addEventListener(SFSEvent.CONNECTION, MyMethod)

as I would for handling a method in another class? Like...

addEventListener(SFSEvent.CONNECTION, Myclass.class)

or

addEventListener(SFSEvent.CONNECTION, MyClass.method)
Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
Rene
  • 1

1 Answers1

2

You may pass another function handler to a class

For example

Class A {

     public function A() {
          addEventListener(SFSEvent.CONNECTION, MyMethod);
     }

     private function _handler:Function;

     public function set handler(value:Function):void {
           _handler = value;
     }

     private function MyMethod(e:SFSEvent):void {

        if (_handler) {
            _handler.apply(null, someParam);
        }
     }

}

Then pass the target handler to A instance

var a:A = new A();
var b:Myclass = new Myclass();
a.handler = b.someMethod;

If the function is a static function, You may just do it like this

addEventListener(SFSEvent.CONNECTION, SomeClass.aStaticFunction);
Pan
  • 2,101
  • 3
  • 13
  • 17