title: AS3/Flex 4: Most Practical Way To Find Nested Children
body: <p>I'm sort of jumping in headfirst to some Flex/AIR stuff.  I have a pretty solid background with AS3, but given the inherent hierarchal complexity of Flex (compared to regular Flash), I'm running into an issue.</p>
  
  <p>Let's assume that you have an app where pretty much everything is event driven (common).  Accessing elements in the near vicinity of the event target, or the event target itself, is trivial.  I'm trying to find, however, the most practical (read: best, most efficient) way to find children that are far removed from the current context.</p>
  
  <p>I know there are functions like <code>getChildAt()</code> and <code>getChildByName()</code>, but that assumes a parent context; what if the element (Flex) you're looking for is several parents up, in a sibling, and then several children down?  We take for granted things like jQuery that do this easily, but obviously we don't have that luxury in AS3.</p>
  
  <p>Are any of the following valid?  Is there a better way?</p>
  
  <ol>
  <li><p>Iterate through parents and parents' parents until you find a stop point, find the sibling, and iterate through children and their children until you find your target;</p></li>
  <li><p>Keep key objects in a global object store (sic) and reference them as necessary (yech)</p></li>
  <li><p>Use specific dot notation to reach the target, including elements (like skins and their containers - yech again)</p></li>
  </ol>
  
  <p>Any thoughts would be appreciated.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>To clarify, let's take an empty Flex 4 AIR app.  We have <code>WindowedApplication</code> as the root, obviously, and let's add two <code>SkinnableContainer</code> children with IDs <code>navContainer</code> and <code>mainContainer</code>, respectively.  Both have custom skins.  Within <code>mainContainer</code>, we have another <code>SkinnableContainer</code> with a vertical layout and ID <code>mainContent</code>, and as one of its children, it has an object (any will do - a spark <code>BorderContainer</code>, maybe) with the ID <code>animatedBox</code>, for example.  Within the <code>navContainer</code>, we have a spark <code>Button</code>, which has a listener bound for <code>MouseEvent.CLICK</code>.  Within that function, we are going to want to access <code>animatedBox</code> (<code>nativeWindow.mainContainer.mainContent.animatedBox</code>) and animate it to change, say, it's width.</p>
  
  <p>The goal is to access that distant <code>DisplayObject</code> (<code>animatedBox</code>) in a way that is as unobtrusive and efficient as possible, while still conforming to Flex standards that I clearly have yet to possess. :)</p>