我有了这个代码在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();
}
它显示的所有产品的列表包含在我的表的数据库。
现在我加了if(products.length >=10){
它工作。
我想补充
`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 ?
}
--------------------------------- ---------------------------------------- 编辑
随着亚伦的回答,这里是我所做的:
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;
}
那么现在我该如何添加next.addEventListener(MouseEvent.CLICK,next10);
?
(我不能这样做,因为next.addEventListener(MouseEvent.CLICK,showNext);
是showNext
没有的MouseEvent ...)
其次,我的代码是从最终产品显示开始(for(var i:int = 0, l:int = products.length - 1; l >= 0; i++, l--){
。我怎样才能保持呢?
我已经试过:for(var i:int = currentNumShowing, l:int = products.length - 1; i <nextNumShowing;l>= 0; i++, l--){
但它不工作(错误1084 rightparen预计分号之前和期待rightparen之前分号)
什么是downvote?这是一个合法的问题(这个问题已被要求在这里的PHP:[链接](http://stackoverflow.com/questions/1571427/returning-first-x-items-from-array)]或在这里[链接]( http://stackoverflow.com/questions/1921421/get-the-first-element-of-an-array)但从来没有要求过AS3 – cocoGeek
不明原因的反对票很讨厌和无益,我认为你的问题不是很清楚。你想加载所有的产品,并且一次只显示* 10吗?或者你一次从你的服务器加载10个? – Aaron
Thx为解释。我的意思是“加载所有产品,只显示10一个时间“(如果可能的话)。 – cocoGeek