-2

所以我明天有这个任务,它是用 as3 在 Flash 中制作一个音频播放器。我根本不明白 as3。我有播放器工作的代码,因为我只是使用了我们在课堂上使用的相同代码,但我有点想把它变成我自己的。我创建了一个 Ipod 风格的播放器。首先,我希望前进按钮播放下一首歌曲。我将如何为此编写代码?Next 当一首歌曲播放时,我希望显示一个特定的图像。当下一首歌曲出现在下一张要显示的图像上时

这是我的歌曲代码

function playTrack(e:MouseEvent) :void {
    switch(e.target.name) {
        case "track1":
            trackToLoad = "audio/Don't Stop Believing.mp3";
            trackName = "Journey • Don't Stop Believing"
            break;
        case "track2":
            trackToLoad = "audio/Never Never Land.mp3";
            trackName = "Metallica • Never Never Land"
            break;
    ...

但不是只有一个停止和播放按钮和 10 个播放每首歌曲的按钮,我想要一个跳过按钮去下一首歌曲..

希望这是对一些帮助的足够信息谢谢

4

2 回答 2

2

Set your tracks up as an array of objects:

var track1:Object = {
  track: 'Don\'t stop believing',
  artist: 'Journey',
  file: 'dont_stop_believing.mp3'
};
var track2 //same as above
var tracks:Array = [track1, track2, ...];

You could really create a Track class, but it sounds like you aren't to that point yet.

Instead of making your playTrack function actually be the mouse event handler, you should separate it out so that it can be used universally no matter how the track begins to play (i.e. clicking on that track's button, clicking on the next button, or after the previous song ends). Write a separate function just to handle the mouse event (i.e. clickTrack()), which will call your playTrack() function.

Setting your tracks up within the array will allow you to keep note of the indices of each track (including the currentTrack) as a number. That way you can iterate through the tracks by just incrementing the currentTrack variable.

This way, you can set your playTrack() function up to take a trackNumber parameter (i.e. playTrack(1). Then just use that parameter to reference the index of the track you want to play within the tracks array. Remember that arrays are on a 0 index meaning that the first element is index [0], the second is [1], etc. So you'll either have to write your playTrack() function in that way, or convert by subtracting 1.

于 2012-10-22T18:22:19.150 回答
0

尝试将某种Track对象存储在索引数组中。您可以跟踪索引,并在用户单击skipback时更改它。该Track对象可以存储文件路径、曲目名称和您想要显示的艺术作品。当索引更改时,从您的数组中获取正确的曲目并更新播放器。

这是一个实际使用歌曲标题的示例。

于 2012-10-22T18:17:27.103 回答