-
Senior Member
Skipping to the next letter using XML files
I have a simple XML file that has a list of names and I need two buttons. One that simply shows the next mane and the other to show the next name that begins with a different letter. Now I can scroll through the list just fine. However I am having issues with skipping to the next name beginning with a different letter. For example if the list contained these three names; Brian, Bill and Ted I need to skip from Brian to Ted in one click.
This is the code I have so far, but for whatever reason it is skipping to the last letter in the list no matter what letter you are on currently.
PHP Code:
currentLetter = _root.nameXML.firstChild.childNodes[tempNum].attributes.name.charAt(0);
for (r=0; r<=_root.nameXML.firstChild.childNodes.length-1; r++) {
if (currentLetter != _root.irCodeXML.firstChild.childNodes[r].attributes.name.charAt(0)) {
mRDevice_txt = _root.irCodeXML.firstChild.childNodes[r].attributes.name;
}
}
I am by no means and expert at flash so any help would be greatly appreciated.
-
First things first, the best practice for looping XML is (r=0; r<xml.length; r++).
Try to make sure that the currentLetter variable is also updated when you are traversing the loop ie.
var currentLetter = _root.nameXML.firstChild.childNodes[0].attributes.name.charAt(0);
var previousLetter = currentLetter;
for (r=0; r<_root.nameXML.firstChild.childNodes.length; r++)
{
currentLetter = _root.nameXML.firstChild.childNodes[r].attributes.name.charAt(0);
if(currentLetter != _root.irCodeXML.firstChild.childNodes[r].attributes.name.charAt(0))
{
mRDevice_txt = _root.irCodeXML.firstChild.childNodes[r].attributes.name;
break;
}
previousLetter = currentLetter;
}
}
Also, make sure you are updating the currentLetter when moving from name to name one by one.
-
Senior Member
Nice so "charAt(0)" just takes the first letter of the string? Seems simple enough thanks.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|