Copy link to clipboard
Copied
I'm trying to cycle through everyone of my display objects to find out if it's a component that I can use .validateNow() on. I found code that cycles through all the display objects on my stage, but I have no idea how to tell if the display object is a ui component that has the validateNow() method. My problem comes from when I resize my flash application, components don't render correctly. I can use validateNow on each individual component, but there has to be a way to get all of them quickly. Like if(dsoChild is uicomponent) then dsoChild.validateNow() .
getChildren(this);
function getChildren(dsObject:DisplayObjectContainer, iDepth:int = 0):void
{
var i:int = 0;
var sDummyTabs:String = "";
var dsoChild:DisplayObject;
for (i ; i < iDepth ; i++)
sDummyTabs += "\t";
trace(sDummyTabs + dsObject);
for (i = 0; i < dsObject.numChildren ; ++i)
{
dsoChild = dsObject.getChildAt(i);
if (dsoChild is DisplayObjectContainer && 0 < DisplayObjectContainer(dsoChild).numChildren) {
getChildren(dsoChild as DisplayObjectContainer,++iDepth);
}
else {
trace(sDummyTabs + "\t" + dsoChild);
}
}
}
not all components are ui components but, i think, for you purposes those and the only ones you want to detect.
if so, you can use UIComponent to check for ui components.
i'm not sure about that code because it has a useless for-loop so you should probably use something more reliable like:
import flash.display.DisplayObjectContainer;
import fl.core.UIComponent;
componentF(Sprite(root));
function componentF(dobjC:DisplayObjectContainer):void{
if(dobjC is UIComponent){
UIComponent(dobjC).inva
...Copy link to clipboard
Copied
not all components are ui components but, i think, for you purposes those and the only ones you want to detect.
if so, you can use UIComponent to check for ui components.
i'm not sure about that code because it has a useless for-loop so you should probably use something more reliable like:
import flash.display.DisplayObjectContainer;
import fl.core.UIComponent;
componentF(Sprite(root));
function componentF(dobjC:DisplayObjectContainer):void{
if(dobjC is UIComponent){
UIComponent(dobjC).invalidate();
}
for(var i:int=0;i<dobjC.numChildren;i++){
if(dobjC.getChildAt(i) is DisplayObjectContainer){
componentF(DisplayObjectContainer(dobjC.getChildAt(i)));
}
}
}
p.s. some ui comoponents have child ui components and you probably don't want to invalidate those (if which case you should not check for children of ui components). however, if you apply addChild to a ui component you probably will want to check ui component children. i don't see an easy way to handle both situations concurrently.
Copy link to clipboard
Copied
Worked great. This has been a frustrating problem and you solved it in a few minutes. Thank you very much. Now whenever I change the screen size I call that function and things look great.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now