actionscript 3 - removeChild in Flash AS3 -
i want clear xml object loaded on stage when click tuebutton
monbutton.addeventlistener(mouseevent.click, monhandler); function monhandler(evt:mouseevent):void { trace(evt.type); // set "y" location on stage first box live var yplacement:int = 110; // set "x" location on stage boxes line vertically var xplacement:int = 30; // set distance each box should apart here var distance:int = 25; // initialize xml, place xml file name, initialize urlrequest // put urlrequest new urlloader, , add event listener on // myloader listening when xml loading complete var myxml:xml = new xml(); var xml_url:string = "menu.xml"; var myxmlurl:urlrequest = new urlrequest(xml_url); var myloader:urlloader = new urlloader(myxmlurl); myloader.addeventlistener("complete", xmlloaded); // create xmlloaded function function xmlloaded(event:event):void { // place xml data myxml object myxml = xml(myloader.data); // initialize , give var name new external xmldocument var xmldoc:xmldocument = new xmldocument(); // ignore spacing around nodes xmldoc.ignorewhite = true; // define new name loaded xml data in myloader var menuxml:xml = xml(myloader.data); // parse xml data readable format xmldoc.parsexml(menuxml.toxmlstring()); // run "for each" loop iterate through of menu items listed in external xml file each (var maindish:xml in myxml.monday.maindish) { // access value of "itemcolor" node in our external xml file var dishname:string = maindish.dname.tostring(); // access value of "itemlabel" node in our external xml file var dishsmall:string = maindish.small.tostring(); // access value of "itemphone" node in our external xml file var dishlarge:string = maindish.large.tostring(); // pertains style of box holds each person var rect:shape = new shape; var color:number = number(0xffffff); rect.graphics.beginfill(color); //rect.graphics.linestyle(1, 0x999999); // draw box rect.graphics.drawrect(0, 0, 150, 50); // pertains text fields give our boxes labels, alter values liking var mytext1:textfield = new textfield(); mytext1.text = dishname; mytext1.autosize = textfieldautosize.left; mytext1.x = 2; mytext1.y = 0; var mytext2:textfield = new textfield(); mytext2.text = dishsmall; mytext2.autosize = textfieldautosize.left; mytext2.x = 250; mytext2.y = 0; var mytext3:textfield = new textfield(); mytext3.text = dishlarge; mytext3.autosize = textfieldautosize.left; mytext3.x = 300; mytext3.y = 0; // create movieclip holder each box graphic , text labels organize container var clip_mc = new movieclip(); // add rectangle graphic clip_mc.addchild(rect); // add text fields clip_mc.addchild(mytext1); clip_mc.addchild(mytext2); clip_mc.addchild(mytext3); // put new movieclip on stage addchild(clip_mc); // apply in offset y position stage clip_mc.y = yplacement; // x position placed on stage clip_mc.x = xplacement; // offset each 1 in loop make sure don't put right on top of each other yplacement = yplacement + distance; } } this.days.gotoandstop("monday"); } tuebutton.addeventlistener(mouseevent.click, tuehandler); function tuehandler(evt:mouseevent):void { trace(evt.type); removechild(clip_mc); this.days.gotoandstop("tuesday"); }
in monday button handler, give clip name right after declare it, so:
var clip_mc = new movieclip(); clip_mc.name = "monday_mc"
then in tuesday button handler, before gotoandplay:
removechild(this.getchildbyname('monday_mc'));
on note, easier have 1 function parse xml data date variable pass function have of xml parsing happen within button handler code.
Comments
Post a Comment