package {
import laya.display.Text;
import laya.display.Sprite;
import laya.utils.Handler;
import laya.resource.Texture;
public class LayaSample {
private var img:Sprite ;
private var index:int ;
public function LayaSample() {
//初始化引擎
Laya.init(600, 300);
img = new Sprite();
var arr:Array = [];
for (index=0;index <=31;index++)
{
var url:String = "../Res/Images/Role1/00011208_"+ index.toString() +".bmp";
arr.push(url);
}
Laya.loader.load(arr,Handler.create(this,LoadComplated));
}
private function LoadComplated(e:*=null):void
{
Laya.stage.addChild(img);
img.on("click",this,OnImgClick);
OnImgClick();
var txt:Text = new Text();
txt.text = "loadcomplated!";
Laya.stage.addChild(txt);
}
private function OnImgClick(e:*=null):void
{
if ( ++index > 31)
{
index = 0;
}
var url:String = "../Res/Images/Role1/00011208_"+ index.toString() +".bmp";
img.graphics.clear();
var txture:Texture = Laya.loader.getRes(url);
img.graphics.drawTexture(txture);
img.size(txture.width,txture.height);
}
}
}
运行后在 LayaSample.max.js 692行提示异常[code]if (!tex.loaded){
tex.once("loaded",this,this._textureLoaded,[tex,args]);[/code]
编辑了好几次,这个代码的功能似乎有点问题。
代码现在是这个yang样子的:
public function LayaSample() {
//初始化引擎
Laya.init(600, 300);
img = new Sprite();
Laya.loader.load("Res/Images/Role1/00011208_0.bmp",Handler.create(this,loadComplated));
}
private function loadComplated():void
{
var txt:Text = new Text();
txt.text = "loadcomplated!";
Laya.stage.addChild(txt);
img.graphics.clear();
var txture:Texture = Laya.loader.getRes("Res/Images/Role1/00011208_0.bmp");
img.graphics.drawTexture(txture);
Laya.stage.addChild(img);
}