How to remove custom windows?

Greetings Fam,

I'm using a combination of Galv's screen buttons and adding 2 windows behind them with the following:

var win = new Window_Base(48, 48, 336, 336);
SceneManager._scene.addChild(win)


var win = new Window_Base(768, 144, 288, 336);
SceneManager._scene.addChild(win)

How would I remove them?

I tried SceneManager._scene.removeChild(win), but it didn't work.


Thanks,
Can you post all the code you have?
ef8128ef-1cd4-4b74-a527-b7e3a0fcd474
I can't upload it for some reason, so I'll type it out:

Text: blah blah
Script: var win = new Window_Base(48, 48, 336, 336);
SceneManager._scene.addChild(win)
Script: Add 9 Galv screen buttons connected to 9 common events
Script: var win = new Window_Base(768, 144, 288, 336);
SceneManager._scene.addChild(win)
Show picture: #1...
Control Self Switch: A = On

On self switch page:

If: some variable = 5
Erase pictures
Script: SceneManager._scene.removeChild(win)
etc.....

I'm getting an error for having an undefined win. When I add the var win = new Window_Base(48, 48, 336, 336) to the same script, I don't get the error, but the windows don't delete.
Because the win variable is only visible in the scriptcall it was declared.

You need to change it a bit.
Code:
var win = new Window_Base(blah);
SceneManager._scene.addChild(win);
$gameTemp._addedWindows = $gameTemp._addedWindows || [];
$gameTemp._addedWindows.push(win);
You need to store every reference of all added windows, so that you can remove it.

Code:
$gameTemp._addedWindows.forEach(function (win) {
SceneManager._scene.removeChild(win); });
$gameTemp._addedWindows = [];
Solved. Thank you very much, Waynee95.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-remove-custom-windows.84009/