Reputation: 658
Ok, I'm trying to put the javascript in a separate source file. This is a newbie question, but I'm getting an 'undefined' error on layer.add(imageObj)
.
I'm guessing it's because of window.onLoad
, but I didn't find an immediate answer.
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="index.css">
<script type="text/javascript" src="js/kinetic-v5.1.0.min.js"></script>
<script type="text/javascript" src="js/game.js" defer="defer"></script>
</head>
<body>
<div id="board"></div>
</body>
The javascript:
window.onload = function(){
var stage = new Kinetic.Stage({
container: 'board'
});
var layer = new Kinetic.Layer();
var imageObj = new Image();
imageObj.onload = function() {
var image = new Kinetic.Image({
x: 0,
y: 0,
image: imageObj,
width: 100,
height: 100
});
};
imageObj.src = 'resources/map.jpg';
layer.add(imageObj);
stage.add(layer);
};
Upvotes: 0
Views: 36
Reputation: 20308
You need to add into layer Kinetic.Image
instance (image
in your source) not imageObj
. You can do this in onload
function. See: http://jsbin.com/buroyi/2/edit
Upvotes: 1