2 Replies Latest reply on Mar 24, 2010 11:03 AM by toft

    numChildren bug ? (Flash Builder)

    toft Level 1

      Consider this:

       

      <s:Group  id="mygroup" >

      <s:VGroup>

      </s:VGroup>

      </s:Group>

       

      When tracing mygroup.numChildren I get 0;

       

      Consider this:

       

      <s:Group  id="mygroup" >

      <s:Button>

      </s:Button>

      </s:Group>

       

      When tracing mygroup.numChildren I get 1;

       

      (numElements returns the same results)

       

      How am I supposed to be able to traverse tags independent of what type they are ??

        • 1. Re: numChildren bug ? (Flash Builder)
          Shongrunden Adobe Employee

          To work with elements in a spark container you should use the IVisualElementContainer "element" methods and properties (like addElementAt(), getElement(), numElements, etc.) instead of the "child" operations that mx containers use (like numChildren, addChildAt(), etc.).

           

          ASDoc - http://help.adobe.com/en_US/FlashPlatform//reference/actionscript/3/mx/core/IVisualElement Container.html

           

          This is because spark containers are optimized to use as little DisplayObjects as possible.  We often refer to this as DisplayObject sharing and it is an optimization to make GraphicElements like Rect as light as possible (they don't extend DisplayObject).  Instead of each element in a halo container being a DisplayObject, elements in a spark container are arranged into chains of DisplayObjects.

           

          For example:

           

          <s:Group id="group1">
            <s:Rect />
            <s:Rect />
          </s:Group>

           

          group1.numChildren = 0
          group1.numElements = 2

           

          (All elements are drawn into the Group's DisplayObject)

           

          <s:Group id="group3">
            <s:Rect />
            <s:Rect rotation="45"/>
          </s:Group>

           

          group1.numChildren = 1
          group1.numElements = 2

           

          (The last Rect requires its own DisplayObject and the rest draw into the Group's DO)

           

          <s:Group id="group2">
            <s:Rect rotation="45"/>
            <s:Rect />
          </s:Group>

           

          group1.numChildren = 2
          group1.numElements = 2

           

          (The first rect breaks the chain so a display object is needed for rect1 and rect2 in addition to the Group)

           

          I'll have a blog post on this difference coming on this topic eventually (flexponential.com).

          • 2. Re: numChildren bug ? (Flash Builder)
            toft Level 1

            Thanks Shongrunden

             

            I think I need a bit of time to get used to the new ways to do stuff... nice to get some help from the pros...