actionscript 3 - Remove duplicate enteries/items from XML in AS3 -
i'm getting duplicate results xml file. want delete excess ones having trouble achieving using splice
, indexof
. can point me in right direction??
var xmlloader:urlloader = new urlloader(); var xmlreq:urlrequest = new urlrequest("data.xml"); xmlloader.load(xmlreq); var background:bkg; var textvar:textfield = new textfield; xmlloader.addeventlistener(event.complete, convertdata); function convertdata(event:event){ var xmlinfo:xml = new xml(event.target.data); //trace(xmlinfo); var list:xmllist = xmlinfo.profile.photography; var totalimage:number = list.length(); trace("length " + totalimage); enterbtn.addeventlistener(mouseevent.click, entersite); function entersite(event:mouseevent){ (var i:int =0; i<totalimage; i++){ trace(xmlinfo.profile.photography[i]); background = new bkg(); background.y = i*40; background.x =80; addchild(background); textvar = new textfield(); textvar.text = list[i]; background.addchild(textvar); } } }
xml file
<profile> <first_name>ann</first_name> <last_name> lee</last_name> <photography>sport</photography> <photography>landscape</photography> <photography>still life</photography> <image>img1.jpg</image> </profile> <profile> <first_name>john</first_name> <last_name> thomas</last_name> <photography>wildlife</photography> <photography>landscape</photography> <image>img2.jpg</image> </profile>
here example on how you'd like:
using test xml:
var xml:xml = <data> <profile> <first_name>ann</first_name> <last_name> lee</last_name> <photography>sport</photography> <photography>landscape</photography> <photography>still life</photography> <image>img1.jpg</image> </profile>; <profile> <first_name>john</first_name> <last_name> thomas</last_name> <photography>wildlife</photography> <photography>landscape</photography> <image>img2.jpg</image> </profile></data>;
//create array, , popluate xml nodes var list:array = new array(); xml.profile.photography.(list.push(tostring())); // ^ converts xmllist array running method in brackets on each item in xmllist //sort duplicate values grouped list.sort(); trace(list); //this traces out full list //now iterate array/vector var i:int = 0; while(i < list.length) { //while next item matches current, splice out while(i < list.length+1 && list[i] == list[i+1]) { list.splice(i, 1); } i++; } trace(list); //this list no duplicates
Comments
Post a Comment