如何为自定义事件创建多个类型和参数?

How can I create multiple types & params for custom events?

我有一个自定义事件 class 并且想要插入多个参数(例如本机事件:MOUSE_UP、CLICK、ROLL_OVER)。到目前为止,这是我的代码:

package
{
    import flash.events.Event;

    public class MenuGeneratorEvent extends Event
    {
        public static const PASS_PARAMS:String = "passParams";

        public var param1:String = new String();

        public function MenuGeneratorEvent(type:String, str:*, bubbles:Boolean = false,
                                                cancelable:Boolean = false):void
        {
            this.param1 = str;

            super(type, bubbles, cancelable);
        }

        override public function clone():Event
        {
            return new MenuGeneratorEvent(type, param1, bubbles, cancelable);
        }
    }
}

我使用的是 Flash Professional CC 2015。可以这样做吗?

只需将它们添加为构造函数参数并使其在外部可见,就像您对 param1 所做的那样。 如果您必须将许多参数作为构造函数参数传递,您总是可以将它们包装在另一个对象中。如果你想直接从事件对象访问它们,只需创建它们的访问器:

public class MenuGeneratorEvent extends Event
{
    public static const PASS_PARAMS:String = "passParams";

    private var params:Object;

    public function MenuGeneratorEvent(type:String, params:Object, bubbles:Boolean = false,
                                            cancelable:Boolean = false):void
    {
        this.params = params;

        super(type, bubbles, cancelable);
    }

    override public function clone():Event
    {
        return new MenuGeneratorEvent(type, params, bubbles, cancelable);
    }

    public function get param1():String{return params.param1;}
    public function get param2():Number{return params.param2;}
    public function get param3():Object{return params.param3;}
}