I haven’t actually looked into Flash Panels, as we’re on CS3 at work, which as far as I understand doesn’t have proper support for such.
Ryan, cheers, every little bit of savings helps. That’s similar to how I usually cache transform lookups, for example, in Unity.
As for the above, I facepalmed when I finally realised what the problem was: I needed to explicitly declare the variables in my function (var tempLayers), otherwise the value was getting overwritten when it recursed. Silly mistake on my part.