Flex 3:读取外部 xml 文件 - 遇到一些问题
我尝试了所有能找到的例子,但没有任何效果。我正在寻找的 to actionscript 代码(不使用类 - 我想执行 mxml 文件部分中的所有代码)以加载到与 swf 文件存储在同一位置的 XML 文件中。
我的 XML 设置如下:
<?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>
我希望将其作为简单的 XML(变量名的projectsXML)读取,以便我可以执行以下操作:
<mx:Repeater id="singleProject" dataProvider="{projectsXML.projects.project}">
<mx:Text id="projectName" text="{singleProject.currentItem.projName}" />
</mx:Repeater>
我实际上要做的是调用中继器中的组件并传递沿着变量,但如果我能实现上述目标,我很确定我可以弄清楚其余的事情。
如果有人能在这里帮助我,我将不胜感激......这样我就可以停止用头撞墙了:(
提前致谢, 亚历克斯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个,看看它是否有效......
Try this and see if it works ...
您可以使用 HTTPService(或类似的方法)加载 XML 数据,然后在加载后使用结果填充列表。
这是一个示例: http ://blog.flexexamples.com/2008/03/29/dynamically-loading-xml-files-using-the-httpservice-tag/
URLLoader 类也是替代 HTTPService 的一个选项。两者的一般方法是相同的。
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.