我如何设置dataProvider为< S:列表>部件是一个XML文件? [英] How do I set the dataProvider for an <s:List> component to be an XML file?

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

问题描述

我已经得到的Adobe Flash Player最新的测试版Builder 4中。

我想用一个< S:列表> 组件,并指定的dataProvider 作为一个XML文件。

不过,研究加载后(包括看文档的链接断开labs.adobe.com),我仍然无法弄清楚如何做到这一点。

中的XML文件看起来是这样的:

 < XML版本=1.0编码=ISO-8859-1&GT?;
<图像列表>
    <图像位置=路径/到/ file1.jpg/>
    <图像位置=路径/到/ file2.jpg/>
    <图像位置=路径/到/ file3.jpg/>
< /图像列表>
 

解决方案

我最初的目的是让外界给我的客户能够保持自己,因此他们必须在显示的图像控制的SWF的XML文件。

我张贴了第一个答案是不完全的解决方案,我是后:使用 FX:XML 意味着XML文件的内容实际上是编译到SWF,并因此是不是编译后可变的。

所以,我实现了詹姆斯的解决方案。

XML文件看起来是这样的:

 < XML版本=1.0编码=ISO-8859-1&GT?;

<图片>
<图像源=路径/到/ image1.jpg/>
<图像源=路径/到/ image2.jpg/>
<图像源=路径/到/ image3.jpg/>
<图像源=路径/到/ image4.jpg/>
< /图片>
 

MXML:

 < XML版本=1.0编码=UTF-8&GT?;

&所述氏:组
的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
XMLNS:S =库://ns.adobe.com/flex/spark
的xmlns:MX =库://ns.adobe.com/flex/halo
>

< FX:脚本>
<![CDATA [
进口mx.events.FlexEvent;

保护功能lstImages_creationCompleteHandler(事件:FlexEvent):无效
{
dpHttpService.send();
}

]]≥

< / FX:脚本>

< FX:声明>

< MX:的HTTPService
的id =dpHttpService
URL =images.xml
/>

< / FX:声明>

< S:列表
的id =lstImages
的dataProvider ={dpHttpService.lastResult.images.image}
宽度=100%
的itemRenderer =path.to.render.ImageRenderer
的skinClass =path.to.skins.ListSkin
>

< S:布局>
&所述氏:Horizo​​ntalLayout间隙=2/>
< / S:布局>

< / S:列表>

< / S:组>
 

和在图像渲染,我指的是数据是这样的:

 < MX:图片
的id =imgRendered
来源={data.source}
/>
 

这个解决方案的真正有用的事情是,我也可以把完整的的http:// 引用其他网站上存在的图像,如果我想(记住的crossdomain.xml ,当然)。

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

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

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

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

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>

解决方案

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.

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.

So I've implemented James' solution.

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}"
/>

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).

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

这篇关于我如何设置dataProvider为&LT; S:列表&gt;部件是一个XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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