完全删除 class

Removing class completely

我有一个 class 文件,我想多次调用它。这是一个扩展精灵的名为 PopupDialog 的 class。在我删除它并再次添加它之后,旧的也会出现。我需要完全删除旧的。这是我的代码:

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

这实际上不能删除 class。我尝试将其设置为 null 但是后来我开始遇到一些其他问题。

试试这个:

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

希望对您有所帮助!