我有用于列表的自定义 LabelItemRenderer,并覆盖集数据功能。在每个数据中,我都有属性“销售”,可以是真假。取决于此属性,我m adding icon. Everything seems fine until i
将向上滚动列表几次。对于设置为 false 的列表索引,销售额为 true。我检查了我的数据提供者并找不到错误,但是在我的自定义项目中呈现数据是错误的并且图标显示在错误的位置。
这是我的代码:
package components {
import flash.display.Bitmap;
import spark.components.LabelItemRenderer;
import spark.components.supportClasses.StyleableTextField;
import spark.primitives.BitmapImage;
public class StoresList extends LabelItemRenderer {
private var storeName:StyleableTextField;
private var floor:StyleableTextField;
private var mapListIco:Bitmap;
private var promotions:Bitmap;
private var sales:Boolean;
private var compData:Object;
public function StoresList() {
super();
}
override public function set data(value:Object):void {
compData = value;
storeName.text = compData.title;
floor.text = 'floor : ' + compData.floor;
if (compData.sales && compData.salesIco) {
promotions = compData.salesIco;
addChild(promotions);
}
}
private function createStoreName():void {
storeName = StyleableTextField(createInFontContext(StyleableTextField));
storeName.editable = false;
storeName.selectable = false;
storeName.multiline = false;
storeName.wordWrap = false;
storeName.styleDeclaration = styleManager.getStyleDeclaration(".titleStyleName");
addChild(storeName);
}
private function createFloortextField():void {
floor = StyleableTextField(createInFontContext(StyleableTextField));
floor.editable = false;
floor.selectable = false;
floor.multiline = false;
floor.wordWrap = false;
floor.styleDeclaration = styleManager.getStyleDeclaration(".floor");
addChild(floor);
}
override protected function createChildren():void {
// store name
createStoreName();
// floor
createFloortextField();
// maplist ico
mapListIco = new Textures.mapListIco160;
addChild(mapListIco);
}
override protected function measure():void {
measuredWidth = getElementPreferredWidth(storeName) + getElementPreferredWidth(floor);
// We only care about the "real" ascent
measuredHeight = getElementPreferredHeight(storeName) + getElementPreferredHeight(floor);
}
override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void {
super.drawBackground(unscaledWidth, unscaledHeight);
}
override protected function layoutContents(unscaledWidth:Number, unscaledHeight:Number):void {
// store name
var gap:Number = Math.round(unscaledHeight * .1);
var storeNameHeight:Number = getElementPreferredHeight(storeName);
var floorHeight:Number = getElementPreferredHeight(storeName);
var storenameY:Number = Math.round( (unscaledHeight - (storeNameHeight + floorHeight + gap) ) * .5 );
setElementSize(storeName, storeName.textWidth, storeName.textHeight);
setElementPosition(storeName, unscaledWidth * .15, storenameY);
// floor
var floorY:Number = Math.round(storenameY + storeNameHeight);
setElementPosition(floor, unscaledWidth * .15, floorY + gap);
// map list
setElementPosition(mapListIco, unscaledWidth - mapListIco.width - unscaledWidth * .05, (unscaledHeight - mapListIco.height) * .5);
// promotions
if (promotions) {
setElementPosition(promotions,
(unscaledWidth * .15 - getElementPreferredWidth(promotions)) * .5,
(unscaledHeight - getElementPreferredHeight(promotions)) * .5)
}
}
}
}