任何人都可以提供一个如何编写回调而不是使用事件在Actionscript 3.0中的两个类(对象)之间进行通信的示例吗?
只需将一个函数传递给另一个函数作为参数即可进行回调:
class A { function A(){ } // function to be called when work is finished private function workDone():void { //... } public function foo():void { var b:B=new B(); b.doWork(workDone); // pass the callback to the work function //can also be an anonymous function, etc.. b.doWork( function():void{ //.... } ); } } class B { function B(){ } public function doWork(callback:Function):void{ // do my work callback(); // call the callback function when necessary } }