神魂顛倒論壇logo

icon
首頁Adobe Animate CCActionScript討論 → [求助]200首flash音樂隨機播放、設定結束時間

雷射溶脂 | 瘦小腹 | 植髮 | 眼袋 | 玻尿酸 | 電波拉皮 | Flash | 購物車 | Flash Player 11.2 | 豐胸 |

下一主題 上一主題


[求助]200首flash音樂隨機播放、設定結束時間


[求助]200首flash音樂隨機播放、設定結束時間 簡版






我做了200首的音樂flash,但是每次要聽音樂,都要一個一個打開太麻煩,想問有沒有可以將200首連接在一個flash並且隨機播放,因為晚上8點後都要做別的事,所以要如何設定播放到晚上8點結束



購物車 | 回到頂部

簡版






送?你一? ?,ArraySound
用法:var sound:ArraySound = new ArraySound();
sound.push("run.mp3");
sound.push("movbg.mp3");
sound.type = ArraySound.TYPE_QUEUE;
sound.play();
以下內容為程式語法:

1 package lerry.sound {
2     import flash.events.Event;
3     import flash.media.Sound;
4     import flash.media.SoundChannel;
5     import flash.net.URLRequest;
6     
7     /**
8      * ...
9      * @author lerry
10      */
11     public class ArraySound {
12         private var _arr:Array;
13         private var _index:int;
14         private var _sound:Sound;
15         private var _channel:SoundChannel;
16         private var _type:String;
17         
18         /**
19          * ?机播放
20          */
21         public static const TYPE_RANDOM:String = "random";
22         /**
23          * ?序播放
24          */
25         public static const TYPE_QUEUE:String = "queue";
26         
27         
28         public function ArraySound() {
29             _arr = [];
30             _index = 0;
31             type = TYPE_RANDOM;
32         }
33         public function set type(value:String):void {
34             _type = value;
35         }
36         public function get type():String {
37             return _type;
38         }
39         
40         /**
41          * ??音url?入??
42          * @param    soundurl
43          */
44         public function push(soundurl:String):void {
45             _arr.push(soundurl);
46         }
47         
48         /**
49          * ?用此方法?始播放
50          */
51         public function play():void {
52             if (type == TYPE_RANDOM) {
53                 _index = int(Math.random() * (_arr.length));
54                 trace(_index);
55             }
56             _sound = new Sound(new URLRequest(_arr[_index]));
57             _sound.addEventListener(Event.COMPLETE, onLoadSoundComplete);
58         }
59         /**
60          * ?音加?完成后
61          * @param    e
62          */
63         private function onLoadSoundComplete(e:Event):void {
64             _sound.removeEventListener(Event.COMPLETE, onLoadSoundComplete);
65             _channel = _sound.play();
66             _channel.addEventListener(Event.SOUND_COMPLETE, onPlaySoundComplete);
67         }
68         /**
69          * ?音播放完成后
70          * @param    e
71          */
72         private function onPlaySoundComplete(e:Event):void {
73             _channel.removeEventListener(Event.SOUND_COMPLETE, onPlaySoundComplete);
74             _channel = null;
75             _sound = null;
76             
77             if (_type == TYPE_RANDOM) {
78                 play();
79             }
80             if (_type == TYPE_QUEUE) {
81                 _index++;
82                 if (_index > _arr.length - 1) {
83                     _index = 0;
84                 }
85                 play();
86             }
87         }
88     
89     }
90
91 }









Flash Player 12 | 回到頂部
下一主題 上一主題