Avoid swapChildren and swapChildrenAt
Simply googling for the phrase 'flex RangeError swapChildrenAt' returns enough reason to follow this advice. Here's some pseudo-code that does work for swapping the depth of two children, A and B:
  1. A needs to be at a depth above B. If not, then switch references to A and B in the following points.
  2. Remember the depths of A and B
  3. Remove A
  4. Remove B
  5. Add A to the level where B was
  6. Add B to the level where A was
As a side note: If you're removing these children from inside either A or B, you'll want to keep a reference to the parent in a local variable since you'll lose it as soon as you remove A and B.