Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3-另一个TypeError:Error#1009无法访问_Actionscript 3_Flash_Audio_Typeerror_Soundchannel - Fatal编程技术网

Actionscript 3 AS3-另一个TypeError:Error#1009无法访问

Actionscript 3 AS3-另一个TypeError:Error#1009无法访问,actionscript-3,flash,audio,typeerror,soundchannel,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.Main

我正在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:创建作为链接名称的链接:

//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
}
//处理函数---------------------------------------------------------------
函数onTick(e:TimerEvent){//下面一些函数的连续运行。
moveCharacter();
moveEnemyField();
playerCollisionDetectWall();
enemyCollisionDetectWall();
enemyCollisionDetectWallBottom();
移动激光器();
enemyHitTest();SpelerMC.y)继续;
if(enemyArray[i].visible&&enemyArray[i].hitTestObject(laserArray[j])){
分数+=10分;
myChannelMisc=explosionFX.play();
SfxTransform.volume=0.3;
myChannelMisc.soundTransform=sfxtTransform;
scoreTxt.text=score.toString();
跟踪(“入侵者努默”+i+“尼尔格肖滕!”);
enemyArray[i].visible=false;
//现在我们在击打时移除激光。
激光阵列[j].x=j*70+100;
激光阵列[j].y=895;
}
如果(分数==660){
//如果你达到660分(66敌人的x10=660),你就赢了这场比赛。
winGame();根据:

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

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


正如Mark所说,类winGameSound是罪魁祸首。调用winFX.play()会返回一个null,而不是一个声音通道。因此,不能对null对象应用声音转换


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

从您的代码摘录和注释中,当您尝试设置
myChannelWin.soundTransform
时,
myChannelWin
显然是null。上面的两行设置为
myChannelWin=winFX.play()
该方法起作用吗()返回非空值的内容?你是什么意思?我认为“myChannelWin”与“myChannelWin.soundTransform”不同?而且,对于丢失的声音“myChannelLose”/“myChannelLose.soundTransform”,我有完全相同的行,并且该行与游戏中的其他所有声音一样没有错误。如果排除此行,则错误,那么其他人仍然可以正常工作。谢谢你的回答。我正在做一个15"MacBook Pro'11。我在这里定义的所有声音都有效。所以我不认为是声卡。整个游戏正常运行,但我一直收到这个错误。正如你所看到的,我使用了4个不同的频道。所以我真的不知道这个类型的错误是如何存在的。他不是这么说的。不管你有什么类型的电脑。你总是需要跟踪myChannelWin(或SfxTransform),您将看到它将为空。然后您可以包装一个条件“if(myChannelWin){}”。如果您不跟踪或调试,您将不会理解任何问题。感谢您的解释,解决了问题!这样做的诀窍:我删除了行“myChannelWin.soundTransform=SfxTransform;”并做了以下两行:'myChannelWin=winFX.play(1,0,SfxTransform);'SfxTransform.volume=0.05;'
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
        }
    }
}
}
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
}