0
我是AS3的新手,需要一些幫助。在運行時構造變量名稱
我有這樣的代碼來播放不同的音頻文件和動態循環他們:
var mIntroLoop = 12495;
var mBattleLoop = 29000;
var currentPlaying;
function playMusic(x):void
{
musicChannel = x.play();
currentPlaying = x;
}
function loopSound(m:Object):Function {
return function(e:Event):void {
musicChannel = m.play(m.toString() + "Loop");
musicChannel.addEventListener(Event.SOUND_COMPLETE, loopSound(currentPlaying));
}
}
playMusic(mIntro);
musicChannel.addEventListener(Event.SOUND_COMPLETE, loopSound(currentPlaying));
正如你可以在代碼的頂部看到我有兩個變量,mIntroLoop
和mBattleLoop
。
我需要這一行幫助:
musicChannel = m.play(m.toString() + "Loop");
這當然不工作,它的存在只是讓你知道我想要做的事。
在該行中,m.play()
需要具有mIntroLoop
或mBattleLoop
的返回值作爲參數,具體取決於我當前正在播放的內容。
我已經使用Object屬性解決了id。 – Fr0z3n