简体   繁体   English

0x800a1391-JavaScript运行时错误:'Stage'未定义

[英]0x800a1391 - JavaScript runtime error: 'Stage' is undefined

I'm trying to do this tutorial: 我正在尝试做本教程:

http://www.sitepoint.com/creating-a-simple-windows-8-game-with-javascript-game-basics-createjseaseljs/ http://www.sitepoint.com/creating-a-simple-windows-8-game-with-javascript-game-basics-createjseaseljs/

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>CatapultGame</title>

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>

    <!-- CatapultGame references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>
    <script src="js/CreateJS/easeljs-0.6.0.min.js"></script>
    <script src="js/CreateJS/preloadjs-0.2.0.min.js"></script>
</head>
<body>
    <canvas id="gameCanvas"></canvas>
</body>
</html>

and there is JS file 还有JS文件

// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509


(function () {
    "use strict";

    WinJS.Binding.optimizeBindingReferences = true;

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;

    WinJS.strictProcessing();

    var canvas, context, stage;
    var bgImage, p1Image, p2Image, ammoImage, p1lives, p2lives, title, endGameImage;
    var bgBitmap, p1Bitmap, p2Bitmap, ammoBitmap;
    var preload;

    // Current Display Factor. Because the orignal assumed a 800x480 screen
    var SCALE_X = window.innerWidth / 800;
    var SCALE_Y = window.innerHeight / 480;
    var MARGIN = 25;
    var GROUND_Y = 390 * SCALE_Y;

    function initialize() {
        canvas = document.getElementById("gameCanvas");
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        context = canvas.getContext("2d");

        preload = new createjs.PreloadJS();
        preload.onComplete = prepareGame;
        var manifest = [
            { id: "screenImage", src: "images/Backgrounds/gameplay_screen.png" },
            { id: "redImage", src: "images/Catapults/Red/redIdle/redIdle.png" },
            { id: "blueImage", src: "images/Catapults/Blue/blueIdle/blueIdle.png" },
            { id: "ammoImage", src: "images/Ammo/rock_ammo.png" },
            { id: "winImage", src: "images/Backgrounds/victory.png" },
            { id: "loseImage", src: "images/Backgrounds/defeat.png" },
            { id: "blueFire", src: "images/Catapults/Blue/blueFire/blueCatapult_fire.png" },
            { id: "redFire", src: "images/Catapults/Red/redFire/redCatapult_fire.png" },
        ];

        preload.loadManifest(manifest);


        stage = new Stage(canvas); <<<--------
    }

    function prepareGame() {
        bgImage = preload.getResult("screenImage").result;
        bgBitmap = new Bitmap(bgImage);
        bgBitmap.scaleX = SCALE_X;
        bgBitmap.scaleY = SCALE_Y;
        stage.addChild(bgBitmap);

        stage.update();
    }

    function gameLoop() {

    }

    function update() {

    }

    function draw() {

    }

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                // TODO: This application has been newly launched. Initialize
                // your application here.
            } else {
                // TODO: This application has been reactivated from suspension.
                // Restore application state here.
            }
            args.setPromise(WinJS.UI.processAll());
        }
    };

    app.oncheckpoint = function (args) {
        // TODO: This application is about to be suspended. Save any state
        // that needs to persist across suspensions here. You might use the
        // WinJS.Application.sessionState object, which is automatically
        // saved and restored across suspension. If you need to complete an
        // asynchronous operation before your application is suspended, call
        // args.setPromise().
    };

    document.addEventListener("DOMContentLoaded", initialize, false);

    app.start();
})();

But When I'm trying to run the project, I get and error saying "0x800a1391 - JavaScript runtime error: 'Stage' is undefined", in the marked place in my code. 但是,当我尝试运行该项目时,在代码中的标记位置出现了错误并显示“ 0x800a1391-JavaScript运行时错误:'Stage'未定义”。

What I did wrong? 我做错了什么?

If you are using a newer version of EaselJS (3.1 is the current version), some things need to change. 如果您使用的是EaselJS的更新版本(当前版本为3.1),则需要进行一些更改。 The most common is that the EaselJS and PreloadJS objects are now wrapped in the createjs namespace. 最常见的是EaselJS和PreloadJS对象现在包装在createjs命名空间中。 So the line from the tutorial: 因此,本教程中的代码行:

stage = new Stage(canvas);

becomes

stage = new createjs.Stage(canvas);

and the line 和线

bgBitmap = new Bitmap(bgImage);

becomes

bgBitmap = new createjs.Bitmap(bgImage);

I hope that Stage class is defined in your application, that why you getting error on line stage = new Stage(canvas); 我希望在您的应用程序中定义Stage类,这就是为什么在line stage = new Stage(canvas)上出错的原因;

please have cross check whether "Stage" class has been defined in any of your JS files(which is included in HTML) 请进行交叉检查是否在您的任何JS文件(包含在HTML中)中都定义了“ Stage”类

that may be the problem !!!! 可能是问题所在!

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 0x800a1391-JavaScript运行时错误:“角度”未定义 - 0x800a1391 - JavaScript runtime error: 'angular' is undefined 0x800a1391-JavaScript运行时错误:&#39;ko&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'ko' is undefined 0x800a1391-JavaScript运行时错误:&#39;bobj&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'bobj' is undefined 0x800a1391-JavaScript运行时错误:&#39;PageMethods&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'PageMethods' is undefined 0x800a1391-JavaScript运行时错误:&#39;__doPostBack&#39;未定义 - 0x800a1391 - JavaScript runtime error: '__doPostBack' is undefined 0x800a1391 - JavaScript运行时错误:&#39;jQuery&#39;未定义 - 0x800a1391 - JavaScript runtime error: 'jQuery' is undefined javascript运行时错误0x800a1391 - javascript runtime error 0x800a1391 0x800a1391-JavaScript运行时错误:未定义“模块” - 0x800a1391 - JavaScript runtime error: 'module' is not defined 0x800a1391-JavaScript运行时错误:“ $”未定义:直接链接有效,但解决方案资源管理器文件不起作用 - 0x800a1391 - JavaScript runtime error: '$' is undefined: directlink works but solution explorer file doesn't Windows 8 App运行正常,现在得到0x800a1391-JavaScript运行时错误:“ WinJS”未定义 - Windows 8 App was working, now getting 0x800a1391 - JavaScript runtime error: 'WinJS' is undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM