0
我有一個閃存項目,同時有許多聲道活動。我想要一個小功能來播放和循環播放,並且聲道的名稱將作爲參數傳遞。這是函數:AS3動態訪問聲音通道
function playBGMusic(channel:String):void
{
SoundChannel(channel) = bgSound1.play();
SoundChannel(channel).addEventListener(Event.SOUND_COMPLETE, loopBGMusic);
}
playBGMusic("bgChannel1");
這不作品,閃光燈給了我這個錯誤:
1105: Target of assignment must be a reference value.
我試圖簡化功能,只是在監聽使用靜態字符串
function playBGMusic():void
{
bgChannel1 = bgSound1.play();
SoundChannel("bgChannel1").addEventListener(Event.SOUND_COMPLETE, loopBGMusic);
}
playBGMusic();
這次它編譯,但它給了我這個錯誤:
Error #1034: Type Coercion failed: cannot convert "bgChannel1" to flash.media.SoundChannel.
如何從字符串訪問聲音通道?
Thaks。