You have to remove var MC
from both handlers, as you want your new MC to be accessible from outside of the handlers. But also you need to change the type of class variable MC
so that it could hold either movieclipsymbol1
or movieclipsymbol2
. The most common choice for the type in there is MovieClip
. So, you have to change your functions like this:
var MC:MovieClip = new movieclipsymbol1();
private function screenbutton1(event: MouseEvent): void {
clearOldMC();
MC = new movieclipsymbol1();
movieclipscreen();
}
private function screenbutton2(event: MouseEvent): void {
clearOldMC();
MC = new movieclipsymbol2();
movieclipscreen();
}
private function clearOldMC():void {
if (MC.parent) MC.parent.removeChild(MC);
}
The new function removes the previously displayed movie clip, regardless of its type.