'"TypeError: Error #1010: A term is undefined and has no properties." in Adobe Animate

i am creating a game rn, and i have popup feature on my game,i make 2 popup for my game, but when i aplly the code for the second popup, it doesn't work, can you help me by seeing my code, thank you. there's an error appeared.

TypeError: Error #1010: A term is undefined and has no properties.
at TugasMMIFIX_fla::MainTimeline/addPopup_2()
at TugasMMIFIX_fla::MainTimeline/popupBaju()

And this is my code (including the first popup code):

import flash.events.MouseEvent;

var popup = new popupRumahMC;
var isPopup = false;

function addPopup(str=""):void{
 popup = new popupRumahMC;
 popup.closeBtn.addEventListener(MouseEvent.CLICK, closePopup);
 popup.x = 640;
 popup.y = 360;
 addChild(popup);
 isPopup = true;
}

function removePopup():void{
 popup.closeBtn.removeEventListener(MouseEvent.CLICK, closePopup);
 removeChild(popup);
 isPopup = false;
}

function closePopup(e:MouseEvent):void{
 removePopup();
}

rumahBtn.addEventListener(MouseEvent.CLICK,popuprumah)
function popuprumah(e:MouseEvent){
addPopup(); 
}

//popup 2//

var popup_2 = new popupBajuMC;
var isPopup_2 = false;

function addPopup_2(str=""):void{
 popup_2 = new popupBajuMC;
 popup_2.copycloseBtn.addEventListener(MouseEvent.CLICK, closePopup_2);
 popup_2.x = 643;
 popup_2.y = 360;
 addChild(popup_2);
 isPopup_2 = true;
}

function removePopup_2():void{
 popup_2.copycloseBtn.removeEventListener(MouseEvent.CLICK, closePopup_2);
 removeChild(popup_2);
 isPopup_2 = false;
}

function closePopup_2(e:MouseEvent):void{
 removePopup_2();
}

bajuBtn.addEventListener(MouseEvent.CLICK,popupBaju)
function popupBaju(e:MouseEvent){
addPopup_2();   
}

I'm trying to fix that error, and unfortunately, it fails. I have double-checked it. What do you think is the problem with this code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source