Well I found out the trick was to call toc.validateNow(); before making the calls to .expandItem. Also my call did not seem to have enough arguments.
But another question is there any documentation on the .expandItem call? I want to know what all those true values are for.
I also want to make sure I am using it to collapse correctly. I tried all false like this and it works but not sure what it all might be doing toc.expandItem(toc.dataProvider.source,false,false,false,null);
--------
Here is my full code.
toc.validateNow();
var i:int;
for (i = 0; i < toc.dataProvider.source.length; i++)
{
if (toc.dataProvider.source.label == mapStr)
{
toc.expandItem(toc.dataProvider.source,true,true,true,null);
toc.validateNow();
var j:int;
for (j = 0; j < toc.dataProvider.source.children.length; j++)
{
if (toc.dataProvider.source.children.layerInfo.name == grpStr)
{
//toc.expandChildrenOf(toc.dataProvider.source,true);
toc.expandItem(toc.dataProvider.source.children,true,true,true,null);
}
else if (toc.dataProvider.source.children.layerInfo.name == layerStr)
{
toc.expandItem(toc.dataProvider.source.children,true,true,true,null);
}
}
}
else toc.expandItem(toc.dataProvider.source,false,false,false,null);
toc.validateNow();
{
}
}
toc.validateNow();