【问题标题】:Custom Event Error "Incorrect number of arguments. Expected no more than 1."自定义事件错误“参数数量不正确。预计不超过 1。”
【发布时间】:2016-04-29 01:21:03
【问题描述】:

我目前正在制作一个只传递一条数据的基本自定义事件类。

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));

我收到“参数数量不正确”错误。我很困惑,因为我没有超过我应该通过的(我认为)。

【问题讨论】:

    标签: actionscript-3 events actionscript


    【解决方案1】:

    在调用 DateEvent 构造函数之前,您缺少 new 关键字。像这样-

    dispatchEvent(new DateEvent(DateEvent.DATE_SET, selectedDate));
    

    【讨论】:

    • 就是这样!我不敢相信我忘了补充。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多