dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Load xml data into a flash array

Hybrid View

  1. #1
    Junior Member
    Join Date
    Dec 2008
    Posts
    7

    Exclamation Load xml data into a flash array

    Hallo.

    I have 3 movie clips (cont1,cont2,cont3) on my stage, each movieclip contains a dynamic text field (name) and another movieclip (image).

    example:
    <people>
    <student><name>sara</name><image>image1.jpg</image></student>
    <student><name>manju</name><age>image2.jpg</image></student>
    <student><name>sind</name><age>image3.jpg</image></student>
    </people>

    I would like to load the data from an xml file into those 3 movieclips so that
    the first movie clip contains data from the first student xml line code (name=sara, image=image1.jpg). The second movie clip from the second one and so on.


    I suppose in order to accomplish what I want I have to convert the xml data into an array.. correct?
    If there is another approach please feel free to comment.

    Can anyone please help me with my project?
    Any reference or links will be deeply appreciated.
    Thanks.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    PHP Code:
    names = [];
    images = [];

    _xml = new XML();
    _xml.ignoreWhite true;
    _xml.load("people.xml");

    _xml.onLoad = function(){
    nodes this.firstChild.childNodes;
    len nodes.length;
    for(var 
    n=0;n!=len;n++){
    names[n] = nodes[n].firstChild.childNodes.toString();
    images[n] = nodes[n].firstChild.nextSibling.childNodes.toString();
    }
    };

    /* this produces two arrays -

    Variable _level0.names = [object #1, class 'Array'] [
        0:"sara",
        1:"manju",
        2:"sind"
      ]
    Variable _level0.images = [object #2, class 'Array'] [
        0:"image1.jpg",
        1:"image2.jpg",
        2:"image3.jpg"
      ]
    */ 
    PHP Code:
    <people>
    <
    student>
    <
    name>sara</name>
    <
    image>image1.jpg</image>
    </
    student>
    <
    student>
    <
    name>manju</name>
    <
    image>image2.jpg</image>
    </
    student>
    <
    student>
    <
    name>sind</name>
    <
    image>image3.jpg</image>
    </
    student>
    </
    people

  3. #3
    Junior Member
    Join Date
    Dec 2008
    Posts
    7
    Thanks a lot for your help!
    It works perfectly fine .

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