tags:

views:

621

answers:

2

Is there a way to access the DOM-Elements of a mxml file in a way that you can in JS (e.g. using Prototype or jQuery)?

I need to know if a top-level element has a child (sub-sub-...-childs) with a certain id.

In JS (using prototype) it would be something like:

$('tabs').select('[id="something"]');

Any ideas?

A: 

You can recursively search through the structure. Something like this (Might not be the most efficient in your case):

private function hasChild(node:UIComponent, target:String):Boolean
{
    if(node.id == target) 
    {
        return true;
    }
    else
    {
        var hasTarget:Boolean = false;
        for(var i:int = 0; i < node.numChildren; i++)
        {
            hasTarget = hasTarget || hasChild(node.getChildAt(i));
        }
       return hasTarget;
    }
}
CookieOfFortune
+2  A: 

Depending on what you're trying to do, Bifff might be the answer. Think of it as "JQuery for Flex": http://wiki.github.com/seanhess/bifff

Sophistifunk