在actionscript 3中使用多个或仅一个eventlisteners

Fer*_*jka 1 flash events actionscript class actionscript-3

抱歉这个蹩脚的问题,但我不知道如何搜索它.所以如果我有两个来自同一个类的事件,比如:

package  {
import flash.events.Event;

public class StylingEvent extends Event{
    public static const BLUE_BG:String = "blue_bg";
    public static const GREEN_BG:String = "green_bg";

    public function StylingEvent(type:String) {
        super(type);
    }
}}
Run Code Online (Sandbox Code Playgroud)

我需要添加两个eventlisteners,如:

gameData.addEventListener(StylingEvent.BLUE_BG, onChangeBg);
gameData.addEventListener(StylingEvent.GREEN_BG, onChangeBg);
Run Code Online (Sandbox Code Playgroud)

或者有可能像:

gameData.addEventListener( [any type of stylingEvent] , [some method]);
Run Code Online (Sandbox Code Playgroud)

谢谢

Sun*_* D. 5

如上所示,是的,您需要添加两次事件侦听器.

要只添加一个事件侦听器,您可以修改事件类,以便只有一个事件名称:

public static const BACKGROUND_CHANGED = "backgroundChanged";
Run Code Online (Sandbox Code Playgroud)

然后在存储颜色的事件类中添加一个属性:

public var backgroundColor:uint;
Run Code Online (Sandbox Code Playgroud)

在分派事件时,请指定颜色:

var event:StylingEvent = new StylingEvent();
event.backgroundColor = 0x0000FF;
dispatchEvent(event);
Run Code Online (Sandbox Code Playgroud)