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[l]);
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 ?
}
------------------------------------------------------------------------- EDIT
With Aaron answer, here's what I did :
function complete(e:Event):void {
addChild(list);
products = JSON.parse(loader5.data) as Array;
feedbackText.text = "complete";
showNext() ;
}
function showNext():void {
var currentNumShowing:int = list.numChildren;
var nextNumShowing:int = Math.min(currentNumShowing + 10, products.length);
for(var i:int = currentNumShowing; i < nextNumShowing; i++){
createListItem(i, products[i]);
}
next.visible = nextNumShowing < products.length;
}
So now how can I add next.addEventListener(MouseEvent.CLICK,next10);
?
(as I can't do next.addEventListener(MouseEvent.CLICK,showNext);
because showNext
is not a MouseEvent...)
Secondly, my code was displaying the products from the end to the beginning (for(var i:int = 0, l:int = products.length - 1; l >= 0; i++, l--){
. How can I keep that ?
I've tried : for(var i:int = currentNumShowing, l:int = products.length - 1; i < nextNumShowing;l >= 0; i++, l--){
but it's not working (error 1084 expecting rightparen before semicolon and expecting semicolon before rightparen)