Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 使用addeventlistener处理另一个类文件_Actionscript 3_Flash_Flash Builder_Smartfoxserver - Fatal编程技术网

Actionscript 3 使用addeventlistener处理另一个类文件

Actionscript 3 使用addeventlistener处理另一个类文件,actionscript-3,flash,flash-builder,smartfoxserver,Actionscript 3,Flash,Flash Builder,Smartfoxserver,我知道我可以使用addEventListener方法处理一个: addEventListener(SFSEvent.CONNECTION, MyMethod) 就像我在另一个类中处理方法一样?像 addEventListener(SFSEvent.CONNECTION, Myclass.class) 或 您可以将另一个函数处理程序传递给类 比如说 Class A { public function A() { addEventListener(SFSEvent

我知道我可以使用addEventListener方法处理一个:

addEventListener(SFSEvent.CONNECTION, MyMethod)
就像我在另一个类中处理方法一样?像

addEventListener(SFSEvent.CONNECTION, Myclass.class)


您可以将另一个函数处理程序传递给类

比如说

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);
        }
     }

}
然后将目标处理程序传递给实例

var a:A = new A();
var b:Myclass = new Myclass();
a.handler = b.someMethod;
如果函数是静态函数,您可以这样做

addEventListener(SFSEvent.CONNECTION, SomeClass.aStaticFunction);
addEventListener(SFSEvent.CONNECTION, SomeClass.aStaticFunction);