Reputation: 1
It seems I do it by the book, but it doesn't work. What on earth is wrong with this code?
<!DOCTYPE html>
<html lang="sv-se">
<head>
<script src="https://code.createjs.com/easeljs-0.8.2.min.js"></script>
<script src="https://code.createjs.com/tweenjs-0.6.2.min.js"></script>
<script src="https://code.createjs.com/preloadjs-0.6.2.min.js"></script>
<script src="https://code.createjs.com/soundjs-0.6.2.min.js"></script>
<script type="text/javascript">
function init() {
var stage = new createjs.Stage("stage");
stage.canvas.width = 1200;
stage.canvas.height = 871;
var queue = new createjs.LoadQueue();
queue.on("complete", handleComplete, this);
queue.loadManifest([
{id: "myImage", src:"images/image.jpg"}
]);
function handleComplete() {
var myImage = queue.getResult("myImage");
stage.addChild(myImage);
}
}
</script>
</head>
<body onLoad="init();">
<canvas id="stage"></canvas>
</body>
</html>
All I get is this error message: Uncaught InvalidStateError: Failed to execute 'dispatchEvent' on 'EventTarget': The event provided is null.
Upvotes: 0
Views: 158
Reputation: 732
You have to create a createjs.Bitmap
object out of the loaded image, add it to the stage and update the stage afterwards:
var myImage = new createjs.Bitmap(queue.getResult("myImage"));
stage.addChild(myImage);
stage.update();
Upvotes: 1