更改列表组件在 ActoinScipt 3 中的工作方式

Change how the List Component works in ActoinSciprt 3

我正在尝试制作一个将显示项目的列表组件,一切正常,但它添加的项目不是我想要的!

假设我发送一个命令,首先添加行 "User1",然后添加行 "User2"。这是它显示项目的方式:

  • User1
  • User2

虽然我想要它 "upside down",但它应该看起来像这样:

  • User2
  • User1

同样,如果我添加一个 "User3",它应该看起来像这样:

  • User3
  • User2
  • User1

我能以某种方式做到这一点吗?谢谢!

addItem() method of the SelectableList class (the super class of the List class) 将项目追加到列表末尾。

行布局的 index 值从 0 开始(即第一项的索引值为 0。)现在每次你想插入项目到列表的开头,你需要使用索引值为 0:

addItemAt() 方法
import fl.controls.List;
var lst:List = new List();

lst.addItemAt({label:"One",   data:1}, 0);
lst.addItemAt({label:"Two",   data:2}, 0);
lst.addItemAt({label:"Three", data:3}, 0);

addChild(lst);