2 Replies Latest reply on Oct 28, 2011 11:49 AM by Shongrunden

    Setting selectedIndex on view stack after removal


      I'm having an issue where when I remove an element from a ViewStack its not selecting the previous item in the list. It keeps snapping back to index 0.


      here's some simple code:


      <?xml version="1.0" encoding="utf-8"?>
                                    import spark.components.Label;
                                    import spark.components.NavigatorContent;
                                    private function onCreationComplete():void {
                                              for (var i:int = 0; i < 10; i++) {
                                    private function removeCurrent():void {
                                              var child:NavigatorContent = layouts.selectedChild as NavigatorContent;
                                              if (child) {
                                    private function addNew():void {
                                              var title:String = "item " + layouts.length;
                                              var content:NavigatorContent = new NavigatorContent();
                                              content.label = title;
                                              var label:Label = new Label();
                                              label.text = title;
          <!-- Drop down list to show the view stack, uses double data binding -->
                <s:DropDownList id="dropDown" width="200" labelField="label" dataProvider="{layouts}" selectedIndex="@{layouts.selectedIndex}" />
                <!-- TabBar to show the view stack, uses single data binding -->
                <s:TabBar id="tabBar" width="100%" dataProvider="{layouts}" />
                <!-- Content view stack -->
                <mx:ViewStack id="layouts">
                <!-- Buttons to test -->
                <s:Button label="remove" click="removeCurrent();"/>
                <s:Button label="add" click="addNew();" />


      when you remove the current item, the stack selects item 0. I cannot seem to override this. I want the view stack to select the previous item in the list