【发布时间】:2010-02-27 13:23:38
【问题描述】:
你好,我是 flex builder 的新手,我正在尝试从由字符串列表组成的外部文件填充数组。
我该怎么做呢?我应该使用某种数据对象吗?
【问题讨论】:
标签: apache-flex arrays builder populate
你好,我是 flex builder 的新手,我正在尝试从由字符串列表组成的外部文件填充数组。
我该怎么做呢?我应该使用某种数据对象吗?
【问题讨论】:
标签: apache-flex arrays builder populate
下面是一个帮助您入门的示例:
示例文件(file_with_strings.txt):
one, two, three
示例应用
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="initializeHandler()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
protected function initializeHandler():void
{
service.send();
}
protected function updateList(result:Object):void
{
var array:Array = result.split(/,\s+/);
var collection:ArrayCollection = new ArrayCollection(array);
list.dataProvider = collection;
}
]]>
</mx:Script>
<mx:HTTPService id="service"
url="file_with_strings.txt"
resultFormat="text" result="updateList(event.result)"/>
<mx:List id="list"/>
</mx:Application>
我只会使用HTTPService 类来加载您的外部文件。如果您愿意,可以将resultFormat 更改为 XML、Object 和其他一些内容。然后只需自定义 updateList() 方法即可。
希望对您有所帮助, 兰斯
【讨论】: