dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Skipping to the next letter using XML files

Hybrid View

  1. #1
    Senior Member hts5000's Avatar
    Join Date
    Oct 2007
    Posts
    160

    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=0r<=_root.nameXML.firstChild.childNodes.length-1r++) {
        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.

  2. #2
    Junior Member
    Join Date
    Jun 2010
    Location
    Toronto
    Posts
    28
    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.

  3. #3
    Senior Member hts5000's Avatar
    Join Date
    Oct 2007
    Posts
    160
    Nice so "charAt(0)" just takes the first letter of the string? Seems simple enough thanks.

  4. #4
    Junior Member
    Join Date
    Jun 2010
    Location
    Toronto
    Posts
    28
    Correct!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center