javascript - why aren't my images showing up -
hi i'm trying learn how use easeljs libraries, combining of extjs libs butt i'm having trouble putting code in .js files. js file looks this
var democanvas = document.createelement('canvas'); document.body.appendchild(democanvas); democanvas.height = "400"; democanvas.width = "600"; function init() { var canvas = document.getelementbyid("democanvas"); var stage = new createjs.stage('canvas'); var im = new createjs.bitmap("dbz.jpg"); // im.regx - im.image.width *.2; // im.regy - im.image.height *.2; stage.addchild(im); stage.update(); im.addeventlistener("click", function(){ var seed = new createjs.bitmap("seed.jpg"); seed.alpha = 0.5; seed.x = window.event.clientx; seed.y = window.event.clienty; stage.addchild(seed); stage.update(); }); //end seed evenlistener */ } //end functin init()
this doesn't work, if comment out whole document.createelement('canvas') section , apply
<body onload="init();"> <canvas id="democanvas" width="1000" height="1000"> alternate content </canvas>
to index.html file start working :( included .js within body tag of te index html
edit:::::::::::::::::::::: current code, still not showing unless add canvas html page :(
window.onload = function (){ var democanvas = document.createelement('canvas'); //document.body.appendchild(democanvas); democanvas.height = "400"; democanvas.width = "600"; } var stage; function init() { stage = new createjs.stage("democanvas"); var text = new createjs.text("hello world", "bold 86px arial", "#ff7700"); stage.addchild(text); stage.update(); } init();
another thing - since using image paths, , not loaded images bitmaps sources, possible images not ready when update stage. can either put onload handlers on image(s) update stage, or preload them first.
var image = new image(); image.onload = handleload; image.src = "src.jpg"; function handleload(event) { stage.update(); } // can use bitmap var bitmap = new createjs.bitmap("src.jpg"); bitmap.image.onload = handleload;
you can tick stage update constantly. quick way see if thats problem.
createjs.ticker.addeventlistener("tick", stage); // or createjs.ticker.on("tick", stage);
Comments
Post a Comment