Differences between IVisualElement.parent and IVisualElement.owner
The IVisualElement interface has both a parent and owner property defined on it. These can both be used to traverse up the display hierarchy, but there are some key differences to be aware of when working with either one.
The full spec for the different trees in a spark application is posted on the open source site. It goes into a great amount of detail and includes lots of pretty graphics (it’s a little stale so you’ll see some old references to the Fx prefix components). It can be a lot to chew on so I thought I would put up a slightly more interactive example that demonstrates one main difference.
The following sample application has two columns: the first column is to examine nested Groups, the second nested SkinnableContainers. If you click on the “climb owner” button for either column it will start at the “Start IVisualElement” button and recursively print each owner on the way up to the application. Notice that the output is essentially the same when climbing through Groups or SkinnableContainers.
If you click on the “climb parent” button for either column you will get very different results. The parent property will reference every container on the way to the application including the skin of SkinnableContainers and any extra Groups inside of that skin. Take for example the output of “climb parent” on the right column: going from skinnableContainer30 to skinnableContainer20 it goes through the contentGroup and SkinnableComponentSkin of skinnableContainer30 before reaching skinnableContainer20.
Most of the time you probably want to use the owner property. If you want more details I recommend reading the spec above and glancing at the ASDoc for the IVisualElement.parent and IVisualElement.owner properties.
Note: This sample requires Flex SDK 4.0.0.12093 or higher. You can get the latest SDK builds from opensource.adobe.com.
Interesting! Thanks for the post. I think I’ll be using the ‘owner’ property to climb the DisplayList from now on, since it seems it filters out a lot of unnecessary things such as skins etc.