actionscript 3 - saving path to xml node to avoid searching later -
i trying use xml in flash as3.
var record:xml = <person name="peter(grandfather)" age=54> <person name = "john(son1)" age = 28 > <person name = "bran(grandson1)" age = 2 /> </person> <person name = "rob(son2)" age = 25 > <person name = "lancel(grandson2)" age = 3 /> </person> <person>
this xml list dynamically updated. , each new person added dynamically, movie-clip person's name created , added stage. when movie-clip clicked want person's age increased 1.
a method comes mind save person's name in movie clip. like
... record.person.addchild(newperson); var newclip:movieclip = new movieclip; newclip.name = newperson.@name ... <newclip mouse click event> record..*.(@name==newclip.name).@age += 1; ....
the thing don't method requires @name == newclip.name comparision; guess requires name matching every node in xml record quite demanding process large xml record. need method save path given xml node can directly accessed later.
something this: so,
... record.person.addchild(newperson); var newclip:movieclip = new movieclip; newclip.xmlref = "<what put here?>" ... <newclip mouse click event> record.[newclip.xmlref].@age += 1; //i want able ....
thank you.
package { import flash.display.movieclip; import flash.events.mouseevent; /** * ... * @author xiler */ // class test public class xmltest extends movieclip { // xml tree here private var record:xml = <person name="peter(grandfather)" age="54"> <person name = "john(son1)" age = "28" > <person name = "bran(grandson1)" age = "2" /> </person> <person name = "rob(son2)" age = "25" > <person name = "lancel(grandson2)" age = "3" /> </person> </person> public function xmltest() { // here, create new xml, add tree, make movieclip reference it, , add stage listener var newperson:xml = < person name = "bob(son3)" age = "19" />; record.appendchild(newperson); var test1:movieclip = new movieclip(); addchild(test1); test1.xmlref = newperson; test1.graphics.beginfill(0x41ed07, 1); test1.graphics.drawrect(0, 0, 100, 100); test1.addeventlistener(mouseevent.click, testlistener); } private function testlistener(event:mouseevent = null):void { // here, clicked, , record xml updated , traced, know changed it. var itsxml:xml = event.currenttarget.xmlref; var newage:number = number(itsxml.@age) + 1; itsxml.@age = string(newage); trace(itsxml.@age); trace(record) } } }
this worked me. copy , paste in a main .as file .fla file, , test , see work. hope answers question, please respond if need further help.
Comments
Post a Comment