1

I have a problem with creatJS I hope you can help.

 var stage = new createjs.Stage(canvas);

I got this error :

angular.js:13642 ReferenceError: createjs is not defined. even thought i get the EaselJS in my bower-components.

Thanks

Lanny
  • 11,244
  • 1
  • 22
  • 30
Mahmoud
  • 23
  • 1
  • 6
  • Can you provide us the full code please? – Mistalis Jul 26 '16 at 14:49
  • this is my code in the controller :var stage = new createjs.Stage(canvas); var image = new createjs.Bitmap("app/common/views/weather/img/windrose.png"); stage.addChild(image); stage.update(); – Mahmoud Jul 26 '16 at 15:01
  • Are you getting any errors in the console? Usually this is caused by an incorrectly loaded script tag or similar. – Lanny Jul 26 '16 at 15:05

3 Answers3

2

I had a similar problem - in my case I added the createjs-module npm package for webpack (I use it in the Laravel wabpack mix). It appeared that there was an issue with the scope, so I had to ensure that createjs is global. So you can try to do the following:

  1. Install the npm module (in the console)

    npm install createjs-module --save
    
  2. Initialize the createjs (in your js file)

    this.createjs = {};
    
  3. Make createjs global (in your js file)

    window.createjs = this.createjs;
    
  4. Import the module (in your js file)

    require('createjs-module');
    

And now you can use it as usual :)

Reference: CreateJS GitHub Issues

tsveti_iko
  • 6,834
  • 3
  • 47
  • 39
1

I assume createjs is defined in the window object. To be accessible in angular js you need to make it injectabled like this :

  angular.module('myApp', [])
  .constant('createjs', window.createjs)

Then you can inject it into your controller for example :

controller: function(createjs) {
  var stage = new createjs.Stage(canvas);
}

You can also refer to it by using $window :

controller: function($window) {
  var stage = new $window.createjs.Stage(canvas);
}
Olivier Boissé
  • 15,834
  • 6
  • 38
  • 56
  • thank you, the problem was that easeljs the library which i use for creatjs was not injected in the bower.json file... so finally i injected the library in the Bower file and it work.. thank you – Mahmoud Jul 27 '16 at 09:27
0

I just get some tests on it and i verify if the library EaselJS which is used for createjs is injected but it was not injected in the Bower.json file. so i had to injected manually in the bower.json file and it's working.

Mahmoud
  • 23
  • 1
  • 6