如何为 <s:List> 设置 dataProvider组件是一个 XML 文件? [英] How do I set the dataProvider for an &lt;s:List&gt; component to be an XML file?

查看:16
本文介绍了如何为 <s:List> 设置 dataProvider组件是一个 XML 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有最新的 Adob​​e Flash Builder 4 测试版.

I've got the latest Beta of Adobe Flash Builder 4.

我想使用 组件,并将 dataProvider 指定为 XML 文件.

I want to use a <s:List> component, and specify the dataProvider as being an XML file.

但是,经过大量研究(包括查看 labs.adobe.com 上的文档链接),我仍然不知道该怎么做.

However, after loads of research (including looking at doc links off labs.adobe.com), I still can't figure out how to do it.

XML 文件将如下所示:

The XML file will look something like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<imageList>
    <image location="path/to/file1.jpg" />
    <image location="path/to/file2.jpg" />
    <image location="path/to/file3.jpg" />
</imageList>

推荐答案

我最初的目标是拥有一个位于 SWF 外部的 XML 文件,我的客户可以自行维护,这样他们就可以控制显示的图像.

My original aim was to have an XML file external to the SWF that my client could maintain themselves, and thus they would have control over the images displayed.

我发布的第一个答案并不是我想要的解决方案:使用 fx:XML 意味着 XML 文件的内容实际上已编译到 SWF 中,因此在编译后不可更改.

The first answer I posted was not quite the solution I was after: using fx:XML means that the contents of the XML file is actually compiled into the SWF, and hence is not alterable after compilation.

所以我已经实施了 James 的解决方案.

So I've implemented James' solution.

XML 文件如下所示:

The XML file looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>

<images>
    <image source="path/to/image1.jpg" />
    <image source="path/to/image2.jpg" />
    <image source="path/to/image3.jpg" />
    <image source="path/to/image4.jpg" />
</images>

MXML:

<?xml version="1.0" encoding="utf-8"?>

<s:Group
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/halo"
    >

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function lstImages_creationCompleteHandler(event : FlexEvent) : void
            {
                dpHttpService.send();
            }

        ]]>

    </fx:Script>

    <fx:Declarations>

        <mx:HTTPService
            id="dpHttpService"
            url="images.xml"
        />

    </fx:Declarations>

    <s:List
        id="lstImages"
        dataProvider="{dpHttpService.lastResult.images.image}"
        width="100%"
        itemRenderer="path.to.render.ImageRenderer"
        skinClass="path.to.skins.ListSkin"
        >

        <s:layout>
            <s:HorizontalLayout gap="2" />
        </s:layout>

    </s:List>

</s:Group>

而在图像渲染器中,我是这样引用数据的:

And in the image renderer, I refer to the data like this:

<mx:Image
    id="imgRendered"
    source="{data.source}"
/>

这个解决方案的真正有用之处在于,如果我愿意,我还可以将完整的 http:// 引用放在另一个站点上存在的图像(记住 crossdomain.xml,当然).

The really useful thing about this solution is that I can also put full http:// references to images that exist on another site if I want to (remembering crossdomain.xml, of course).

事实上,images.xml 文件可以存在于另一台服务器上.

In fact, the images.xml file can exist on another server.

这篇关于如何为 <s:List> 设置 dataProvider组件是一个 XML 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆