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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
<html>
<head>
<title>SoundManager Demo</title>
<meta name="robots" content="noindex" />
<style type="text/css">
html, body {
margin:0px;
padding:0px;
}
body {
color:#fff;
font-size:75%;
text-shadow:0 0 0 #fff; /* Safari nonsense */
font-family:verdana,arial,tahoma,"sans serif";
}
h1, h2, h3 {
font:lighter 3em "Helvetica Neue Light","Helvetica Neue",georgia,"times new roman","Arial Rounded MT Bold",helvetica,verdana,tahoma,arial,"sans serif";
font-weight:normal;
margin-bottom:0px;
}
h1 {
margin-top:0px;
}
h1, h2 {
letter-spacing:-1px; /* zomg web x.0! ;) */
}
h2 {
font-size:2em;
margin-top:0px;
color:#fff;
}
h2 span {
text-indent:1em;
font-family:verdana,tahoma,arial;
font-size:small;
}
p {
position:absolute;
left:1em;
bottom:0px;
font-size:x-small;
opacity:0.5;
}
#instructions {
position:absolute;
left:1em;
top:0px;
}
#canvas {
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
overflow:hidden;
}
#horizon {
position:relative;
height:50%;
background:transparent url(bg-sky.png) 0px 0px repeat-x;
}
#land {
position:absolute;
bottom:0px;
left:0px;
width:100%;
height:50%;
border-top:1px solid #339933;
margin-bottom:0px;
background:#669966 url(bg-land.png) 0px 0px repeat-x;
}
#content {
position:relative;
border-top:1px solid #ccc;
}
#cursor-shade {
position:absolute;
left:-100px;
top:-100px;
margin:0px 0px 0px -2px;
width:20px;
height:24px;
opacity:0.75;
}
#sun {
position:absolute;
top:50%;
width:100%;
height:128px;
margin-top:-66px;
background:transparent url(sun-test.png) 50% 0px no-repeat;
display:none;
}
.dot {
position:absolute;
width:32px;
height:32px;
}
#overlay {
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
cursor:url(cursor-11.cur),default;
}
</style>
<script type="text/javascript" src="../../script/soundmanager2-nodebug-jsmin.js"></script>
<script type="text/javascript">
function _id(sID) {return document.getElementById(sID);}
function Cursor() {
var self = this;
this.o = null;
this.offX = 20;
this.offY = 40;
this.screenX = null;
this.screenY = null;
this.screenXHalf = null;
this.screenYHalf = null;
this.lastCursor = null;
this.cursorRange = 9;
this.oDots = _id('dots');
this.painting = 0;
this.sounds = [];
this.soundIndex = 0;
this.soundTimer = null;
this.oDot = document.createElement('img');
this.oDot.className = 'dot';
this.oDot.src = 'dot.png';
this.refreshCoords = function() {
self.screenX = (window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth);
self.screenY = (window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight);
self.screenXHalf = parseInt(self.screenX/2);
self.screenYHalf = parseInt(self.screenY/2);
}
this.mousedown = function(e) {
self.painting = true;
return false;
}
this.mouseup = function(e) {
self.painting = false;
return false;
}
this.mousemove = function(e) {
var evt = e?e:event;
var x = evt.clientX;
var y = evt.clientY;
var xHalf = self.screenXHalf;
var yHalf = self.screenYHalf;
var scaleX = (x>xHalf?(x-xHalf)/xHalf:-((xHalf-x)/xHalf));
var scaleY = (y>yHalf?(y-yHalf)/yHalf:0);
var xScale = (self.offX*scaleY)*scaleX;
var yScale = self.offY*scaleY;
var cursor = parseInt(self.cursorRange*scaleY);
if (cursor != self.lastCursor) {
var curString = 'cursor-'+(Math.min(11,cursor+3))+'.cur';
document.documentElement.style.cursor = 'url("'+curString+'"),default';
_id('overlay').style.cursor = 'url("'+curString+'"),default';
self.lastCursor = cursor;
}
var xDiff = (x+xScale);
self.o.style.left = (xDiff)+'px';
self.o.style.top = (y+yScale)+'px';
self.o.style.width = ((20*scaleY)+'px');
self.o.style.height = ((24*scaleY)+'px');
self.o.style.opacity = Math.max((scaleY-0.33),0.33);
if (self.painting && scaleY>0) self.paint(x,y,scaleX,scaleY);
return false;
}
this.paint = function(x,y,scaleX,scaleY) {
var oD = self.oDot.cloneNode(false);
var size = 32*scaleY;
oD.style.left = (x-size)+'px';
oD.style.top = (y-size)+'px';
oD.style.width = (size+'px');
oD.style.height = (size+'px');
oD.style.opacity = Math.min(1,Math.max(scaleY*1.5,0.1));
self.oDots.appendChild(oD);
// var sID = self.sounds[0].sID;
if (!self.soundTimer) {
// self.soundTimer = window.setTimeout(function(){soundManager.play(sID,{volume:100*scaleY,pan:100*scaleX});self.soundTimer=null;},20);
self.sounds[Math.random()>0.5?1:0].play({pan:100*scaleX,volume:100*scaleY});
}
// if (self.soundIndex++>=self.sounds.length-1) self.soundIndex = 0;
}
this.createSounds = function() {
self.sounds[0] = soundManager.createSound('paint','../animation/audio/fingerplop.mp3');
self.sounds[1] = soundManager.createSound('paint2','../animation/audio/fingerplop2.mp3');
}
this.createSounds();
this.o = _id('cursor-shade');
this.refreshCoords();
window.onresize = this.refreshCoords;
_id('overlay').onmousedown = this.mousedown;
_id('overlay').onmouseup = this.mouseup;
document.onmousemove = this.mousemove;
}
var cursor = null;
var sounds = [];
soundManager.allowPolling = false;
function doEvil() {
// HIGHLY EXPERIMENTAL (and dangerous) optimation testing - attempting to override Flash's ExternalInterface JS. :D - The below may have only been relevant to Flash 8.
if (typeof window.__flash__argumentsToXML !== 'undefined') {
window.__flash__argumentsToXML = function(obj,index) {
var s = ["<arguments>"];
for (var i=index, j=obj.length; i<j; i++) {
s[s.length] = __flash__toXML(obj[i]);
}
s[s.length] = "</arguments>";
// console.log('argumentsToXML: '+s.length+' items');
return s.join('');
}
window.__flash__arrayToXML = function(obj) {
var s = ["<array>"];
for (var i=0,j=obj.length; i<j; i++) {
s[s.length] = "<property id=\"" + i + "\">" + __flash__toXML(obj[i]) + "</property>";
}
s[s.length] = "</array>";
// console.log('arrayToXML: '+s.length+' items');
return s.join('');
}
window.__flash__escapeXML = function(s) {
// console.log('escapeXML'); // '+s.length);
return s; // s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
}
window.__flash__objectToXML = function(obj) {
console.log('objectToXML');
var s = ["<object>"];
for (var prop in obj) {
s[s.length] = "<property id=\"" + prop + "\">" + __flash__toXML(obj[prop]) + "</property>";
}
s[s.length] = "</object>";
return s.join('');
}
window.__flash__toXML = function(value) {
// console.log('toXML');
var type = typeof(value);
if (type == "string") {
return "<string>" + __flash__escapeXML(value) + "</string>";
} else if (type == "undefined") {
return "<undefined/>";
} else if (type == "number") {
return "<number>" + value + "</number>";
} else if (value == null) {
return "<null/>";
} else if (type == "boolean") {
return value ? "<true/>" : "<false/>";
} else if (value instanceof Date) {
return "<date>" + value.getTime() + "</date>";
} else if (value instanceof Array) {
return __flash__arrayToXML(value);
} else if (type == "object") {
return __flash__objectToXML(value);
} else {
return "<null/>"; //???
}
}
// this one non-IE, only?
if (!navigator.userAgent.match(/MSIE/i)) {
window.__flash__request.prototype = function(name) {
return "<invoke name=\"" + name + "\" returntype=\"javascript\">" + __flash__argumentstoXML(arguments, 1) + "</invoke>";
}
}
}
}
function doInit() {
doEvil(); // NOTE: highly experimental, only a performance test; probably doesn't apply to Flash 9, and/or does nothing, or bad things.
cursor = new Cursor();
}
soundManager.flashVersion = 9;
soundManager.url = '../../swf/';
soundManager.useHighPerformance = true;
soundManager.wmode = 'transparent';
soundManager.debugMode = false;
soundManager.onload = doInit;
</script>
</head>
<body>
<div>
<div id="canvas">
<div id="horizon"></div>
<div id="land">
<div id="content">
</div>
</div>
<div id="sun"></div>
<div id="dots"></div>
<img id="cursor-shade" src="cursor-shadow.png" alt="" />
</div>
<div id="instructions">
<h1>SoundManager 2: JS/DOM + Sound Demo</h1>
<h2>Heavy DOM manipulation + Javascript Sound <span>(see code for experimental ideas)</code></h2>
</div>
<p>Click and drag to draw.. Noisily.</p>
<div id="overlay"></div>
</div>
</body>
</html>
|