Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Determine if a display object is a component that can use method validateNow()

Community Beginner ,
Jul 21, 2013 Jul 21, 2013

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);

         }

     }

}

TOPICS
ActionScript
726
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 21, 2013 Jul 21, 2013

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

...
Translate
Community Expert ,
Jul 21, 2013 Jul 21, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 21, 2013 Jul 21, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2013 Jul 21, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines