forked from Draknek/Pongtinental
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudio.as
125 lines (89 loc) · 2.48 KB
/
Audio.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package
{
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.SharedObject;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
public class Audio
{
[Embed(source="audio/music.mp3")] public static var MUSIC:Class;
private static var sounds:Object = {};
private static var _mute:Boolean = false;
private static var so:SharedObject;
private static var menuItem:ContextMenuItem;
public static var music:Sound;
public static function init (o:InteractiveObject):void
{
// Setup
/*so = SharedObject.getLocal("audio");
_mute = so.data.mute;
addContextMenu(o);
if (o.stage) {
addKeyListener(o.stage);
} else {
o.addEventListener(Event.ADDED_TO_STAGE, stageAdd);
}*/
// Create sounds
music = new MUSIC;
}
/*public static function play (sound:String):void
{
if (_mute) return;
if (sound == "die") {
if (dieShuffle.length == 0) {
dieShuffle.push(1,2,3,4,5,6,7,8,9,10,11);
FP.shuffle(dieShuffle);
}
sound = "die" + dieShuffle.pop();
music.stop();
}
if (sounds[sound]) {
var volume:Number = 1.0;
if (sound == "scrape") {
volume = 0.7 + Math.random()*0.1;
}
sounds[sound].play(volume);
}
}*/
// Getter and setter for mute property
public static function get mute (): Boolean { return _mute; }
public static function set mute (newValue:Boolean): void
{
if (_mute == newValue) return;
_mute = newValue;
menuItem.caption = _mute ? "Unmute" : "Mute";
so.data.mute = _mute;
so.flush();
}
// Implementation details
private static function stageAdd (e:Event):void
{
addKeyListener(e.target.stage);
}
private static function addContextMenu (o:InteractiveObject):void
{
var menu:ContextMenu = o.contextMenu || new ContextMenu;
menu.hideBuiltInItems();
menuItem = new ContextMenuItem(_mute ? "Unmute" : "Mute");
menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuListener);
menu.customItems.push(menuItem);
o.contextMenu = menu;
}
private static function addKeyListener (stage:Stage):void
{
//stage.addEventListener(KeyboardEvent.KEY_DOWN, keyListener);
}
private static function keyListener (e:KeyboardEvent):void
{
if (e.keyCode == Key.M) {
mute = ! mute;
}
}
private static function menuListener (e:ContextMenuEvent):void
{
mute = ! mute;
}
}
}