当我点击每首歌曲的相应按钮时,会出现以下错误。
SecurityError:错误#2000:没有活动的安全上下文。
没有歌曲播放。
我已经检查了MP3s文件夹的路径,但我找不到我做错了。
var songList:Array=new Array("Faster","Floofin","Healing Invitation","Leave The Light On","Lift Me Up","Looking Up","Shelter","Sparkles On Her Dress","Squirrel Map","TapTouch","Vancouver Transit","What_");
song1.addEventListener(MouseEvent.CLICK, chooseSong);
song2.addEventListener(MouseEvent.CLICK, chooseSong);
song3.addEventListener(MouseEvent.CLICK, chooseSong);
song4.addEventListener(MouseEvent.CLICK, chooseSong);
song5.addEventListener(MouseEvent.CLICK, chooseSong);
song6.addEventListener(MouseEvent.CLICK, chooseSong);
song7.addEventListener(MouseEvent.CLICK, chooseSong);
song8.addEventListener(MouseEvent.CLICK, chooseSong);
song9.addEventListener(MouseEvent.CLICK, chooseSong);
song10.addEventListener(MouseEvent.CLICK, chooseSong);
song11.addEventListener(MouseEvent.CLICK, chooseSong);
song12.addEventListener(MouseEvent.CLICK, chooseSong);
for (var i = 0; i < songList.length; i++){
var str:String = songList[i] as String;
str = str.replace(".mp3","");
var clip = this["song"+(i+1)].title;
clip.text = str;
}
function chooseSong(e:MouseEvent):void{
switch(e.currentTarget.name){
case "song1":
currSong = "../MP3s/"+songList[0] as String;
break;
case "song2":
currSong = "../MP3s/"+songList[1] as String;
break;
case "song3":
currSong = "../MP3s/"+songList[2] as String;
break;
case "song4":
currSong = "../MP3s/"+songList[3] as String;
break;
case "song5":
currSong = "../MP3s/"+songList[4] as String;
break;
case "song6":
currSong = "../MP3s/"+songList[5] as String;
break;
case "song7":
currSong = "../MP3s/"+songList[6] as String;
break;
case "song8":
currSong = "../MP3s/"+songList[7] as String;
break;
case "song9":
currSong = "../MP3s/"+songList[8] as String;
break;
case "song10":
currSong = "../MP3s/"+songList[9] as String;
break;
case "song11":
currSong = "../MP3s/"+songList[10] as String;
break;
case "song12":
currSong = "../MP3s/"+songList[11] as String;
break;
}
if(snd != null){
channel.stop();
}
snd = new Sound();
snd.load(new URLRequest(currSong));
channel = new SoundChannel;
trans = new SoundTransform(currVol, currPan);
channel = snd.play();
channel.soundTransform = trans;
nowPlaying.visible = true;
snd.addEventListener(Event.ID3, id3Handler);
}
我在CS5.5中使用Action Script 3
编辑:我已经看过类似问题的答案,但没有任何运气由于
答案 0 :(得分:1)
加载外部资源时,最好还为错误事件添加事件监听器,因此如果出现问题,您就会知道原因。即使您检查了mp3的路径,它仍然可能是错误的。要真正检查您的路径是否正确,您需要添加一个IO_Error事件侦听器,如下所示:
snd = new Sound();
snd.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
snd.load(new URLRequest(currSong));
function onIoError(evt:IOErrorEvent):void {
trace("io Error: " + evt.text);
}
AS3文档中还有一个关于您可以在Sound对象上收听的事件的示例。 http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html#includeExamplesSummary