0 Replies Latest reply on Jul 7, 2011 12:42 AM by huangxinghui

    Container IndexChangedEvent problem

    huangxinghui

      i am using sdk3.5

       

      The container when set borderStyle="solid" and borderThickness="1",

       

      then invoke setChildIndex function, it will dispatch IndexChangedEvent, but the property oldIndex and newIndex are zero.

       

      because the contentPane is not null, so it does not handle the oldIndex and newIndex value

       

      now, my solution is set borderThickness="0", then it does work.

       

      part of Container.as Source Code:

       

      override public function setChildIndex(child:DisplayObject, newIndex:int):void
          {
              var oldIndex:int;
              var eventOldIndex:int = oldIndex;
              var eventNewIndex:int = newIndex;
              if (contentPane) // it does not handle the oldIndex and newIndex value, so they are always zero.
              {
                  contentPane.setChildIndex(child, newIndex);
                  if (_autoLayout || forceLayout)
                      invalidateDisplayList();
              }
              else
              {
                  oldIndex = super.getChildIndex(child);
                  // Offset the index, to leave room for skins before the list of children
                  newIndex += _firstChildIndex;
                  if (newIndex == oldIndex)
                      return;
                  // Change the child's index, shifting around other children to make room
                  super.setChildIndex(child, newIndex);
                  invalidateDisplayList();
                  
                  eventOldIndex = oldIndex - _firstChildIndex;
                  eventNewIndex = newIndex - _firstChildIndex;
              }
              // Notify others that the child index has changed
              var event:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHILD_INDEX_CHANGE);
              event.relatedObject = child;
              event.oldIndex = eventOldIndex;
              event.newIndex = eventNewIndex;
              dispatchEvent(event);
              dispatchEvent(new Event("childrenChanged"));
          }
      

       

      why not handle when contentPane is exists?

       

      Thanks for any help.

      Huang.