2010-03-24 36 views
0

我正在從XML向後加載我的MC,並且每頁分隔10個。當它被裝載到舞臺上時,它不能相應地安排到網格上。當我在其他頁面點擊讓它以前加載XML對象之前再跑10,它不添加到陣列中(我已經償清前陣重新加載XML)安排從XML向後調用的MC

private function loadItem():void { 
     commentArray=new Array(); 

     var columns:int=Math.ceil(stage.stageWidth/300); 
     var x_counter:Number=0; 
     var y_counter:Number=0; 


     var firstItem=myXMLList.length()-(currentPage*ItemPerPage); 
     var lastItem=firstItem-ItemPerPage; 

     if (lastItem<=0) { 
      lastItem=0; 
     } 
     //trace("firstItem="+firstItem, "lastItem="+lastItem) 

     for (i=(firstItem-1); i>lastItem; i--) { 
      cBox=new MovieClip(); 

//cbox created from here 
      items(); 
      allcBox.addChild(cBox); 
      commentBox(); 

//moving object to top layers 
       cBox.setChildIndex(cBox.getChildByName("box"+i),0); 

//arranging object in grids 
      for (l; l<ItemPerPage; l++) { 
       commentArray.push(cBox); 
       commentArray[l].x=(200+10)*x_counter; 
       commentArray[l].y=((60)*y_counter); 

       if (x_counter+1<columns) { 
        x_counter++; 
       } else { 
        x_counter=0; 
        y_counter++; 
       } 
      } 
      addChild(allcBox); 
      allcBox.y=-(allcBox.height+50); 
     } 
    } 
//clearing off array to run a new set so could arrange item in grids 

private function clearEverything():void { 
      commentArray.splice(0,commentArray.length); 
      currentPage=pagesArray.indexOf(event.target); 
      loadWishes(); 
    } 

我的猜測在問題可能是2循環哪一個正在使用++和另一個 - ?

回答

0

差不多固定它。儘管XML中的第一個數據似乎沒有顯示出來。可能需要在加載的XML數據上以-1爲基礎作弊。

private function loadWishes():void { 
     commentArray=new Array(); 

     var x_counter:Number=0; 
     var y_counter:Number=0; 


     var firstWishes=myXMLList.length()-(currentPage*wishesPerPage); 
     var lastWishes=firstWishes-wishesPerPage; 


     //start placing object 
     for (i=(firstWishes-1); i>lastWishes-1; i--) { 

      if (lastWishes<=0) { 
       lastWishes=1; 
      } 

      cBox=new MovieClip(); 
      wishes(); 
      //dropShadow.dShadow(sec); 
      //cBox.rotation=(Math.random()*5); 
      allcBox.addChild(cBox); 
      commentBox(); 
      cBox.setChildIndex(cBox.getChildByName("box"+i),0); 

      commentArray.push(cBox); 
      addChild(allcBox); 
     } 


     for (var l:uint=0; l<commentArray.length; l++) { 
      commentArray[l].x=(200+10)*x_counter; 
      commentArray[l].y=((100)*y_counter); 

      if (x_counter+1<columns) { 
       x_counter++; 
      } else { 
       x_counter=0; 
       y_counter++; 
      } 
     } 
     allcBox.y=-(allcBox.height+50); 
    }