Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:59:54+00:00 2026-05-25T14:59:54+00:00

So my problem is the selectedIndex isn’t updated when i use nextSlide() and prevSlide(),

  • 0

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?

This is my playlist class

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;
            }
        }
    }
}

This is my mate 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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:59:55+00:00Added an answer on May 25, 2026 at 2:59 pm

    Mate isn’t able to populate your private dispatcher variable with a reference to its event bus, so the event map never “hears” the event you are dispatching on it, and can’t invoke your method.

    This seems like a silly way to invoke a method on the same component, and I think this is a sign that you know that you ought to separate the logic in some way. What I’d suggest is that you have a Presentation Model that contains the dataprovider and selectedIndex, and inject a reference to that. Then, your List will bind to the dataprovider and selectedIndex. The pm can listen for events on the bus to maintain selectedIndex, or you can operate it directly from the View component.

    That way, when you realize it’s a bit problematic to have a List subclass that has buttons in it, you can attach the new Group subclass that has a List and buttons in it without any problem.

    For an example of how to properly inject the event bus (that conveniently shows how to use a PM), check out http://www.developria.com/2010/05/refactoring-with-mate.html. It looks like you’ve got a good start on understanding the event bus, but you might want to get a bit more detail by looking at http://www.developria.com/2010/05/pass-the-eventdispatcher-pleas.html .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have an address field from an Access database which has been converted
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem: Given a list of strings, find the substring which, if subtracted from the
Problem I have timestamped data, which I need to search based on the timestamp
I think the problem was I was writing .innerHtml and overwriting the form elements,
I am currently stuck on a small problem. I have a List View which
I am having a strange problem. There are two ajax calls in the code.
I am getting a problem with these two scripts I coded, it appears as
I'm trying to do a two way binding of the SelectedIndex attribute of a
I need help with the following problem: I have a class with two properties.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.