Skip to main content
Participant
December 15, 2011
Answered

XML Current & Next Item

  • December 15, 2011
  • 1 reply
  • 619 views

Hi, I have this code within the flash to load in the XML file. A list of buttons is generated from the XML list. How do I find out which is the current 'item' selected, and then how to select the next 'item' from the XML list - Thanks


myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("items.xml");
myXML.onLoad = function(_status) {
if (_status) {
var clientList:Array = [];
var clientRegistry:Object = {};
tempxml = myXML.firstChild.childNodes;
var space = 10;

for (var i = 0; i<tempxml.length; i++) {
var clientData:Object = {};
var item = all_items.list_mc.attachMovie("clip", "clip"+i, i);

item._x = clientData["x"]=(item._width+space)*i;
item.title_txt.text = clientData["title"]=tempxml.attributes.title;
item.path = tempxml.attributes.path;
item.thumb = tempxml.attributes.thumb;
item.swf = tempxml.attributes.swf;
}

}
};

This topic has been closed for replies.
Correct answer kglad

use:


myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("items.xml");
myXML.onLoad = function(_status) {
if (_status) {
var clientList:Array = [];
var clientRegistry:Object = {};
tempxml = myXML.firstChild.childNodes;
var space = 10;

for (var i = 0; i<tempxml.length; i++) {
var clientData:Object = {};
var item = all_items.list_mc.attachMovie("clip", "clip"+i, i);

item.ivar=i;

item.onRelease=function(){

trace("item "+this.ivar+" was clicked\nNext item is "+(this.ivar+1)+" unless "+this.ivar+" = "+(tempxml.length-1));

}

item._x = clientData["x"]=(item._width+space)*i;
item.title_txt.text = clientData["title"]=tempxml.attributes.title;
item.path = tempxml.attributes.path;
item.thumb = tempxml.attributes.thumb;
item.swf = tempxml.attributes.swf;
}

}
};

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
December 15, 2011

use:


myXML = new XML();
myXML.ignoreWhite = true;
myXML.load("items.xml");
myXML.onLoad = function(_status) {
if (_status) {
var clientList:Array = [];
var clientRegistry:Object = {};
tempxml = myXML.firstChild.childNodes;
var space = 10;

for (var i = 0; i<tempxml.length; i++) {
var clientData:Object = {};
var item = all_items.list_mc.attachMovie("clip", "clip"+i, i);

item.ivar=i;

item.onRelease=function(){

trace("item "+this.ivar+" was clicked\nNext item is "+(this.ivar+1)+" unless "+this.ivar+" = "+(tempxml.length-1));

}

item._x = clientData["x"]=(item._width+space)*i;
item.title_txt.text = clientData["title"]=tempxml.attributes.title;
item.path = tempxml.attributes.path;
item.thumb = tempxml.attributes.thumb;
item.swf = tempxml.attributes.swf;
}

}
};

Jon_EvansAuthor
Participant
December 16, 2011

Thanks Kglad

When the user clicks an 'item' it loads in item attributes into an mc as shown above. How would I load the next items attributes, as in the following item in the XML list?

kglad
Community Expert
Community Expert
December 16, 2011

the only code showing an item mouse handler is the code i suggested and that code is not loading anything.