先建项目,创建标签,创建item
最后在main里面找到创建的list进行设置资源
代码设置如下
import Itemtest from "./Itemtest";
import Item from "./Itemtest";
export default class fgu extends Laya.Script {
private _view:fgui.GComponent;
private _vbn1:fgui.GProgressBar;
private _btn2:fgui.GComponent;
private _list:fgui.GList;
constructor() {
super();
fgui.UIPackage.loadPackage("res/UI/FguiTest",Laya.Handler.create(this,this.onUILoad));
}
onUILoad()
{
this._view = fgui.UIPackage.createObject("FguiTest", "Main").asCom;
this._view.makeFullScreen();
fgui.GRoot.inst.addChild(this._view);
var _bnt:fgui.GButton=this._view.getChild("n2").asButton;
_bnt.selectedIcon
_bnt.onClick(this,()=>{
//window.alert("点击l");
this._view.getChild("n2").asButton.x+=Math.round(Math.random()*(300));
this._view.getChild("n2").asButton.y+=Math.round(Math.random()*(300))
console.log( this._view.getChild("n5").asProgress.value);
this._view.getChild("n5").asProgress.value+=2;
});
fgui.UIObjectFactory.setExtension("res/UI/FguiTest/Item",Itemtest);
this._list=this._view.getChild("list").asList;
for (let index = 0; index <10; index++) {
<Itemtest>this._list.addItemFromPool();
}
this._list.ensureBoundsCorrect();
for (let index = 0; index < 10; index++) {
<Itemtest>this._list.getChildAt(index);
}
console.log("list名字"+this._list.name);
var _GSlider:fgui.GSlider=this._view.getChild("n6").asSlider;
_GSlider.stopDrag();
Laya.stage.frameLoop(3,this,this.loopr,[_GSlider]);
}
loopr(cell:any):void
{
console.log(cell.value);
}
onEnable(): void {
}
onUpdate(): void {
// console.log(this._view.getChild("n6").asSlider.value);
}
onDisable(): void {
}
}