我有一个自定义事件类,想要插入多个参数(比如本机事件: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.是否可以这样做?
答案 0 :(得分:1)
只需将它们添加为construcor参数,并使其在外部可见,就像使用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;}
}