nikel
nikel

Reputation: 653

Removing class completely

I have a class file and I want call it multiple times. It's a class named PopupDialog that extends sprite. After I remove it and add it again, the older one appears as well. I need to delete the older one completely. Here's my code:

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

This can't actually delete the class. I tried setting it to null however then I started to have some other problems.

Upvotes: 0

Views: 41

Answers (1)

Antizam
Antizam

Reputation: 216

Try this:

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

Hope it helps!

Upvotes: 1

Related Questions