我正在尝试播放阵列中的随机声音。这是我正在使用的代码。有任何想法吗?这不起作用。
import flash.media.Sound;
//var mySound:Sound = new Sound();
var mySoundsArray:Array = ["blue.mp3","green.mp3","red.mp3","yellow.mp3"];
var storedSounds:Array;
for(var i =0; i < mySoundsArray.length; i++)
{
/// DOES NOT WORK BELOW
storedSounds[i] = new Sound();
storedSounds[i].load(new URLRequest("sounds/" + mySoundsArray[i]));
}
/// later to loop through sounds but for now I use the line below default at 0
mySoundsArray[0].play();
答案 0 :(得分:1)
您不能将play
方法用于mySoundsArray
元素,因为它们不是声音对象而是字符串。尝试更改storedSounds[0].play()
<强>更新强>
这段代码对我来说很好
package
{
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
public class test extends Sprite
{
private var names:Array = new Array("blue.mp3","green.mp3","red.mp3","yellow.mp3");
private var sounds:Array = new Array();
public function test()
{
for(var i:uint = 0; i < this.names.length; i++)
{
sounds[i] = new Sound(new URLRequest("sounds/" + this.names[i]));
}
}
}
}