【问题标题】:Uncaught ReferenceError: Stage is not defined using EaselJS未捕获的 ReferenceError:未使用 EaselJS 定义阶段
【发布时间】:2016-01-18 06:42:16
【问题描述】:

我正在设置一个快速的小测试来开始深入研究 EaselJS,但我收到了这个错误,Uncaught ReferenceError: Stage is not defined。我不确定为什么没有定义 Stage,因为我检查了 Easeljs-NEXT.combined.js 的 Stage 方法,它肯定在那里。我在这里做错了什么?

<!doctype html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Easel Intro</title>
        <!-- EaselJS Library -->
        <script src="js/vendor/easeljs-NEXT.combined.js"></script>

        <script>
        var stage;
        var text;
        var logo;

            function init()
            {
                stage = new Stage(document.getElementById("canvas"));

                logo = new Bitmap("img/HTML5_Logo_64.png");
                logo.regX = logo.image.width * 0.5;
                logo.regY = logo.image.height * 0.5;
                stage.addChild(logo);

                text = new Text("Text rendered on the canvas.", "36px Arial", "#666");
                text.x = 100;
                text.y = 100;
                stage.addChild(text);

                stage.update();
            }
        </script>
    </head>

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

</html>

【问题讨论】:

    标签: html createjs easeljs


    【解决方案1】:

    您需要在所有 CreateJS 类前面加上 createjs.

    new createjs.Stage("canvas");
    

    这适用于您示例中的所有项目:舞台、位图和文本。

    那里可能有过时的文档或示例,因为早期版本(2011 年左右)没有命名空间。

    【讨论】:

    • 啊,谢谢!我是根据一些老例子来操作的。
    猜你喜欢
    • 2020-11-20
    • 2023-01-23
    • 2016-11-03
    • 2011-01-05
    • 2016-01-02
    • 2013-10-06
    • 2016-12-17
    相关资源
    最近更新 更多