Actionscript 3 Actionscript从字符串数组加载/调用声音
我试图通过创建一个包含每个声音的文件路径(或名称)的字符串数组来实例化一组声音Actionscript 3 Actionscript从字符串数组加载/调用声音,actionscript-3,dynamic,object,audio,Actionscript 3,Dynamic,Object,Audio,我试图通过创建一个包含每个声音的文件路径(或名称)的字符串数组来实例化一组声音 我的当前代码包含sound_completeHandler()函数中的一个错误,指出找不到“name”属性。我不知道如何添加此name属性,或者如何引用e.currentTarget。您的代码有三个部分是错误的: soundByName是一个对象,您正在执行一个soundByName。soundName=new Sound()=>您正在soundByName中创建一个名为soundName的字段。 使用soundB
我的当前代码包含sound_completeHandler()函数中的一个错误,指出找不到“name”属性。我不知道如何添加此name属性,或者如何引用e.currentTarget。您的代码有三个部分是错误的:
- soundByName是一个对象,您正在执行一个
=>您正在soundByName中创建一个名为soundName的字段。 使用soundByName。soundName=new Sound()
这意味着创建一个名称取自变量condname的字段soundByName[soundName]=new Sound()
- 您正在对channelByName使用
channelByName[channelName]=value执行相同的操作代码>
- 然后你想把一个
与你的名字关联起来,它不能工作soundChannel
对象没有这样的字段。使用字典将声音与名称关联起来Sound
var nameBySound:Dictionary = new Dictionary(); var soundByName:Object = {}; var channelByName:Object = {}; loadSounds(); function loadSounds():void { var files:Array = ["sound1.mp3", "sound2.mp3"]; //etc. for (var i:int = 0; i < files.length; i++) { var soundName:String = files[i]; var sound:Sound=new Sound(); nameBySound[sound] = soundName; soundByName[soundName] = sound; sound.addEventListener(Event.COMPLETE, sound_completeHandler); sound.addEventListener(IOErrorEvent.IO_ERROR, sound_ioErrorHandler); sound.load(new URLRequest(soundName)); } } function sound_completeHandler(e:Event):void { var soundName:String=nameBySound[e.currentTarget]; channelByName[soundName] = new SoundChannel(); } function sound_ioErrorHandler(e:IOErrorEvent):void { trace("Failed To Load Sound:" + nameBySound[e.currentTarget]); }
var nameBySound:Dictionary=newdictionary(); var soundByName:Object={}; var channelByName:Object={}; loadSounds(); 函数loadSounds():void{ var文件:Array=[“sound1.mp3”,“sound2.mp3”];//等。 for(var i:int=0;i
//Stop a sound
channelByName["sound1.mp3"].stop();
//Play a sound
channelByName["sound2.mp3"] = soundByName["sound2.mp3"].play();
var nameBySound:Dictionary = new Dictionary();
var soundByName:Object = {};
var channelByName:Object = {};
loadSounds();
function loadSounds():void {
var files:Array = ["sound1.mp3", "sound2.mp3"]; //etc.
for (var i:int = 0; i < files.length; i++) {
var soundName:String = files[i];
var sound:Sound=new Sound();
nameBySound[sound] = soundName;
soundByName[soundName] = sound;
sound.addEventListener(Event.COMPLETE, sound_completeHandler);
sound.addEventListener(IOErrorEvent.IO_ERROR, sound_ioErrorHandler);
sound.load(new URLRequest(soundName));
}
}
function sound_completeHandler(e:Event):void {
var soundName:String=nameBySound[e.currentTarget];
channelByName[soundName] = new SoundChannel();
}
function sound_ioErrorHandler(e:IOErrorEvent):void {
trace("Failed To Load Sound:" + nameBySound[e.currentTarget]);
}