以下のコードでは、presentedAlbumIndex を使用して TileList の selectedIndex を制御しています。項目「5」が最初に選択されています。ボタンが押されるたびに、配列の最初の項目が削除され、presentedAlbumIndex が減分されます。
理論的には、選択されたインデックスは、ボタンがクリックされるたびに ("five" 自体が削除されるまで) "five" のままである必要があります。最初にボタンを押すと、このように機能します。ただし、2番目のボタンを押すと、何らかの理由で強調表示が「6」に変わります。また、TileList selectedIndex は常に 1 つ遅れます。
なんで?
ListBase を調べて selectedIndex を監視してみました。selectedIndexは最初は正しいインデックスに更新されているように見えますが、その後、ある時点で正しいインデックス + 1 に戻ります。なぜ後退しているのかはわかりません。
同じ操作でデータプロバイダーの削除とインデックスの変更を行っていることが原因のようです。
selectedIndex を最新の状態に保つためにオーバーライドできる TileList の関数はありますか?
スティーブ
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
applicationComplete="init()">
<mx:Label id="label1" text="{'TileList selected index: ' + albumsThumbnailList.selectedIndex}"
x="255" y="55" width="234"/>
<mx:Label id="label2" text="{'Presented album index: ' + presentedAlbumIndex}" x="255" y="81" width="234"/>
<mx:TileList id="albumsThumbnailList" direction="vertical"
dataProvider="{presentedAlbums}"
selectedIndex="{presentedAlbumIndex}" x="25" y="13"
change="presentedAlbumIndex=albumsThumbnailList.selectedIndex"
height="400"/>
<mx:Button click="test2()" x="297" y="150"/>
<mx:Script>
<![CDATA[
import mx.events.CollectionEvent;
import mx.collections.ArrayCollection;
private var _includedAlbums:ArrayCollection = new
ArrayCollection(["zero","one","two","three","four","five","six","seven"]);
[Bindable]
private var presentedAlbumIndex:int = 5;
private function init():void {
_includedAlbums.addEventListener(CollectionEvent.COLLECTION_CHANGE,
function():void {
dispatchEvent(new Event("albumDataChanged"));
}
);
}
public function test2():void {
_includedAlbums.removeItemAt(0);
presentedAlbumIndex--;
}
[Bindable(event="albumDataChanged")]
public function get presentedAlbums():ArrayCollection {
return _includedAlbums;
}
]]>
</mx:Script>
</mx:Application>