2013-08-21 94 views
0

因此,繼承人的代碼:AS3空對象引用

function playSound():void 
{ 
    var channel:SoundChannel = sound.play(); 
    channel.addEventListener(Event.SOUND_COMPLETE, onComplete); 
} 

function onComplete(event:Event):void 
{ 
    SoundChannel(event.target).removeEventListener(event.type, onComplete); 
    playSound(); 
} 

我的錯誤上channel.addEventListener(Event.SOUND_COMPLETE, onComplete); ,但我不在一開始把它作爲一個遊戲運行一段時間沒有錯誤,因此Im提示在onComplete函數或事件監聽器中存在問題,但是,我嘗試的所有嘗試都失敗了,現在我在這裏呆了一段時間。

我只是決定在這裏發佈,看看是否有人能看到問題。

在此先感謝!編輯: 對不起,我還沒有包括這個馬上。

錯誤:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at projectSnowFlake_fla::MainTimeline/playSound()[projectSnowFlake_fla.MainTimeline::frame1:275] at projectSnowFlake_fla::MainTimeline/playGame()[projectSnowFlake_fla.MainTimeline::frame1:269] at projectSnowFlake_fla::MainTimeline/gameLoop()[projectSnowFlake_fla.MainTimeline::frame1:156] [UnloadSWF] projectSnowFlake.swf Test Movie terminated.

而且繼承人的sound

var sound:Sound = new MainSound(); 
+1

'VAR渠道:的SoundChannel = sound.play();'你是什麼'sound'變量? –

+0

你會得到什麼錯誤?我在想,你註冊事件的順序可能是一個問題。但是,不知道,除非我看錯誤。 – Zeus

+0

看到最後編輯 – Dominiko

回答

0

我看了你的代碼,唯一的潛在問題是聲音變量,可以爲空。

你是否實例化了聲音變量?

如果聲音有價值,方法播放(可變聲音)可以返回空值?

編輯點評AFTER:

嗨,鑑於thisthis issue

+0

看到最後編輯 – Dominiko

+0

嗨,你測試了方法play()的結果嗎?它可能返回null? –

+0

剛剛做到了,這可能是一個問題,它返回undefined – Dominiko