Copy link to clipboard
Copied
I've got this code in AS3
var products:Array;
var list:Sprite = new Sprite();
function complete(e:Event):void {
addChild(list); products = JSON.parse(loader5.data) as Array;
for(var i:int = 0, l:int = products.length - 1; l >= 0; i++, l--){
createListItem(i, products
); if(products.length >=10){
next.visible=true; }
}
showList();
}
It displays a list of all the products contains in my table database.
Now I added if(products.length >=10){
and it's working.
I would like to add :
if(products.length >=10){
What shoud I put here for showing only 10 products.
next.visible=true;
next.addEventListener(MouseEvent.CLICK, show10Next);
}
function show10Next(event:MouseEvent){
What should I put here for showing the 10 next products ?
}
I've tried createListItem(i, products[10]); but it's showing me the product number 10 x times. How can I tell the code to show me the 10 first products only ?
Thx
Copy link to clipboard
Copied
Hi, you can do something like this
// keep a page variable
var page:int = 1;
function show10Next(event:MouseEvent):void
{
// you must add a check to not go after the last page
var start:int = ++page * 10;
var stop:int = start + 10;
var l:int;
for( var i:int = start; i<stop; ++i )
{
l = products.length - i;
createListItem( i, products
}
}