0x800a1391-JavaScript运行时错误:';舞台';是未定义的

0x800a1391-JavaScript运行时错误:';舞台';是未定义的,javascript,Javascript,我正在尝试做这个教程: stage = new Stage(canvas); 弹射器 还有一个JS文件 // For an introduction to the Blank template, see the following documentation: // http://go.microsoft.com/fwlink/?LinkId=232509 (function () { "use strict"; WinJS.Binding.optimizeBind

我正在尝试做这个教程:

stage = new Stage(canvas);


弹射器
还有一个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();
})();
<代码> //对于空白模板的介绍,请参阅下列文档: // http://go.microsoft.com/fwlink/?LinkId=232509 (功能(){ “严格使用”; WinJS.Binding.optimizeBindingReferences=true; var app=WinJS.Application; var activation=Windows.ApplicationModel.activation; WinJS.strictProcessing(); var画布、语境、舞台; var bgImage、p1Image、p2Image、ammoImage、p1Lifes、p2Lifes、title、endGameImage; var bgBitmap、p1Bitmap、p2Bitmap、AMOMBitmap; var预载; //当前显示系数。因为原始信号采用800x480屏幕 var SCALE_X=window.innerWidth/800; var SCALE_Y=窗内高度/480; var保证金=25; var地面Y=390*刻度Y; 函数初始化(){ canvas=document.getElementById(“gameCanvas”); canvas.width=window.innerWidth; canvas.height=window.innerHeight; context=canvas.getContext(“2d”); preload=new createjs.PreloadJS(); preload.onComplete=预加载名称; 变量清单=[ {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/failure.png”}, {id:“blueFire”,src:“images/Catapults/Blue/blueFire/blueCatapult_fire.png”}, {id:“redFire”,src:“images/Catapults/Red/redFire/redcatapultt_fire.png”}, ]; 预加载。加载清单(manifest);
stage=newstage(canvas);我希望stage类是在应用程序中定义的,这就是为什么stage=newstage(canvas)行出现错误的原因

请交叉检查是否在任何JS文件(包含在HTML中)中定义了“Stage”类

这可能就是问题所在


谢谢。

如果您使用的是较新版本的EaselJS(3.1是当前版本),有些事情需要更改。最常见的是,EaselJS和preload js对象现在包装在createjs命名空间中。因此教程中的一行:

stage = new Stage(canvas);
变成

stage = new createjs.Stage(canvas);
bgBitmap = new createjs.Bitmap(bgImage);
线路呢

bgBitmap = new Bitmap(bgImage);
变成

stage = new createjs.Stage(canvas);
bgBitmap = new createjs.Bitmap(bgImage);

这个脚本在哪里?(它是哪个文件?)哦,我忘了提到(很抱歉)我正在使用easelJS和prelojs库。所以,我只有3个.js文件:default.js、easelJS.js和prelojs.js,还有1个HTML文件(default.HTML)编辑:我只是把“stage=newstage(canvas);”改为“stage=newstage(canvas);”(带有小的“s”)现在我得到另一个错误,说“JavaScript运行时错误:对象不支持此操作”.我不知道easelJS和prelodjs库。看到你的问题,它表示Stage类未定义,这意味着它无法获取类Stage的引用。简单地说,你加载的应用程序中没有定义函数Stage。如果我删除这一行(Stage=new Stage(canvas);),我会遇到更多未定义的错误。当它在“bgBitmap=new Bitmap(bgImage);”行中说:“JavaScript运行时错误:'位图'未定义”;///最后!!!!我明白了。我只需要替换“stage=new stage(canvas);“to”stage=new createjs.stage(canvas);”