Need some help - Never done this before...
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Need some help - Never done this before...

  1. #1
    Senior Member
    Join Date
    Nov 2000
    Posts
    177
    Hello all,

    I know that most of you know how to do this, however I've never tried, and don't really understand how the book explains it.

    I have an XML file filled with strings I need to use in flash.

    ex:
    Code:
    [XML]
    [MAIN]
    [TEXT]This is one[/TEXT]
    [TEXT] This is two[/TEXT]
    ... continued
    [/MAIN]
    [/XML]
    (with all the "["'s replaced with "<"'s)

    Now what I want to do is to dynamically load randomlly load one of these strings into my dynamic text box!
    Can someone explain how to randomally get the strings from the xml? mostly how to get them though, I can do the random stuff.

    Thanks in advance!!


  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112

    Ok...

    You'll probably like using the childNodes property/array.

    For instance:: (using your XML file...)

    nameOfXMLObj = new XML;
    nameOfXMLObj.load("yourXMLFile.xml");
    firstText = nameOfXMLObj.childNodes[0].childNodes[0].childNodes[0];
    secondText = nameOfXMLObj.childNodes[0].childNodes[0].childNodes[1];
    thirdText = nameOfXMLObj.childNodes[0].childNodes[0].childNodes[2];

    So you get the idea... childNodes is an array like property.. I'm not sure how to describe it... use it like an array by accessing items in it's 'list' with [] operators... and it can be placed after a node, to access that nodes children...

    Parent
    child1
    child2
    child3
    /Parent

    So Parent.childNodes[2] would give you child3.... I hope this is making sense.... Look under childNodes in the Flash help files...

    OH - and as always, don't forget to deal with the elusive 'whitespace nodes'.... they will also show up on the childNodes array...

    As for your randomness.. just randomise the number inside the brackets, make sure that it isn't over the parent.childNodes.length property of your array....

  3. #3
    Senior Member
    Join Date
    Nov 2000
    Posts
    177
    Thank you very much for your help,
    I appreciate it!

    also, just as a question if I have a file like this:

    (quotes.xml)
    Code:
    [MAIN]
     
    text
    text2
    [/MAIN]
    I can access it by using:
    Code:
    quotes = new XML();
    quotes.load(quotes.xml);
    ran = random(142);
    display = quotes.childNodes[0].childNodes[ran];
    ???

    Will that work? - I've been having some problems with it.

    Thanks again!


  4. #4
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112

    Ok...

    Yeah.. you've got the idea - you'll want to mess around with the number of childNodes tags you'll need to access certain levels of code.. due to whitespace...

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

Poll by Flashkit.com