6 Replies Latest reply on Mar 28, 2011 1:21 AM by EvyatarBH

    List layout issue

    Benoitcn Level 1

      I create one layout. I use it to a list component. But there's an null reference error occured.

      I have no ideas how to sovle this. Please give some suggestions.

           <s:List id="list" labelField="label" selectedIndex="0"
                     width="100%" height="100%" >
                <s:layout>
                     <!--<local:WheelLayout gap="130" axisAngle="0"/>-->
                     <local:circleLayout />
                </s:layout>
                <s:dataProvider>
                     <mx:ArrayCollection>
                          <fx:Object label="Horizontal CoverFlow"/>
                          <fx:Object label="Vertical CoverFlow"/>
                          <fx:Object label="Carousel"/>
                          <fx:Object label="Awesome"/>
                          <fx:Object label="Spiral"/>
                          <fx:Object label="Time Machine"/>
                     </mx:ArrayCollection>
                </s:dataProvider>
           </s:List>
      
      this custom list layout:
      
                override public function updateDisplayList(width:Number, height:Number):void{
                     super.updateDisplayList(width,height);
                     //make sure that target i.e container which is using this layout, is not null
                     if (!target)
                          return;
                     //get the reference of target container which is using this layout
                     var targetContainer:GroupBase = target;
                     //get the count of elements
                     var childsCount:int = targetContainer.numElements;
                     var arr:Array = caluPositions(width, height, childsCount);
                     
                     for(var i:int = 0; i< childsCount; i++)
                     {
                          //get the current element
                          //NOTE: ILayoutElement interface is used primarily by the layout
                          //classes to query, size and position the elements of the GroupBase based containers.
                          var currentElement:ILayoutElement = targetContainer.getElementAt(i);
                          //use setLayoutBoundsSize method and pass NAN values, so that the element
                          //will bet get drawn with its prefered height and width
                          currentElement.setLayoutBoundsSize(NaN,NaN);
                          //now position the element as you want
      //                    var x:Number = arr[i].x - 50
                          currentElement.setLayoutBoundsPosition(arr[i].x-20, arr[i].y+30);
                     }
                }