在ActionScript 3.0,可以使用的addEventListener一类反应到另一个类的函数调用?可以使用、函数、应到、ActionScript

2023-09-08 11:54:31 作者:小软糖

我知道如何使用的addEventListener一类反应被点击的另一个类的按钮。如果你想使用它比一个更通用的?如果你想用它来应对其他类的成员函数被什么叫?是否有一个语法?谢谢!

I know how to use addEventListener for one class to react to another class's button being clicked on. What if you want to use it for a more general purpose than that? What if you want to use it to react to one of the member functions of the other class being called? Is there a syntax for that? Thanks!

编辑:请注意,我已经用Google搜索的答案

Please note that I have already Googled for the answer.

推荐答案

您可以创建自己的事件,并从其他类调度他们,听他们在听力课。下面是一些code

You can create your own events and dispatch them from the other class and listen to them in your listening class. Here is some code

在A级(假设它继承的EventDispatcher)

In class A (assuming it inherits EventDispatcher)

public function classAMethod():void
{
   dispatchEvent(new Event("someCustomTypeForEvent"));
}

在B类(假设它有一个参考A级)

In class B (assuming it has a reference to Class A)

public function classBMethod():void
{
   classA.addEventListener("someCustomTypeForEvent",customHandler);
}

public function customHandler(e:Event):void
{
   trace("handle event");
}