Search code examples
flashactionscript-3flash-cs4

retrieving children from parent container of a certain type


is it possible to retrieve all children of a certain type from a parent in actionscript 3? i only see getChildAt,getChildByName, is there a getchild of a certain type like get all childs of object type:Food?


Solution

  • function getChildrenOfType( p_parent:DisplayObjectContainer, p_class:Class ):Array
    {
        var result:Array = [];
        for( var i:0; i < p_parent.numChildren; ++i )
        {
            if( p_parent.getChildAt(i) is p_class )
            {
                result.push( p_parent.getChildAt(i);
            }
        }
    
        return result;
    }
    

    Might need some tweaking, but it would go something like that.