AS3 ScrollPane number of items
-
25-06-2021 - |
Domanda
everyone.
Can I get a number of items from a ScrollPane component in Flash? If yes, then how?
Thanks in advance.
Soluzione
ScrollPane has one item which is the source parameter. If you want to know all the children within that source (and it's a DisplayObjectContainer), you can use the .numChildren property of the SOURCE.
If you want all the sub-children, you could iterate through all the children until you have you're final number:
var d:DisplayObjectContainer = scrollPane.source;
function countChildren(container:DisplayObjectContainer):int {
var count:int = container.numChildren;
var tmp:DisplayObject;
var i:int = count;
while(i--){
tmp = container.getChildAt(i);
if(tmp is DisplayObjectContainer){
count += countChildren(tmp);
}
}
return count;
}
so call countChildren() with the source of the scrollPane.
if(scrollPane.source is DisplayObjectContainer){
countChildren(DisplayObjectContainer(scrollPane.source));
}
Altri suggerimenti
Should have a numChildren if the objects you're talking about are actual direct descendants of the ScrollPane in question.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow