开发者

flex builder: how to populate an array from an external file of strings

开发者 https://www.devze.com 2022-12-21 21:46 出处:网络
hello i\'m new to flex builder and trying to populate an array from an external file consisting of a list of strings.

hello i'm new to flex builder and trying to populate an array from an external file consisting of a list of strings.

how do i go ab开发者_高级运维out that? should i use some sort of a data object?


Here's an example to get you started:

Sample File (file_with_strings.txt):

one, two, three

Sample App

<?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>

I would just use the HTTPService class to load your external file. You can change the resultFormat to XML, Object, and a few other things if you'd like. Then just customize that updateList() method however.

Hope that helps, Lance

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号