开发者

Removing object from the display list

开发者 https://www.devze.com 2023-03-05 10:51 出处:网络
I have an application that uses a main class to control other MovieClips, adding and removing them as needed, most of them are separate screens or sub menus.

I have an application that uses a main class to control other MovieClips, adding and removing them as needed, most of them are separate screens or sub menus.

When I leave the main menu and come back to it later from another screen, certain animations and roll over buttons still play, which I don't want, I basically need the main menu screen to reset every time it is seen.

I read up on this and found out that removing the child doesn't necessarily remove it from the memory.

I tried setting the mainmenu to null before moving onto a different screen but this threw up an error, stating that the parameter child must be none null.

Could anyone shed some light on how to completely kill my mainmenu when it is not needed.

public function confSubMenuOneScreen():void {
        subMenuOneScreen = new SubMenuOne();
        mainmenu = null;
        removeChild(mainmenu开发者_StackOverflow社区)
        addChild(subMenuOneScreen)
        currentScreen = subMenuOneScreen;
    }

This is the example of code that removes the menu and adds another screen, with the mainmenu = null code that throws up the error.


The error you're getting is because you're setting the object to null - then attempting to remove the object (which is now null). Reversing the two lines will probably fix the error. However, this won't free the object from memory until garbage collection removes it (assuming there are no other references to "mainmenu" in your application).

Rather than trying to delete the object and create new objects each time you need it, I would suggest creating one instance of "mainmenu" and reuse it. Then, just remove it from the display list and add it back when you need it again.

0

精彩评论

暂无评论...
验证码 换一张
取 消