2 Replies Latest reply on Apr 9, 2009 2:03 PM by K-kOo

    Using contentPane in a custom HBox


      Hi !


      This a question for the flex team i guess or anybody who knows very well the creation live-cycle of a component.


      I'm extending a HBox where i added a Label on the right border which is not a content child. This label is here to show how much child is hidden on the sides when the box is too small to show everything (my scroll policy is off in that component). From what i understand a contentPane is created if (but not only) the size of the container is too small. Then all the children previously added are moved from the container display list to the contentPane one.

      1) So my first question is about the creation of that pane, not the most important though. In the comments we can read that it works like a mask but i can't see where a mask property is actually setted with the pane. Does anyone knows something about it ?


      Next things that i understand are : at the beginning the stage is validating all its children, so my MyBox.validateDisplayList() is called and then it's my overriden updateDisplayList method which is called. My problem is here. If my Box already has too much children into it to being displayed, the contentPane variable is not set yet. That's happenning because the contentPane is created after the call of updateDisplayList (when createContentPaneAndScrollbarsIfNeeded() is called)


      2) And my main question is, how should i do to have my contentPane initialized before the end of my first updateDisplayList() call



        • 1. Re: Using contentPane in a custom HBox
          injpix Level 3

          To answer your first question, the  scrollRect property "masks" the display object.  This property is assigned in the scrollChildren() of the Container class.




               *  Positions the container's content area relative to the viewable area

               *  based on the horizontalScrollPosition and verticalScrollPosition properties.

               *  Content that doesn't appear in the viewable area gets clipped.

               *  This method should be overridden by subclasses that have scrollable

               *  chrome in the content area.


          protected function scrollChildren():void



          contentPane.scrollRect = new Rectangle(x, y, w, h);






          I believe the answer to your second question would be that, Container.validateDisplayList() calls createContentPaneAndScrollbarsIfNeeded() in a conditional and if that returns true, then it will call super.validateDisplayList().  So the contentPane seems to be created *during* validateDisplayList(), if its needed.


          override public function validateDisplayList():void



                // Based on the positions of the children, determine

                // whether a clip mask and scrollbars are needed.

                if (createContentPaneAndScrollbarsIfNeeded())


                     // Redo layout if scrollbars just got created or destroyed (because

                     // now we may have more or less space).

                     if (_autoLayout || forceLayout)


                          doingLayout = true;


                          doingLayout = false;


                     // If a scrollbar was created, that may precipitate the need

                     // for a second scrollbar, so run it a second time.






                if (contentPane)




          • 2. Re: Using contentPane in a custom HBox
            K-kOo Level 1

            Hey thanks for the answers.


            I didn't know about the scrollRect property. That's a useful one


            For my second question sorry but I dont think it's what really happening. You see the first validateDisplayList() before calling createContentPaneAndScrollbarsIfNeeded() ? That one goes to UIComponent.validateDisplayList() where a first call to updateDisplayList is done. That's why it's reaching my custom update function before creating the contentPane.

            But what about the second call to super.validateDisplayList() after a true createContentPaneAndScrollbarsIfNeeded() ? Well too bad for me this function is returning true if scrollbars have been created. Not just a contentPane ! And guess what ? I'm not using scrollbars


            So what trick do you think i might to have my contentPane initialized in my update function. Maybe sould I call my update a second time or something...