Flash/TileList 组件

发布于 2024-07-12 01:12:48 字数 125 浏览 11 评论 0原文

我有问题,希望有人可以帮助我
我有一个包含 TileList 的 Flash 项目
我需要将此 TileList 中的某些项目(不是全部)的背景更改为红色,一些更改为蓝色
你知道该怎么做吗?
谢谢

I have a problem and I hope that someone can help me
I hava Flash project with TileList in it
I need to change background of some items (not all) in this TileList to red and some to blue
Do you know how to do this?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱没勇气 2024-07-19 01:12:48

嗯,棘手的一个。

我试图以一种干净的方式解决这个问题,但 Flash 不允许我这么容易做到。
基本思想是设置 upSkin 样式< /a>,或每个 itemRenderer(ImageCell) 的任何其他必要的皮肤,而不是全部(就像tileList.setRendererStyle());

我以为我可以轻松访问 ImageCell 类(TileList 的默认 Cell 渲染器),但事实并非如此。 我访问 cellRenderer itemToCellRenderer 的唯一方法 方法,但作为参数传递的项目来自 ListEvent

我修改了文档中的示例来说明这个想法。
此代码假设您有 TileList 组件,以及库中具有以下链接的三个 MovieClips 元件:Star、BlueBg、RedBg
导入 fl.controls.;
导入 fl.controls.listClasses.
;
导入 fl.data.;
导入 fl.events.
;

var totalEntries:uint = 20;
var myTileList:TileList = new TileList();
myTileList.columnWidth = 125;
myTileList.rowHeight = 150;
myTileList.columnCount = 3;
myTileList.rowCount = 1;
myTileList.move(10,10);
addChild(myTileList);

for(var i:int=0; i<totalEntries; i++) {
    myTileList.addItem( { label:"star"+i, source:Star, scaleContent:false, index:i} ); 
}

myTileList.addEventListener(ListEvent.ITEM_ROLL_OVER, listItemOver);
function listItemOver(e:ListEvent):void {
    var imageCell:ImageCell = myTileList.itemToCellRenderer(e.item) as ImageCell;
    //e.index % 2 == 0 ? imageCell.setStyle('upSkin',BlueBg): imageCell.setStyle('upSkin',RedBg);
}

即使它有效,也会变得混乱。 我在分派 ITEM_ROLL_OVER 事件时遇到问题,而且我认为在填充组件时分派大量事件(仅针对某些颜色)是一个好主意。

Sooo...Flash 中仍然存在两件事:

  1. 几乎没有人想要 Flash 组件中的默认行为。 每个人都想要一点
    定制一些东西。
  2. 我猜想,Flash 的“魔力”在于找到“hacky”解决方案。

这对我有用:
请注意,当我添加一个项目时,我还添加了索引属性,因此每个项目都会知道它的索引是什么。 接下来,我让每个单元格的内容决定要显示的正确皮肤(这会创建依赖关系,因此应该有一种清晰的方法),因此我在 Star MovieClip 中添加了以下代码,

import fl.controls.listClasses.ImageCell;

var cell:ImageCell = this.parent.parent.parent as ImageCell;
trace(cell.data.index);
if(cell.data.index %2 == 0) cell.setStyle('upSkin',BlueBg);
else cell.setStyle('upSkin',RedBg);

希望这会有所帮助。

Hmmm, tricky one.

I tried to solve this in a clean way, but Flash wouldn't allow me to so easily.
The basic idea is to set a upSkin style, or any other necesary skin for each itemRenderer(ImageCell) instead of all of them (as would tileList.setRendererStyle());

I thought that I could access the ImageCell class ( the default Cell Renderer for TileList) easily, but it's not the case. The only way I gained access to the cellRenderer itemToCellRenderer method, but the item passed as an argument comes from a ListEvent

I've modified the Example that comes in the documentation to illustrate the idea.
This code assumes you have the TileList Component, plus three MovieClips symbols with the following linkages in the Library: Star, BlueBg, RedBg
import fl.controls.;
import fl.controls.listClasses.
;
import fl.data.;
import fl.events.
;

var totalEntries:uint = 20;
var myTileList:TileList = new TileList();
myTileList.columnWidth = 125;
myTileList.rowHeight = 150;
myTileList.columnCount = 3;
myTileList.rowCount = 1;
myTileList.move(10,10);
addChild(myTileList);

for(var i:int=0; i<totalEntries; i++) {
    myTileList.addItem( { label:"star"+i, source:Star, scaleContent:false, index:i} ); 
}

myTileList.addEventListener(ListEvent.ITEM_ROLL_OVER, listItemOver);
function listItemOver(e:ListEvent):void {
    var imageCell:ImageCell = myTileList.itemToCellRenderer(e.item) as ImageCell;
    //e.index % 2 == 0 ? imageCell.setStyle('upSkin',BlueBg): imageCell.setStyle('upSkin',RedBg);
}

This would get messy even if it would work. I has issues when dispatching ITEM_ROLL_OVER events, plus I don't think dispatching a ton of events when the component get populated, just for some colors is such a good idea.

Sooo...there 2 things that remain true in Flash

  1. Almost no one wants the default behavior in Flash components. Everyone wants a little
    custom something.
  2. The 'magic' in Flash stands in finding 'hacky' solutions I guess.

here's what worked for me:
Notice that when I add an item, I also add and index property, so each item would know what's it's index. Next, I'm letting the content for each cell decide what's the right skin to display( which creates dependencies, so there should be a clenear way for this one) so I've added the following code in the Star MovieClip

import fl.controls.listClasses.ImageCell;

var cell:ImageCell = this.parent.parent.parent as ImageCell;
trace(cell.data.index);
if(cell.data.index %2 == 0) cell.setStyle('upSkin',BlueBg);
else cell.setStyle('upSkin',RedBg);

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文