Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Later
-
Adobe Flex SDK Previous
-
None
-
None
-
Affected OS(s): All OS Platforms
Affected OS(s): All OS Platforms
Language Found: English
Description
setElementIndex() calls removeElement() followed by addElementAt(). For display objects added with ActionScript, this ultimately removes the child from the display list and adds it again. This seems like a very heavy implementation, and it could probably be optimized so that a display object stays on the display list and is simply reordered with other children.
Ryan Frishberg explains the reasoning for this implementation below, and agrees that it could be optimized better:
setElementIndex() is only implemented in that way to save implementation time. Removing then adding the components is definitely not ideal when calling setElementIndex (or swapElements()). This is something that would be good for us to go back and optimize.
It won't be as easy as just calling setChildIndex because not all visual elements are DisplayObjects, and Group does a lot behind the scenes around managing children's display object order to deal with graphic elements and the depth property. Because it's pretty complex, that's why we decided to just take the performance hit (and the slighly odd API hit with dispatching add/remove events) because it's a lot easier to implement using a remove() and then an add(). As you pointed out, it's not a great solution, so it'd be a great thing for us to do a better job of.