Flash Can';在flex中嵌入声音的t形环 [Embed('sounds/music1.mp3')] 公共音乐1:课堂; [嵌入('sounds/music2.mp3')] 公共音乐2:课堂; [Embed('sounds/music3.mp3')] 公共音乐3类; 公共音乐:阵列; 公共指数:int; 公共函数完成():void{ stage.scaleMode=StageScaleMode.SHOW_ALL; stage.frameRate=32; 音乐=新数组(); 音乐。推送(新音乐1()); 音乐。推送(新音乐2()); music.push(新音乐3()); currentSongIndex=Math.floor(Math.random()*music.length); var playFirst:SoundAsset=music[currentSongIndex]作为SoundAsset; playFirst.addEventListener(Event.COMPLETE,songFinished); playirst.play(); } 公共函数PlaySongFromIndex(歌曲索引:int){ var playFirst:SoundAsset=music[currentSongIndex]作为SoundAsset; playFirst.addEventListener(Event.COMPLETE,songFinished); playirst.play(); } 公共功能已完成(e:事件){ if(当前歌曲索引

Flash Can';在flex中嵌入声音的t形环 [Embed('sounds/music1.mp3')] 公共音乐1:课堂; [嵌入('sounds/music2.mp3')] 公共音乐2:课堂; [Embed('sounds/music3.mp3')] 公共音乐3类; 公共音乐:阵列; 公共指数:int; 公共函数完成():void{ stage.scaleMode=StageScaleMode.SHOW_ALL; stage.frameRate=32; 音乐=新数组(); 音乐。推送(新音乐1()); 音乐。推送(新音乐2()); music.push(新音乐3()); currentSongIndex=Math.floor(Math.random()*music.length); var playFirst:SoundAsset=music[currentSongIndex]作为SoundAsset; playFirst.addEventListener(Event.COMPLETE,songFinished); playirst.play(); } 公共函数PlaySongFromIndex(歌曲索引:int){ var playFirst:SoundAsset=music[currentSongIndex]作为SoundAsset; playFirst.addEventListener(Event.COMPLETE,songFinished); playirst.play(); } 公共功能已完成(e:事件){ if(当前歌曲索引,flash,apache-flex,actionscript,Flash,Apache Flex,Actionscript,我正在尝试循环嵌入的音乐,但只播放第一首随机歌曲,然后是静默…无法理解为什么下一首歌曲不播放,有人能告诉我吗?在您测试的音乐的完成处理程序的条件中。长度(注意大写L)它一执行就会抛出一个错误。您还需要修复当前允许索引增量超过数组范围的测试(请记住,数组元素是0索引的) 另外,由于您没有从else条件调用playsongfromfromindex方法,因此程序大约每三次不会超过第一首歌曲一次 尝试使用以下内容更新代码: [Embed('sounds/music1.mp3')] public var

我正在尝试循环嵌入的音乐,但只播放第一首随机歌曲,然后是静默…无法理解为什么下一首歌曲不播放,有人能告诉我吗?

在您测试的
音乐的
完成
处理程序的条件中。长度
(注意大写L)它一执行就会抛出一个错误。您还需要修复当前允许索引增量超过数组范围的测试(请记住,数组元素是0索引的)

另外,由于您没有从
else
条件调用
playsongfromfromindex
方法,因此程序大约每三次不会超过第一首歌曲一次

尝试使用以下内容更新代码:

[Embed('sounds/music1.mp3')]
public var Music1:Class;

[Embed('sounds/music2.mp3')]
public var Music2:Class;

[Embed('sounds/music3.mp3')]
public var Music3:Class;

public var music:Array;
public var currentSongIndex:int;

    public function complete():void {

        stage.scaleMode = StageScaleMode.SHOW_ALL;
        stage.frameRate = 32;
        music = new Array();
        music.push(new Music1());
        music.push(new Music2());
        music.push(new Music3());

        currentSongIndex = Math.floor( Math.random() * music.length );
        var playFirst:SoundAsset = music[currentSongIndex] as SoundAsset;
        playFirst.addEventListener(Event.COMPLETE, songFinished);
        playFirst.play();
    }

    public function PlaySongFromIndex(songIndex:int){
        var playFirst:SoundAsset = music[currentSongIndex] as SoundAsset;
        playFirst.addEventListener(Event.COMPLETE, songFinished);
        playFirst.play();
    }

    public function songFinished(e:Event){
        if(currentSongIndex < music.Length){
            currentSongIndex++;
            PlaySongFromIndex(currentSongIndex);
        } else {
            currentSongIndex=0;
        }
    }
公共功能已完成(e:事件){
如果(当前歌曲索引
我改成了这首歌,但在第一首歌之后,下一首歌仍然无法播放。。。无法找出为什么您在控制台中看到任何错误?尝试在歌曲完整处理程序中放置跟踪语句或断点,以确保正在执行。实际上,请参阅更新的答案。您的条件是允许索引超出数组的范围,并且您正在测试music.Length而不是music.Length,这将在执行时立即抛出错误。
public function songFinished(e:Event){
    if(currentSongIndex < music.length - 1){
        currentSongIndex++;
    } else {
        currentSongIndex=0;
    }
    PlaySongFromIndex(currentSongIndex);
}