AS3循环播放多个音乐

 1 package  
 2 {
 3     import flash.display.Sprite;
 4     import flash.events.Event;
 5     import flash.events.KeyboardEvent;
 6     import flash.media.Sound;
 7     import flash.media.SoundChannel;
 8     import flash.net.URLRequest;
 9     /**
10      * ...
11      * @author gangzi
12      */
13     public class LoopMore extends Sprite
14     {
15         private var music_array:Array;
16         private var music_index:uint;
17         private var urlrequest:URLRequest;
18         private var sound:Sound;
19         private var soundchannel:SoundChannel;
20         
21         public function LoopMore() 
22         {
23             init();
24         }
25         
26         private function init():void
27         {
28             music_array        = new Array();
29             music_index        = 0;
30             urlrequest        = new URLRequest();
31             sound            = new Sound();
32             soundchannel    = new SoundChannel();
33             
34             music_array[0]  = "1.mp3";
35             music_array[1]    = "2.mp3";
36             music_array[2]    = "3.mp3";
37             
38             loadmusic();
39         }
40         
41         private function loadmusic():void
42         {
43             urlrequest.url = music_array[music_index];
44             sound           = new Sound();
45             sound.load(urlrequest);
46             trace("Load start");
47             sound.addEventListener(Event.COMPLETE, startPlay);
48         }
49         
50         private function startPlay(e:Event):void
51         {
52             trace("Play start");
53             soundchannel = sound.play();
54             soundchannel.addEventListener(Event.SOUND_COMPLETE,playEnd);
55         }
56         
57         private function playEnd(e:Event):void
58         {
59             trace("Play End");
60             music_index = (music_index < music_array.length - 1) ? music_index + 1:music_index = 0;
61             loadmusic();
62         }
63         
64     }
65 
66 }

你可能感兴趣的:(.net,Flash,音乐)