admin管理员组文章数量:1292101
Here I have a very simple script.
stage = new createjs.Stage("myCanvas");
circle = new createjs.Shape();
circle.graphics.beginFill("red").drawCircle(0,0,40);
And my HTML
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mainStyle.css">
<script src="mainScript.js"></script>
<script src="create.js"></script>
</head>
<body>
<canvas id="myCanvas" width=1000 height=500 ></canvas>
</body>
</html>
Yet it does not work. I get this error:
"createjs is not defined"
But in my HTML it is linked to file. Is there anything else that could be causing this?
Here I have a very simple script.
stage = new createjs.Stage("myCanvas");
circle = new createjs.Shape();
circle.graphics.beginFill("red").drawCircle(0,0,40);
And my HTML
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mainStyle.css">
<script src="mainScript.js"></script>
<script src="create.js"></script>
</head>
<body>
<canvas id="myCanvas" width=1000 height=500 ></canvas>
</body>
</html>
Yet it does not work. I get this error:
"createjs is not defined"
But in my HTML it is linked to file. Is there anything else that could be causing this?
Share Improve this question asked Feb 22, 2013 at 3:54 starscapestarscape 2,9935 gold badges30 silver badges40 bronze badges 2- can you post the code for linked to that file? – Iswanto San Commented Feb 22, 2013 at 3:56
- Modified it to include the HTML – starscape Commented Feb 22, 2013 at 3:58
3 Answers
Reset to default 5<script src="create.js"></script>
<script src="mainScript.js"></script>
Your code needs to execute AFTER including create.js
- order matters.
There are a couple problems with your code.
First, and to directly answer the question, you have to load the library which constructs the createjs object before you load your script which instantiates it. Change the order of the script tags you have in your head.
Second, your instantiation will execute before the canvas element is added to the DOM. To fix this you need to listen for the document's onload event. Then execute your code.
Third, to get the red circle object to actually show up you need to append it to the canvas and then call the stages update method.
Ex:
window.onload = function(){
stage = new createjs.Stage("myCanvas");
circle = new createjs.Shape();
circle.graphics.beginFill("red").drawCircle(0,0,40);
stage.addChild(circle);
stage.update();
}
For angular projects the above answers might not be sufficient to solve the problem. What I did:
myAngularModule.service('preloadservice', function ($rootScope) {
if (typeof createjs === 'undefined') {
setTimeout(continueAfterWait, 500);
} else {
continueAfterWait();
}
var continueAfterWait = function () {
var queue = new createjs.LoadQueue();
//...
}
}
版权声明:本文标题:javascript - I get the error "createjs is not defined" even though I linked to the file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741546433a2384621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论