1
// Copyright (c) 2004 Divmod.
2
// See LICENSE for details.
5
// variables injected into the global namespace are:
12
var server = new XMLSocket();
14
var canvas = _root.createEmptyMovieClip('canvas', 0);
16
function sendEvent(evtTxt) {
17
server.send(evtTxt); }
19
// The flash movie can control which event handlers are installed.
20
// The following names should be defined in the movie's namespace:
29
Key.addListener(canvas);
30
canvas.onKeyDown = function() {
31
sendEvent('onKeyDown '+Key.getCode()); } }
34
canvas.onKeyUp = function() {
35
sendEvent('onKeyUp '+Key.getCode()); } }
38
canvas.onMouseDown = function() {
39
sendEvent('onMouseDown '+_root._xmouse+' '+_root._ymouse); } }
42
canvas.onMouseUp = function() {
43
sendEvent('onMouseUp '+_root._xmouse+' '+_root._ymouse); } }
46
canvas.onMouseMove = function() {
47
sendEvent('onMouseMove '+_root._xmouse+' '+_root._ymouse); } }
52
function extractList(nodes) {
54
for (i=0; i<nodes.length; i++) {
56
Number(nodes[i].attributes['v'])); }
59
function extractDict(nodes) {
61
for (i=0; i<nodes.length; i++) {
63
var val = nod.attributes['v'];
64
if (val == "matrixType") {
65
rv[nod.attributes['k']] = val; }
67
rv[nod.attributes['k']] = Number(val); } }
70
function extractGroup(path) {
71
var groupTarget = _root;
72
var segments = path.split('.');
73
for (var i = 0; i < segments.length; i++) {
74
groupTarget = groupTarget[segments[i]]; }
79
function reposition(canvas, x, y) {
80
canvas._x = Number(x);
81
canvas._y = Number(y); }
83
function rotate(canvas, angle) {
84
canvas._rotation = Number(angle); }
86
function alpha(canvas, percent) {
87
canvas._alpha = Number(percent); }
89
function scale(canvas, x, y) {
90
canvas._xscale = Number(x);
91
canvas._yscale = Number(y); }
93
function swapGroup(canvas, other) {
94
var groupTarget = extractGroup(other);
95
canvas.swapDepths(groupTarget); }
97
function swapInt(canvas, other) {
98
canvas.swapDepths(Number(other)); }
100
function gradient(canvas, type, colors, alphas, ratios, matrix) {
101
var cl = extractList(colors);
102
var al = extractList(alphas);
103
var ra = extractList(ratios);
104
var ma = extractDict(matrix);
105
canvas.beginGradientFill(
106
type, cl, al, ra, ma) }
108
function curve(canvas, controlX, controlY, anchorX, anchorY) {
115
function fill(canvas, rgb, alpha) {
116
canvas.beginFill(Number(rgb), Number(alpha)); }
118
function close(canvas) {
121
function move(canvas, x, y) {
122
canvas.moveTo(Number(x), Number(y)); }
124
function line(canvas, x, y) {
125
canvas.lineTo(Number(x), Number(y)); }
127
function pen(canvas, w, c, a) {
129
canvas.lineStyle(Number(w), Number(c), Number(a)) }
131
canvas.lineStyle(Number(w), Number(c)); }
133
canvas.lineStyle(Number(w)); }
135
canvas.lineStyle(); } }
138
function clear(canvas) {
143
function text(canvas, cookie, val, x, y, height, width) {
144
canvas.createTextField(
145
"T_" + cookie, Number(cookie),
146
Number(x), Number(y), Number(height), Number(width));
147
var T = canvas["T_" + cookie]
149
T.selectable = false;
150
// T.background = true;
151
// T.backgroundColor = 0xefefef;
154
function changeText(canvas, cookie, val) {
155
canvas["T_" + cookie].text = val; }
157
function moveText(canvas, cookie, x, y) {
158
var T = canvas["T_" + cookie];
162
function rotateText(canvas, cookie, angle) {
163
var A = Number(angle);
164
canvas["T_" + cookie]._rotation = A; }
166
function listFonts(canvas, identifier) {
167
var fonts = TextField.getFontList();
169
identifier + " " + fonts); }
171
function font(canvas, cookie, fn) {
172
var T = canvas["T_" + cookie];
173
var F = T.getTextFormat();
175
T.setTextFormat(F); }
177
function size(canvas, cookie, s) {
178
var T = canvas["T_" + cookie];
179
var F = T.getTextFormat();
181
T.setTextFormat(F); }
185
function group(canvas, cookie) {
186
canvas.createEmptyMovieClip('G_'+cookie, Number(cookie));
187
var G = canvas['G_'+cookie]; }
189
function setMask(canvas, otherCanvas) {
191
canvas.setMask(null); }
193
var G = extractGroup(otherCanvas);
194
canvas.setMask(G); } }
196
function setVisible(canvas, visible) {
197
if (visible == 'True') {
198
canvas._visible = true; }
200
canvas._visible = false; } }
204
function image(canvas, cookie, where) {
205
canvas.createEmptyMovieClip("I_"+cookie, Number(cookie));
206
var I = canvas["I_"+cookie];
207
I.loadMovie(where); }
209
function moveImage(canvas, cookie, x, y) {
210
var I = canvas["I_" + cookie];
214
function scaleImage(canvas, cookie, x, y) {
215
var I = canvas["I_" + cookie];
216
I._xscale = Number(x);
217
I._yscale = Number(y); }
219
function alphaImage(canvas, cookie, alpha) {
220
var I = canvas["I_" + cookie];
221
I._alpha = Number(alpha); }
223
function rotateImage(canvas, cookie, angle) {
224
var T = canvas["I_" + cookie];
225
T._rotation = Number(angle); }
230
function sound(canvas, cookie, where, streaming) {
232
canvas["S_"+cookie] = S;
233
S.loadSound(where, Boolean(streaming));
236
function playSound(canvas, cookie, offset, timesLoop) {
237
var S = canvas["S_"+cookie]
238
S.start(Number(offset), Number(timesLoop)); }
242
server.onXML = function(xml) {
243
xml = xml.firstChild;
244
var funcName = xml.attributes['n'];
245
var func = eval(funcName);
249
extractGroup(xml.attributes['t']));
251
for(i=0; i<xml.childNodes.length; i++) {
252
if (xml.childNodes[i].attributes['v']){
254
xml.childNodes[i].attributes['v']); }
257
xml.childNodes[i].childNodes[0].childNodes); } }
259
func.apply(groupTarget, parms); }
261
server.onConnect = function(success) {
264
"GET " + prefix + "canvas_socket/"+
266
" HTTP/1.0\r\n\r\n"); } }
268
server.connect(null, port);