dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: XMLList as dataProvider of dataGrid

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    3

    Question XMLList as dataProvider of dataGrid

    I'm learning xml and actionscript 3.0 at the moment, and I'm making myself a little test application to improve.
    It's basically an external xml file with artist, album, and track info.
    I loaded my external xml file into an XML object called music.
    I already extracted the artist name, album title, release date and cover art, and got those to display on the stage.
    The only thing left to do is load the list of tracks into a datagrid component.
    I got the list of all tracks into an XMLList called trackList.
    I traced this list and it looks fine:

    Code:
    <track id="1">
      <no>1</no>
      <title>Cruising</title>
      <length>03:48</length>
    </track>
    <track id="2">
      <no>2</no>
      <title>Joy</title>
      <length>06:22</length>
    </track>
    <track id="3">
      <no>3</no>
      <title>Marriage</title>
      <length>03:35</length>
    </track>
    <track id="4">
      <no>4</no>
      <title>Creation a Child</title>
      <length>06:53</length>
    </track>
    <track id="5">
      <no>5</no>
      <title>Just a Man</title>
      <length>03:15</length>
    </track>
    <track id="6">
      <no>6</no>
      <title>We Cant Make it, Love</title>
      <length>02:30</length>
    </track>
    <track id="7">
      <no>7</no>
      <title>Not Mine</title>
      <length>03:29</length>
    </track>
    <track id="8">
      <no>8</no>
      <title>Where is She</title>
      <length>03:36</length>
    </track>
    <track id="9">
      <no>9</no>
      <title>Mythical Dream</title>
      <length>04:54</length>
    </track>
    I have a dataGrid component set up on my main timeline with the instance name trackGrid.
    I already set the column names of the trackGrid correctly, but how would I go about specifying the list as a dataProvider to fill the columns with track number, title, and length?
    I looked for different snippets of code everywhere, but I just couldn't get it working, even though I have the feeling it probably wouldn't be that hard to fix.
    This is the code I used, but it's giving me a typeError #1088:
    Code:
    var trackList:XMLList = music.artist.album.track;
    	trackGrid.addColumn("No.");
    	trackGrid.addColumn("Title");
    	trackGrid.addColumn("Length");
    	trace(trackList);
    	var xmlTrackList:XML = new XML(trackList);
    	trackGrid.dataProvider = new DataProvider(xmlTrackList);
    Any help?

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to change the column titles to have the same name as the nodes in the XML:
    trackGrid.addColumn ("no");
    trackGrid.addColumn ("title");
    trackGrid.addColumn ("length");

    Also you may get an error message saying that the XML is malformed, because the XML list has no root node.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    I already added the columns to the trackGrid to match the nodes (should have posted that), but the lack of a root node sounds logical.
    How should I go about adding those at the beginning and end of the XMLList with actionscript?

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    For example:
    var xmlTrackList:XML = new XML("<items>"+trackList+"</items>");
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

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