I am trying to body onload my init function. but my html file tells me it can not find the init. I have put the init in a external js file called game. I am adding this script with script src but it still can not read my function. does somebody know what is going wrong?

html :

<script src="http://code.createjs.com/easeljs-0.7.1.min.js"></script>
<script src="js/game.js"></script>
<script src="js/stone.js"></script>


    <style>

    #canvas {
        border-style:solid;
        border-width:5px;


    }



    </style>

    </head>

    <body onload="init();">
            <canvas id="canvas" width="960" height="580"></canvas>
    </body>








var game = {

        player :null,
        stage: null,
        score: 0,
        rocks: [], //maak er een array van omdat je we straks meerdere stenen willen

        init: function() {

                this.stage = new createjs.Stage("canvas");
                this.score = 0;

                this.initPlayer();
                this.initStone();

                this.start();       


        }

};
有帮助吗?

解决方案

You can call object properties using dot notation so it will be called using game.init()

<body onload="game.init();">

Also please make sure that script gets object gets loaded first before onload function itself.

其他提示

You should use

game.init()

because your init function is inside the game object.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top