3 Replies Latest reply on Jan 4, 2010 2:32 PM by Flex harUI

    Problems with binding on scrollPosition atribute

    Fredy Gadotti

      Hello,

       

      I'm having a few problems to implement the binding between a Canvas and a List.

      When i scroll vertically the Canvas, the List scrolls, but the items dont render as they should.

      The Canvas have the same size of the List.

       

      I created a quick sample to show what is the problem.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
           layout="absolute"
           backgroundColor="0xFFFFFF"
           creationComplete="addRandomItems()">
           
           <mx:Script>
                <![CDATA[
                     import mx.collections.ArrayCollection;
                     import mx.utils.ObjectUtil;
                     
                     private function addRandomItems():void {
                          var provider:ArrayCollection = new ArrayCollection();
                          
                          for (var i:int = 0; i < 100; i++){
                               var o:Object = new Object();
                               var children:Array = [];
                               var incYear:int = 0;
                               
                               incYear += i % 2 == 0 ? 1 : 0; 
                               
                               o.description = "Teste " + i ;
                               
                               for (var j:int = 0; j < 3; j++){
                                    var xyz:Object = new Object();
                                    
                                    do {
                                         xyz.startDate = new Date(2008 + incYear , Math.random()*10, Math.random()*31);
                                         xyz.endDate = new Date(2008 + incYear, Math.random()*11, Math.random()*31);
                                         xyz.color = Math.random() * 0xFFFFFF;
                                         
                                         if (xyz.startDate.date == 31 && xyz.startDate.month == 11){
                                              xyz.startDate.date++;
                                         }
                                         
                                         if (xyz.endDate.date == 31 && xyz.endDate.month == 11){
                                              xyz.endDate.date++;
                                         }
                                    } while (ObjectUtil.dateCompare(xyz.startDate, xyz.endDate) != -1 );
                                    
                                    children.push(xyz);                              
                               }
                               
                               o.children = children;
                               provider.addItem(o);
                          }
                          descriptionList.dataProvider = provider;
                     }
                ]]>
           </mx:Script>
           
           <mx:List id="descriptionList"
                x="10" 
                y="10" 
                height="738"
                width="300"
                rowHeight="25"
                labelField="description" 
                horizontalScrollPolicy="off" 
                verticalScrollPolicy="off" 
                verticalScrollPosition="{viewer.verticalScrollPosition}"/>
           
           <mx:Canvas id="viewer" x="318" y="10" width="840" height="738">
                <mx:Canvas height="2500" width="2500" />
           </mx:Canvas>
           
           
      </mx:Application>
      

       

       

       

      Regards,

       

      Fredy.