Note that there are some explanatory texts on larger screens.

plurals
  1. POSpark List SelectedIndex doesn't update
    text
    copied!<p>So my problem is the selectedIndex isn't updated when i use nextSlide() and prevSlide(), which are executed when i click on two buttons. SelectedIndex works when i click on the elements in the List. What am i doing wrong? do i have to dispatch some events? Are there any tricks to doing it with buttons?</p> <p>This is my playlist class</p> <pre><code>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.&lt;int&gt; = new Vector.&lt;int&gt;(); var itemVector:Vector.&lt;Object&gt; = new Vector.&lt;Object&gt;(); var n:int = 1; for (var i:int=0;i&lt;tempArray.length;i++){ var item:PlaylistItem = tempArray[i]; if (i&lt;index) deselectItem(item); else if (i&lt;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 &lt; 0) { var event1:PlaylistEvent = new PlaylistEvent(PlaylistEvent.ITEMS_SELECTED, 0, 1); dispatcher.dispatchEvent(event1); return; } var item:PlaylistItem = PlaylistItem(dataProvider.getItemAt(index)); if (index &lt; 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 &lt; 0) { var event1:PlaylistEvent = new PlaylistEvent(PlaylistEvent.ITEMS_SELECTED, 0, 1); dispatcher.dispatchEvent(event1); return; } var item:PlaylistItem = PlaylistItem(dataProvider.getItemAt(index)); if (index &gt; 0) { var event:PlaylistEvent = new PlaylistEvent(PlaylistEvent.ITEMS_SELECTED, index-1, 1); dispatcher.dispatchEvent(event); return; } } } } </code></pre> <p>This is my mate EventMap</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mate:EventMap xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mate="http://mate.asfusion.com/" xmlns:air="de.websector.mate.extensions.air.*"&gt; &lt;fx:Script&gt; &lt;![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"); } ]]&gt; &lt;/fx:Script&gt; &lt;fx:Declarations&gt; &lt;mate:EventHandlers type="{FlexEvent.APPLICATION_COMPLETE}"&gt; &lt;mate:InlineInvoker method="initLogger"/&gt; &lt;mate:ObjectBuilder generator="{MainManager}"/&gt; &lt;mate:EventAnnouncer type="{InitEvent.SYSTEM_INIT_COMPLETE}" /&gt; &lt;/mate:EventHandlers&gt; &lt;mate:Injectors target="{Playlist}"&gt; &lt;mate:PropertyInjector targetKey="dataProvider" source="{MainManager}" sourceKey="playlistItems" /&gt; &lt;/mate:Injectors&gt; &lt;mate:Injectors target="{MainManager}"&gt; &lt;mate:PropertyInjector targetKey="playlist" source="{Playlist}" /&gt; &lt;/mate:Injectors&gt; &lt;!-- Playlist events! __________________________________________________________________________________________________--&gt; &lt;mate:EventHandlers type="{PlaylistEvent.ITEMS_SELECTED}"&gt; &lt;mate:MethodInvoker generator="{Playlist}" method="handleSelection" arguments="{event}" /&gt; &lt;/mate:EventHandlers&gt; &lt;/fx:Declarations&gt; &lt;/mate:EventMap&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload