Так что моя проблема в том, что selectedIndex не обновляется, когда я использую nextSlide () и prevSlide (), которые выполняются, когда я нажимаю на две кнопки. SelectedIndex работает, когда я нажимаю на элементы в списке. Что я делаю неправильно? я должен отправить некоторые события? Есть ли уловки, чтобы сделать это с помощью кнопок?
Это мой плейлист класса
public class Playlist extends List
{
private var dispatcher:Dispatcher;
public function Playlist()
{
super();
this.dragEnabled = true;
this.dragMoveEnabled = true;
this.dropEnabled = true;
this.allowMultipleSelection = true;
this.dispatcher = new Dispatcher();
}
public function handleSelection(event:PlaylistEvent):void
{
if (event.type == PlaylistEvent.ITEMS_SELECTED){
selectItem(event.index, event.count);
selectedIndex = event.index;
}
}
private function selectItem(index:Number, count:Number):void
{
var tempArray:Array = this.dataProvider.toArray();
var indiceVector:Vector.<int> = new Vector.<int>();
var itemVector:Vector.<Object> = new Vector.<Object>();
var n:int = 1;
for (var i:int=0;i<tempArray.length;i++){
var item:PlaylistItem = tempArray[i];
if (i<index) deselectItem(item);
else if (i<index+count) {
item.Selected=true;
indiceVector[count-n] = i;
itemVector[count-n++] = item;
}
else deselectItem(item);
}
selectedItems = itemVector;
selectedIndices = indiceVector;
}
private function deselectItem(item:PlaylistItem):void
{
item.Selected = false;
}
public function nextSlide():void
{
if (dataProvider.length == 0) return;
var index:int = selectedIndex;
if (index < 0) {
var event1:PlaylistEvent = new PlaylistEvent(PlaylistEvent.ITEMS_SELECTED, 0, 1);
dispatcher.dispatchEvent(event1);
return;
}
var item:PlaylistItem = PlaylistItem(dataProvider.getItemAt(index));
if (index < dataProvider.length-1) {
trace("going to index", index+1);
var event:PlaylistEvent = new PlaylistEvent(PlaylistEvent.ITEMS_SELECTED, index+1, 1);
dispatcher.dispatchEvent(event);
return;
}
}
public function previousSlide():void
{
if (dataProvider.length == 0) return;
var index:int = selectedIndex;
if (index < 0) {
var event1:PlaylistEvent = new PlaylistEvent(PlaylistEvent.ITEMS_SELECTED, 0, 1);
dispatcher.dispatchEvent(event1);
return;
}
var item:PlaylistItem = PlaylistItem(dataProvider.getItemAt(index));
if (index > 0) {
var event:PlaylistEvent = new PlaylistEvent(PlaylistEvent.ITEMS_SELECTED, index-1, 1);
dispatcher.dispatchEvent(event);
return;
}
}
}
}
Это мой друг EventMap
<?xml version="1.0" encoding="utf-8"?>
<mate:EventMap xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mate="http://mate.asfusion.com/"
xmlns:air="de.websector.mate.extensions.air.*">
<fx:Script>
<![CDATA[
import components.Playlist;
import events.PlaylistEvent;
import mx.controls.Alert;
import mx.events.*;
import mx.logging.*;
import mx.logging.Log;
import spark.components.Application;
private var logger:ILogger;
private function initLogger():void{
logger = Log.getLogger("MainEventMap");
trace("started init maineventmap");
}
]]>
</fx:Script>
<fx:Declarations>
<mate:EventHandlers type="{FlexEvent.APPLICATION_COMPLETE}">
<mate:InlineInvoker method="initLogger"/>
<mate:ObjectBuilder generator="{MainManager}"/>
<mate:EventAnnouncer type="{InitEvent.SYSTEM_INIT_COMPLETE}" />
</mate:EventHandlers>
<mate:Injectors target="{Playlist}">
<mate:PropertyInjector targetKey="dataProvider" source="{MainManager}" sourceKey="playlistItems" />
</mate:Injectors>
<mate:Injectors target="{MainManager}">
<mate:PropertyInjector targetKey="playlist" source="{Playlist}" />
</mate:Injectors>
<!-- Playlist events! __________________________________________________________________________________________________-->
<mate:EventHandlers type="{PlaylistEvent.ITEMS_SELECTED}">
<mate:MethodInvoker generator="{Playlist}" method="handleSelection" arguments="{event}" />
</mate:EventHandlers>
</fx:Declarations>
</mate:EventMap>