我有一个类文件,我想多次调用它。它是一个名为PopupDialog的类,它扩展了sprite。删除它并再次添加后,旧的也会出现。我需要完全删除旧版本。这是我的代码:
function onSettings(event:MouseEvent):void {
addChild(popupDialog);
popupDialog.init(spWidth, spHeight, dialogSettings);
popupDialog.addEventListener(CustomEvent.PASS_PARAMS, onProcessedEvent);
spWidth = spWidth - 50;
spHeight = spHeight - 50;
}
function onProcessedEvent(e:CustomEvent):void {
popupDialog.removeEventListener(CustomEvent.PASS_PARAMS, onProcessedEvent);
if (e.btnName == "close") {
removeChild(popupDialog);
}
}
这实际上无法删除该类。我尝试将其设置为null然后我开始遇到其他一些问题。
答案 0 :(得分:1)
试试这个:
var popupDialog:PopupDialog;
function onSettings(event:MouseEvent):void {
popupDialog=new PopupDialog();
addChild(popupDialog);
popupDialog.init(spWidth, spHeight, dialogSettings);
popupDialog.addEventListener(CustomEvent.PASS_PARAMS, onProcessedEvent);
spWidth = spWidth - 50;
spHeight = spHeight - 50;
}
function onProcessedEvent(e:CustomEvent):void {
popupDialog.removeEventListener(CustomEvent.PASS_PARAMS, onProcessedEvent);
if (e.btnName == "close") {
e.currentTarget.parent.removeChild(e.currentTarget);
}
}
希望它有所帮助!