Search code examples
javascriptangularjscreatejs

Createjs and Angularjs: Cannot read property 'Stage' of undefined


Hi i want connect Createjs with Angularjs i have this code in my controller

var stage,padel,createjs;
    $scope.load = function () {
        init();
    }
    function init() {
        console.log('idsaf');
        stage = new createjs.Stage(document.getElementById('canvas'));
        canvas = document.getElementById('canvas');
        //aby grafika była ładna w canvasie
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        createjs.Ticker.addEventListener("tick", tick);
        createjs.Ticker.setFPS(60);
        startGame();
    }

in view html:

<script src="https://code.createjs.com/createjs-2015.11.26.min.js"></script>
    <script src="https://code.createjs.com/easeljs-0.8.2.min.js"></script>
    <script src="https://code.createjs.com/preloadjs-0.6.2.min.js"></script>
    <script src="https://code.createjs.com/tweenjs-0.6.2.min.js"></script>

<div class="wrapper" ng-init="load()">
        <canvas id="canvas"></canvas>
    </div>

and when i run it i have error in console:

Cannot read property 'Stage' of undefined

how to fix that, I sit on this for 2 hours


Solution

  • You have a naming conflict in line 7 (as well as in 12 and 13) with the variable createjs which you declared in the first line! You should remove it from the first line or rename it!