As the title suggests, what is the runtime complexity (eg, big-O) of the Sprite.contains method?
A:
According to the documentation, it's available in any version of Flash Player 9. Have you seen something to indicate otherwise?
matthew
2010-06-29 19:43:37
Err, sorry, I was thinking about the algorithmic-complexity-runtime, not the Flash-Player-version-runtime. I can see the confusion, though.
David Wolever
2010-06-29 20:55:07
A:
I don't have an authoritative answer, but anything other than O(n) would surprise me. It should be a simple walk down the display list, with a simple pointer comparison at each stop.
Should be fast, but it would probably be even faster (depending on the actual display list) to query possible childs parent atribute (with recursion up the parent chain up to to the display list root node) and look if the potential parent sprite is there.
Sprite.getChildByName() is a decidedly worse alternative.
jpop
2010-07-01 13:04:50