javascriptbitmapeaseljspreloader

how to load bitmap using easeljs?


I am trying to load bitmap using easeljs but its not working, please help me.

function init() {

    canvas = document.getElementById("testCanvas");
    context = canvas.getContext("2d");
    stage = new createjs.Stage(canvas);
    var image = new Image();
    image.src = "assets/puli.png";

    var container = new createjs.Container();
    stage.addChild(container);

    bitmap = new createjs.Bitmap(image);
    container.addChild(bitmap);
    createjs.Ticker.addEventListener("tick", tick);
}

function tick(event) {

    if (update) {
        update = false; // only update once
        stage.update(event);
    }
}

Solution

  • You have to load your images using the LoadQueue Class form EaselJs: take a look at this--> http://www.createjs.com/Docs/PreloadJS/classes/LoadQueue.html

    var queue = new createjs.LoadQueue(true);
    queue.addEventListener("fileload",onFileLoaded.bind(this));
    var manifest = getManifest();
    queue.loadManifest(manifest);
    
    onFileLoaded = function(evt)
    {
     var item = evt.item;
     var type = evt.type;
    }
    
    getManifest = function()
    {
     var manifest = [
     {src:"/images/yourimage.png", id:"myimage"}    
     ];
    
     return manifest;
    }
    
    //create images
    var myimage = new createjs.Bitmap(images.myimage);