自定义事件错误 "Incorrect number of arguments. Expected no more than 1."
Custom Event Error "Incorrect number of arguments. Expected no more than 1."
我目前正在制作一个基本的自定义事件 class,它只传递一条数据。
package {
import flash.events.Event;
public class DateEvent extends Event {
public static const DATE_SET: String = "exampleEvent";
public var calendarObj: Object;
public function DateEvent(type: String, calendarObj: Object = null) {
this.calendarObj = calendarObj;
super(type, false, false);
}
override public function clone(): Event {
return new DateEvent(type, calendarObj);
}
}}
像这样调用事件时:
selectedDate = new Date(displayedYear, displayedMonthNum, displayedDate, displayedHour, displayedMins);
trace(selectedDate);
dispatchEvent(DateEvent(DateEvent.DATE_SET, selectedDate));
我遇到 "Incorrect number of arguments" 错误。我很困惑,因为我没有超过我应该通过的(我认为)。
您在调用 DateEvent
构造函数之前缺少 new
关键字。像这样-
dispatchEvent(new DateEvent(DateEvent.DATE_SET, selectedDate));
我目前正在制作一个基本的自定义事件 class,它只传递一条数据。
package {
import flash.events.Event;
public class DateEvent extends Event {
public static const DATE_SET: String = "exampleEvent";
public var calendarObj: Object;
public function DateEvent(type: String, calendarObj: Object = null) {
this.calendarObj = calendarObj;
super(type, false, false);
}
override public function clone(): Event {
return new DateEvent(type, calendarObj);
}
}}
像这样调用事件时:
selectedDate = new Date(displayedYear, displayedMonthNum, displayedDate, displayedHour, displayedMins);
trace(selectedDate);
dispatchEvent(DateEvent(DateEvent.DATE_SET, selectedDate));
我遇到 "Incorrect number of arguments" 错误。我很困惑,因为我没有超过我应该通过的(我认为)。
您在调用 DateEvent
构造函数之前缺少 new
关键字。像这样-
dispatchEvent(new DateEvent(DateEvent.DATE_SET, selectedDate));