AS3:错误#1034:类型强制失败:无法转换为flash.display.DisplayObject



遇到hitTestObject的一些问题,现在Flash告诉我它无法将我的飞船转换为显示对象。。我的问题是船级从一开始就扩展了Sprite,所以我不知道发生了什么:

编译错误显示:

TypeError: Error #1034: Type Coercion failed: cannot convert Ship$ to flash.display.DisplayObject.
at Control/controlgame()

Control/controlgame()是这样的:

function controlgame(e:Event) {
        for (var i = 0; i < wprojectiles.length; i ++) {
            if (wprojectiles[i].x < -200 || wprojectiles[i].x > 750 || wprojectiles[i].y < -200 || wprojectiles[i].y > 600) {
                parent.removeChild(wprojectiles[i]);
                wprojectiles.splice(i,1);
            }
            if (wprojectiles[i].hitTestObject(Ship)) {
                parent.removeChild(wprojectiles[i]);
                wprojectiles.splice(i,1);
            }
        }
    }

使用调试器,我得到这个错误:

TypeError: Error #1034: Type Coercion failed: cannot convert Ship$ to flash.display.DisplayObject.
at Control/controlgame()[C:UsersHarryDesktopFlash GamesGamesDodgeControl.as:29]

在上面的片段中,第29行是这样的:

if (wprojectiles[i].hitTestObject(Ship)) {

在这里撕裂我的头发,尝试了我能想到的一切,无论我做什么,我每次都会犯这个错误!非常感谢您的帮助!

提前谢谢。

e: 如果它具有相关性,这就是我的文档类文件

您在哪里声明Ship?看起来您在测试中使用的是Class,而不是实例。。。你有类似Ship = new ShipClass()的东西吗?

最新更新