0

I've tried every example I could find, but nothing really worked. What I'm looking for the to actionscript code (without using classes - i'd like to do all the code in the section of the mxml file) to load in an XML file that is stored in the same location as the swf file.

My XML is set up like the following:

<?xml version="1.0" encoding="utf-8"?>
<projects>
    <project>
        <projName>project1</projName>
        <startDate>5/5/2011</startDate>
        <positions>
            <position>
                <startOffset>1</startOffset>
                <numDays>4</numDays>
                <role>1D</role>
                <student>Project 1 - Name 1</student>
            </position>
            ... repeat for however many position pieces there are
        </positions>
    </project>
    ... repeat for however many project pieces there are
</projects>

I am looking to read this in as a simple XML (projectsXML for the variable name) so that i can do something like:

<mx:Repeater id="singleProject" dataProvider="{projectsXML.projects.project}">
    <mx:Text id="projectName" text="{singleProject.currentItem.projName}" />
</mx:Repeater>

What I'll actually be doing is calling components within the repeater and passing along the variables, but if i can achieve the above, I'm pretty sure I can figure out the rest.

If anybody can help me out here, it'd be greatly appreciated... so i can stop pounding my head against the wall :(

Thanks in advance, Alex

Brds
  • 1,035
  • 3
  • 17
  • 37

2 Answers2

2

Try this and see if it works ...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
     minWidth="955" minHeight="600"
        creationComplete="{projectsHttp.send()}" layout="vertical">
    <mx:HTTPService id="projectsHttp" url="projects.xml" />
    <mx:Repeater id="rpt" 
         dataProvider="{projectsHttp.lastResult.projects.project}" >
        <mx:Label text="{rpt.currentItem.projName}" />
    </mx:Repeater>
</mx:Application>
Sai
  • 3,819
  • 1
  • 25
  • 28
  • when i try to incorporate it into my code it doesnt display when i run the application I have the following code: – Brds May 05 '11 at 02:04
  • It is difficult for me to figure out without knowing details of the "project" component in the code snippet above. Also where is the Canvas in relation to the application. Sorry if i am not being helpful . 1 immediate question i have is -- Are you calling send() ? – Sai May 05 '11 at 02:25
  • I'm not exactly sure what i did, but i got it working... now i'm running into another issue. In my repeater, where I call the project component, i'm passing along this: projectPositions="{projectRP.currentItem.positions.position}"..... on the project component, i declare projectPositions as an Object. Is this correct? I need to be able to navigate through projectPositions and see each element in that object. – Brds May 05 '11 at 03:28
1

You would use the HTTPService (or a similar method) to load the XML data, then use the result to populate your list after it has loaded.

Here is an example: http://blog.flexexamples.com/2008/03/29/dynamically-loading-xml-files-using-the-httpservice-tag/

The URLLoader class is also an option in lieu of HTTPService. The general method is the same for both.

drkstr
  • 609
  • 6
  • 9