Flex - 第一个项目作为按钮,所有其他项目作为图像的图块列表
我需要帮助 我需要一个 TileList,其第一个位置/项目有一个按钮,并且在所有其他项目中每个项目都有一个图像。 好吧,在遇到 Plastic 主题和 s:List 问题(滚动条列表的问题)之后,我放弃了并开始使用 TileList。 我正在为 TileList 使用自定义项目渲染器。这很简单,但我认为我做错了什么。
ArrayCollection 中 TileList 的 dataProvider 由 String 类第一项组成,所有其他项都是扩展 Image 类的自定义类。 喜欢: arr=["bt",图片,图片.....];
我不知道为什么,但我的 TileList 在第一个项目中显示正确的按钮,但之后它显示更多 2 个项目图像,然后第四个项目具有正确的图像但带有按钮,它是一个图案......在 3 个正确的项目之后,下一个项目带有一个按钮......
我的自定义 ItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center"
verticalAlign="middle"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Button;
protected function init():void
{
if(this.data == "bt")
{
var bt:Button = new Button();
bt.id = "btEnviar";
bt.width=84;
bt.height=28;
bt.label = "Enviar Fotos";
addElement(bt);
}
}
]]>
</mx:Script>
<mx:Image id="img" source = "{data}"/>
如果有人可以提供帮助,我真的很感激...我在互联网上没有找到任何相关信息。
谢谢!
i need help with something
I need a TileList that have in its first position/item a button and in all other items a image for each.
Well, after having problems with Plastic theme and s:List (a problem with the scroller s List) i gave up and started working with TileList.
I am using a custom item Renderer for the TileList. It is pretty simple but i think I'm doing something wrong.
The dataProvider for the TileList in an ArrayCollection composed by a String class first item, and all others are a custom class that extends Image Class.
like:
arr=["bt",Image,Image.....];
I don't no why but my TileList display the correct button in its first item, but after that it displays more 2 item images, then a fourth item with the right image but with a button, and it is a pattern....after 3 right items the next comes with a button....
my custom ItemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center"
verticalAlign="middle"
creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.Button;
protected function init():void
{
if(this.data == "bt")
{
var bt:Button = new Button();
bt.id = "btEnviar";
bt.width=84;
bt.height=28;
bt.label = "Enviar Fotos";
addElement(bt);
}
}
]]>
</mx:Script>
<mx:Image id="img" source = "{data}"/>
i really appreciate if someone could help...i didn't found nothing about it on the internet.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎是虚拟布局问题。这意味着渲染器被重用。如果它们没有重新初始化(例如:删除您的 bt 元素),可能会发生这样的事情。另外,我建议您重写 public function data(value:Object):void 并将代码放在那里。如果您确实愿意,您还可以禁用虚拟布局(在数据组/列表上使用VirtualLayout = false)。
我目前没有太多时间来解释它,但我建议您查看 DataGroup 的 itemRendererFunction 属性。此函数返回一个 ClassFactory,定义根据数据使用的项目渲染器的类型。
以下是来自 Adobe 参考资料的链接:使用项目渲染器 。请参阅“将项目渲染器函数与 Spark 容器结合使用”部分。
Seems like a virtual layout issue. This means renderer are reused. If they are not reinitialised (ex : remove your bt element) things like this can happen. Also, I suggest you override public function data(value:Object):void and put your code in there. You can also disable virtual layout if you really want to (useVirtualLayout = false on your DataGroup/List).
I don't have much time to explain it at the moment, but I suggest you look into the itemRendererFunction property of a DataGroup. This function returns a ClassFactory defining the type of item renderer to use depending on the data.
Here's a link on this from Adobe references : Working with item renderers. See the "Using an item renderer function with a Spark container" section.