开发者

Arranging MC that is called from XML backwards

I'm loading my MC from XML backwards, and its separated by 10 per pages. When it's loaded to the stage it could not be arrange accordingly to grids. And when I click at other pages to let it run another 10 before the previous loaded XML object, it does not add in to the Array(I've clear off the array before reload the XML)

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开发者_JAVA技巧

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

my guess on the problem might be the 2 loop which 1 is using ++ and the other -- ?


nearly fixed it. though the 1st data in XML doesn't seems to be showing. Maybe need to cheat around the amount by -1 at the XML data that is loaded.

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);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜