actionscript-3 - AS3 - 又一个 TypeError : Error #1009 Cannot acces

标签 actionscript-3 flash audio typeerror soundchannel

我正在 AS3 中创建“太空入侵者”游戏。现在一切正常,但不断出现 #1009 错误,我正在查看它很长一段时间,但我只是看不到问题所在。一些额外的眼睛可以帮助我想!

这是调试器所说的:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at testbestandkopie_fla::MainTimeline/winGame()[testbestandkopie_fla.MainTimeline::frame1:352]
at testbestandkopie_fla::MainTimeline/enemyHitTest()[testbestandkopie_fla.MainTimeline::frame1:338]
at testbestandkopie_fla::MainTimeline/onTick()[testbestandkopie_fla.MainTimeline::frame1:117]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()

下面我将粘贴与错误有关的代码:

1:创建 AS 链接名称:
//Sound FX-------------------------------------------------------------------------
var startFX:Sound = new startGameSound();
var laserFX:Sound = new laserSound();
var explosionFX:Sound = new explosionSound();
var musicFX:Sound = new backgroundMusic();
var loseFX:Sound = new endGameSound();
var winFX:Sound = new winGameSound();
var SfxTransform = new SoundTransform();
var myChannelMisc:SoundChannel = new SoundChannel();
var myChannelMusic:SoundChannel = new SoundChannel();
var myChannelWin:SoundChannel = new SoundChannel();
var myChannelLose:SoundChannel = new SoundChannel();
//---------------------------------------------------------------------------------

2:[第 117 行] AS 117 行是突出显示的:
//Handlers Functions---------------------------------------------------------------
function onTick(e:TimerEvent) { //A continuous run of some functions below.
moveCharacter();
moveEnemyField(); 

playerCollisionDetectWall();
enemyCollisionDetectWall();
enemyCollisionDetectWallBottom();

moveLasers();
enemyHitTest(); <---- line 117
}

3: [第 338 行] 函数enemyHitTest(); winGame() 开始的地方;功能:
function enemyHitTest() {
//For each of the three enemys
for (var i:int = 0; i < enemyArray.length; i++) {
    //the each of the six lasers
    for (var j:int = 0; j < 6; j++) {
        //don't consider lasers that aren't in play:
        if (laserArray[j].y > SpelerMC.y) continue;
        if (enemyArray[i].visible &&     enemyArray[i].hitTestObject(laserArray[j])) {
            score += 10;
            myChannelMisc = explosionFX.play();
            SfxTransform.volume = 0.3;
            myChannelMisc.soundTransform = SfxTransform;
            scoreTxt.text = score.toString();
            trace("Invader nummer " + i + " neergeschoten!");
            enemyArray[i].visible = false;
            //Now we remove the laser when hitting.
            laserArray[j].x = j * 70 + 100; 
            laserArray[j].y = 895;
        }
        else if(score == 660) { 
        //If you reach a score of 660 (66 enemy's x 10 = 660) you win the game.
            winGame(); <---- Line 338
        }
    }
}
}

4: [第 352 行] winGame();在敌人命中获得 660 分后运行函数。
function winGame() {
winScreen.visible = true;
gameTimer.stop();
//Stop the music.
myChannelMusic.stop();
//Start the "You Win" music.
myChannelWin = winFX.play();
SfxTransform.volume = 0.02;
myChannelWin.soundTransform = SfxTransform; <---- line 352
}

如您所见,它通过这些功能运行。我已经检查了我在库中的文件是否有问题,但是 AS Linkage 名称与我在上面定义的 var 完全相同。也许一些额外的眼睛可以看到这里出了什么问题,并解释我为什么..

提前致谢!

最佳答案

根据 livedocs :

winFX.play() 如果您没有声卡或没有可用的声道,该方法可能会返回 null。一次可用的最大声道数为 32。

检查上述任何一个问题是否适用于您....

正如马克所说,类(class) winGameSound 是这里的罪魁祸首。来电 winFX.play() 返回空值,而不是声道。所以你不能对空对象应用声音变换。

目前可以得到的唯一信息是该类继承了 Sound 类并通过 play() 调用返回 null。

关于actionscript-3 - AS3 - 又一个 TypeError : Error #1009 Cannot acces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12924363/

相关文章:

sql - SQLite 中的计数器变量

flash - 如何在 AS3 中粘贴选定的文本

actionscript-3 - ADT 适用于 ipa-test-interpreter 但不适用于 ipa-test

c++ - Linux,C++ 音频捕获(只是麦克风)库

actionscript-3 - Event.MOUSE_LEAVE 在 AS3 中不起作用

flash - 混合 AS2 和 AS3 时出现问题

php - 将 SWF 转换为 PNG

java - 是否可以使用计时器扩展Flex树中的所有节点?

audio - 在 nim 中使用 sdl2/mixer 播放音频的时间不可靠

java - Java中是否有一个库可以不断发出一定的频率?