actionscript 3 - Replacing a movieclip with another movieclip, keeping the same instance name -
i'm new actionscript question might stupid one.
i'm trying replace movieclip movieclip, while keeping instance name of previous.
i have menu selection of buttons, each leading same screen movieclip , scrubber bar. tried defining movieclip through variable, tried redefining through event listener function, i'm guessing can't this:
var mc: movieclipsymbol1 = new movieclipsymbol1; private function selectionscreen(): void { selectionscreenbutton1.addeventlistener(mouseevent.click, screenbutton1); selectionscreenbutton2.addeventlistener(mouseevent.click, screenbutton2); private function screenbutton1(event: mouseevent): void { var mc: movieclipsymbol1 = new movieclipsymbol1; movieclipscreen(); } private function screenbutton2(event: mouseevent): void { var mc: movieclipsymbol2 = new movieclipsymbol2; movieclipscreen(); } } public function movieclipscreen(): void { stage.addchild(mc); }
because of scrubber bar code did, need keep instance movieclips same. approach i'm using off?
you have remove var mc
both handlers, want new mc accessible outside of handlers. need change type of class variable mc
hold either movieclipsymbol1
or movieclipsymbol2
. common choice type in there movieclip
. so, have change functions 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 displayed movie clip, regardless of type.
Comments
Post a Comment