this.createEmptyMovieClip("noise1",getNextHighestDepth());
noise1 = new Sound(noise1);
noise1.attachSound("noise1");
noise1.start(0,99999);
noise1.setVolume(0);
this.createEmptyMovieClip("noise2",getNextHighestDepth());
noise2 = new Sound(noise2);
noise2.attachSound("noise2");
noise2.start(0,99999);
noise2.setVolume(0);
this.createEmptyMovieClip("noise3",getNextHighestDepth());
noise3 = new Sound(noise3);
noise3.attachSound("noise3");
noise3.start(0,99999);
noise3.setVolume(0);
我如何将这些压缩成一个函数。一个看起来像这样的函数:
function soundclip(soundname){
this.createEmptyMovieClip("soundname",getNextHighestDepth());
soundname = new Sound(soundname);
soundname.attachSound("soundname");
soundname.start(0,99999);
soundname.setVolume(0);
}
我希望soundname替换函数中的所有声音名称,包括引号中的声音名称。他们必须有相同的名字。我会调用这样的函数:
soundclip(noise1);
soundclip(noise2);
soundclip(noise3);
会产生上述内容。我的语法不好。我已经尝试了所有涉及在函数中使用引号的内容,或者根本没有,我尝试使用toString()但没有成功。 谢谢你的帮助
答案 0 :(得分:1)
返回声音对象并将其指定给命名变量:
function soundclip(soundname){
var mc = this.createEmptyMovieClip(soundname + "_mc",getNextHighestDepth());
var sound = new Sound(mc);
sound.attachSound(soundname);
sound.start(0,99999);
sound.setVolume(0);
return sound;
}
noise1 = soundclip("noise1");
noise2 = soundclip("noise2");
noise3 = soundclip("noise3");