-3

HTML CODE: I HAD TO ADD SOMETHING TO DESCRIBE THE CODE, DONO Y so obviously this is html code, don't know why its not running. the code after this is javascript. If my code is very bad and doesn't make any sense, what im looking for is basically a way to use loadqueue to load an image and then set it as a background for a game.

<!DOCTYPE html>
<html>
    <head>
        <title>My Game</title>
        <link href="assets/MyGame.css" rel="stylesheet" type="text/css"/>
        <script src="https://code.createjs.com/preloadjs-0.6.1.min.js"></script>
        <script src="https://code.createjs.com/tweenjs-0.6.1.min.js"></script>
        <script language="javascript" type="text/javascript" 
        src="https://code.createjs.com/easeljs-0.8.1.min.js"></script>
        <script language="javascript" type="text/javascript" src="MyGame.js" 
        ></script>
    </head>

    <body>
        <canvas id="demoCanvas" width="1000" height="700"></canvas>
    </body>
</html>

var stage;


window.onload = function()
{
    var queue = new createjs.LoadQueue(true);

    queue.on("fileload", handleFileLoad, this);
    queue.loadFile({id:"image", src:"assets/space.jpg"});
    queue.load();

    stage = new createjs.Stage("demoCanvas");
}

function handleFileLoad(event) {
    // A reference to the item that was passed in to the LoadQueue
     var item = event.item; 
     var type = item.type;

     // Add any images to the page body.
     if (type == createjs.LoadQueue.IMAGE) {
         stage.addChild(event.result)
         stage.update;
     }
 }
Shaker
  • 1
  • 4

2 Answers2

1

I believe that stage.update; should be stage.update(); as it is a method and not a property

taxicala
  • 21,408
  • 7
  • 37
  • 66
1

I can spot two immediate issues:

  1. you are trying to add the loaded image directly to the stage. It needs to be wrapped in a Bitmap first: stage.addChild( new createjs.Bitmap( event.result ));

  2. you aren't calling stage.update() - you forgot the parenthesis.

gskinner
  • 2,478
  • 11
  • 12