• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

How can I display only a certain numbers of items contain in an Array?

Contributor ,
Jan 20, 2016 Jan 20, 2016

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

TOPICS
Development

Views

249

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 20, 2016 Jan 20, 2016

Copy link to clipboard

Copied

LATEST

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

  }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines