views:

24

answers:

2

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
Err, sorry, I was thinking about the algorithmic-complexity-runtime, not the Flash-Player-version-runtime. I can see the confusion, though.
David Wolever
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