MV setHandler is not a function error

Hello, im trying to do a custom window, but when i try to put the script to close the window when pressed "Cancel" button the game got a typeError saying the "this._brandnewwindow.setHandler is not a function". What i should do?

1680729829263.png

JavaScript:
function Scene_Testing() {
    this.initialize.apply(this, arguments);
}

Scene_Testing.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Testing.prototype.constructor = Scene_Testing;

Scene_Testing.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};


Scene_Testing.prototype.create = function () {
    Scene_MenuBase.prototype.create.call(this);
    this._brandnewwindow = new Window_Testing(0, 0, 320, 240);
    this._brandnewwindow.setHandler('cancel', this.popScene.bind(this));
    this.addWindow(this._brandnewwindow);

};



function Window_Testing () {
    this.initialize.apply(this, arguments);
}

Window_Testing.prototype = Object.create(Window_Base.prototype);
Window_Testing.prototype.constructor = Window_Testing;

Window_Testing.prototype.initialize = function (x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
}
Hi there!

That is happening because, by default, Window_Base doesn't have the setHandler method like the Window_Command.

If you want to close a window that inherits from the Window Base, you can try applying the following on the Window Update function or the Scene Update function:

JavaScript:
const Window_Testing_update = Window_Testing.prototype.update
Window_Testing.prototype.update = function(){
    Window_Testing_update.call(this)
    if(Input.isTriggered("cancel") && this.isOpen()){
        this.close()
    }
}
Hi there!

That is happening because, by default, Window_Base doesn't have the setHandler method like the Window_Command.

If you want to close a window that inherits from the Window Base, you can try applying the following on the Window Update function or the Scene Update function:

JavaScript:
const Window_Testing_update = Window_Testing.prototype.update
Window_Testing.prototype.update = function(){
    Window_Testing_update.call(this)
    if(Input.isTriggered("cancel") && this.isOpen()){
        this.close()
    }
}
Thank you 🙂

Original thread: https://forums.rpgmakerweb.com/threads/sethandler-is-not-a-function-error.156447/