リスト用のカスタム LabelItemRenderer があり、セット データ関数をオーバーライドしています。各データには、true または false のプロパティ「sales」があります。このプロパティに依存して、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)
}
}
}
}