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.
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.
I know there are functions like getChildAt()
and getChildByName()
, 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.
Are any of the following valid? Is there a better way?
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;
Keep key objects in a global object store (sic) and reference them as necessary (yech)
Use specific dot notation to reach the target, including elements (like skins and their containers - yech again)
Any thoughts would be appreciated.
Edit:
To clarify, let's take an empty Flex 4 AIR app. We have WindowedApplication
as the root, obviously, and let's add two SkinnableContainer
children with IDs navContainer
and mainContainer
, respectively. Both have custom skins. Within mainContainer
, we have another SkinnableContainer
with a vertical layout and ID mainContent
, and as one of its children, it has an object (any will do - a spark BorderContainer
, maybe) with the ID animatedBox
, for example. Within the navContainer
, we have a spark Button
, which has a listener bound for MouseEvent.CLICK
. Within that function, we are going to want to access animatedBox
(nativeWindow.mainContainer.mainContent.animatedBox
) and animate it to change, say, it's width.
The goal is to access that distant DisplayObject
(animatedBox
) in a way that is as unobtrusive and efficient as possible, while still conforming to Flex standards that I clearly have yet to possess. :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…