[]Laya.loader.load 教程代码出错

 
 
 
 

     
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行提示异常
if (!tex.loaded){
tex.once("loaded",this,this._textureLoaded,[tex,args]);
 
编辑了好几次,这个代码的功能似乎有点问题。
 
代码现在是这个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);
        }
 
已邀请:

cqgcs

赞同来自:

LoadComplated 回调函数没有被执行

Monica - 知识达人

赞同来自:

图片格式只支持png和jpg格式的,你修改下图片的格式看能否加载成功。
还是不可以的话麻烦上传一个可以运行的Demo(不要直接贴代码),我们看下!

要回复问题请先

商务合作
商务合作