bump libtool version
[swfdec.git] / libswfdec / swfdec_initialize.as
blob3fffa4ed633576185b89fe4637715aef4eaec563
1 /* Swfdec
2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 /*** GENERAL ***/
22 ASSetNative = ASnative (4, 0);
23 ASSetNativeAccessor = ASnative (4, 1);
25 /*** Object ***/
26 /* Only Flash extensions here, rest to swfdec_as_initialize.as */
28 Object.registerClass = ASnative(101, 8);
29 ASSetPropFlags (Object, null, 7);
31 /*** ASBROADCASTER ***/
33 function AsBroadcaster () { };
35 AsBroadcaster.broadcastMessage = ASnative(101, 12);
37 AsBroadcaster.addListener = function (x) {
38 this.removeListener (x);
39 this._listeners.push (x);
40 return true;
43 AsBroadcaster.removeListener = function (x) {
44 var l = this._listeners;
45 var i;
47 for (var i = 0; i < l.length; i++) {
48 if (l[i] == x) {
49 l.splice (i, 1);
50 return true;
53 return false;
56 AsBroadcaster.initialize = function (o) {
57 o.broadcastMessage = ASnative(101, 12);
58 o.addListener = AsBroadcaster.addListener;
59 o.removeListener = AsBroadcaster.removeListener;
60 o._listeners = [];
61 ASSetPropFlags(o, "broadcastMessage,addListener,removeListener,_listeners", 131);
63 ASSetPropFlags(AsBroadcaster, null, 131);
65 Key = { ALT: 18, BACKSPACE: 8, CAPSLOCK: 20, CONTROL: 17, DELETEKEY: 46,
66 DOWN: 40, END: 35, ENTER: 13, ESCAPE: 27, HOME: 36, INSERT: 45, LEFT: 37,
67 PGDN: 34, PGUP: 33, RIGHT: 39, SHIFT: 16, SPACE: 32, TAB: 9, UP: 38 };
68 ASSetNative(Key, 800, "getAscii,getCode,isDown");
69 AsBroadcaster.initialize(Key);
70 ASSetPropFlags(Key, null, 7);
72 /*** MOUSE ***/
74 Mouse = { };
75 Mouse.show = ASnative (5, 0);
76 Mouse.hide = ASnative (5, 1);
77 AsBroadcaster.initialize (Mouse);
78 ASSetPropFlags(Mouse, null, 7);
80 /*** STAGE ***/
82 Stage = { };
83 AsBroadcaster.initialize (Stage);
84 ASSetNativeAccessor (Stage, 666, "scaleMode,align,width,height", 1);
86 /*** LOADVARS ***/
88 function LoadVars () { };
90 LoadVars.prototype.contentType = "application/x-www-form-urlencoded";
92 LoadVars.prototype.load = ASnative (301, 0);
93 //LoadVars.prototype.send = ASnative (301, 1);
94 //LoadVars.prototype.sendAndLoad = ASnative (301, 2);
95 LoadVars.prototype.decode = ASnative (301, 3);
97 LoadVars.prototype.onLoad = function () {
100 LoadVars.prototype.onData = function (src) {
101 this.loaded = true;
102 if (src != null) {
103 this.decode (src);
104 this.onLoad (true);
105 } else {
106 this.onLoad (false);
110 LoadVars.prototype.toString = function () {
111 var str = null;
112 for (var x in this) {
113 if (str == null) {
114 str = escape(x) + "=" + escape(this[x]);
115 } else {
116 str += "&" + escape(x) + "=" + escape(this[x]);
119 return str;
122 LoadVars.prototype.getBytesLoaded = function () {
123 return this._bytesLoaded;
126 LoadVars.prototype.getBytesTotal = function () {
127 return this._bytesTotal;
130 ASSetPropFlags(LoadVars.prototype, null, 131);
132 /*** Sound ***/
134 Sound = ASconstructor (500, 16);
135 ASSetNative (Sound.prototype, 500, "stop,attachSound,start", 6);
137 /*** XMLNode ***/
139 XMLNode = ASconstructor (253, 0);
141 XMLNode.prototype.cloneNode = ASnative (253, 1);
142 XMLNode.prototype.removeNode = ASnative (253, 2);
143 XMLNode.prototype.insertBefore = ASnative (253, 3);
144 XMLNode.prototype.appendChild = ASnative (253, 4);
145 XMLNode.prototype.hasChildNodes = ASnative (253, 5);
146 XMLNode.prototype.toString = ASnative (253, 6);
147 XMLNode.prototype.getNamespaceForPrefix = ASnative (253, 7);
148 XMLNode.prototype.getPrefixForNamespace = ASnative (253, 8);
150 /*** XML ***/
152 XML = ASconstructor (253, 9);
154 XML.prototype = new XMLNode (1, "");
155 ASSetPropFlags (XML, "prototype", 3);
157 XML.prototype.load = ASnative (301, 0);
158 //XML.prototype.send = ASnative (301, 1);
159 //XML.prototype.sendAndLoad = ASnative (301, 2);
160 XML.prototype.createElement = ASnative (253, 10);
161 XML.prototype.createTextNode = ASnative (253, 11);
162 XML.prototype.parseXML = ASnative (253, 12);
164 XML.prototype.onLoad = function () {
167 // Note: handling of loaded is different here than in LoadVars
168 XML.prototype.onData = function (src) {
169 if (src != null) {
170 this.loaded = true;
171 this.parseXML (src);
172 this.onLoad (true);
173 } else {
174 this.loaded = false;
175 this.onLoad (false);
179 XML.prototype.getBytesLoaded = function () {
180 return this._bytesLoaded;
183 XML.prototype.getBytesTotal = function () {
184 return this._bytesTotal;
187 /*** System ***/
189 System = {};
190 System.capabilities = {};
191 System.capabilities.Query = ASnative (11, 0);
192 System.capabilities.Query ();
193 delete System.capabilities.Query;
195 /*** Color ***/
197 Color = function (target) {
198 this.target = target;
199 ASSetPropFlags (this, null, 7);
201 ASSetNative (Color.prototype, 700, "setRGB,setTransform,getRGB,getTransform");
202 ASSetPropFlags (Color.prototype, null, 7);
204 /* MovieClip */
206 MovieClip.prototype.meth = function (method) {
207 var lower = method.toLowerCase ();
208 if (lower == "post") {
209 return 2;
210 } else if (lower == "get") {
211 return 1;
212 } else {
213 return 0;
217 MovieClip.prototype.getURL = function (url, target, method) {
218 if (typeof (target) == "undefined")
219 target = ""; // undefined to empty string, even in version >= 7
221 var type = this.meth (method);
222 if (type == 0) {
223 getURL (url, target);
224 } else if (type == 1) {
225 getURL (url, target, "GET");
226 } else {
227 getURL (url, target, "POST");
231 // work around ming bug, causing loadVariables to be lower cased
232 MovieClip.prototype["loadVariables"] = function (url, method) {
233 var type = this.meth (method);
234 setTarget (this);
235 if (type == 0) {
236 loadVariables (url, this._target);
237 } else if (type == 1) {
238 loadVariables (url, this._target, "GET");
239 } else {
240 loadVariables (url, this._target, "POST");
242 setTarget ("");
245 // work around ming bug, causing loadMovie to be lower cased
246 MovieClip.prototype["loadMovie"] = function (url, method) {
247 var type = this.meth (method);
248 setTarget (this);
249 if (type == 0) {
250 loadMovie (url, this._target);
251 } else if (type == 1) {
252 loadMovie (url, this._target, "GET");
253 } else {
254 loadMovie (url, this._target, "POST");
256 setTarget ("");
259 MovieClip.prototype.attachMovie = ASnative (900, 0);
260 MovieClip.prototype.swapDepths = ASnative (900, 1);
261 MovieClip.prototype.hitTest = ASnative (900, 4);
262 MovieClip.prototype.getBounds = ASnative (900, 5);
263 MovieClip.prototype.getBytesTotal = ASnative (900, 6);
264 MovieClip.prototype.getBytesLoaded = ASnative (900, 7);
265 MovieClip.prototype.getDepth = ASnative (900, 10);
266 MovieClip.prototype.play = ASnative (900, 12);
267 MovieClip.prototype.stop = ASnative (900, 13);
268 MovieClip.prototype.nextFrame = ASnative (900, 14);
269 MovieClip.prototype.prevFrame = ASnative (900, 15);
270 MovieClip.prototype.gotoAndPlay = ASnative (900, 16);
271 MovieClip.prototype.gotoAndStop = ASnative (900, 17);
272 // work around ming bug, causing these two to be lower cased
273 MovieClip.prototype["duplicateMovieClip"] = ASnative (900, 18);
274 MovieClip.prototype["removeMovieClip"] = ASnative (900, 19);
275 MovieClip.prototype.startDrag = ASnative (900, 20);
276 MovieClip.prototype.stopDrag = ASnative (900, 21);
278 ASSetPropFlags (MovieClip.prototype, "getDepth", 128);
280 ASSetNative (MovieClip.prototype, 901, "6createEmptyMovieClip,6beginFill,6beginGradientFill,6moveTo,6lineTo,6curveTo,6lineStyle,6endFill,6clear");
281 ASSetPropFlags (MovieClip.prototype, null, 3);
283 /* TextField */
285 TextField = {};
287 /* TextFormat */
289 TextFormat = ASconstructor (110, 0);
291 /* TextField.Stylesheet */
293 TextField.StyleSheet = ASconstructor (113, 0);
295 TextField.StyleSheet.prototype._copy = function (o) {
296 if (typeof (o) != "object")
297 return null;
299 var o_new = {};
300 for (var prop in o) {
301 o_new[prop] = o[prop];
303 return o_new;
306 TextField.StyleSheet.prototype.clear = function () {
307 this._css = {};
308 this._styles = {};
311 TextField.StyleSheet.prototype.getStyle = function (name) {
312 return (this._copy (this._css[name]));
315 TextField.StyleSheet.prototype.setStyle = function (name, style) {
316 if (!this._css)
317 this._css = {};
319 this._css[name] = this._copy (style);
320 this.doTransform (name);
323 TextField.StyleSheet.prototype.getStyleNames = function () {
324 var tmp = this._css; /* ming bug? */
325 var names = [];
326 for (var prop in tmp) {
327 names.push (prop);
329 return names;
332 TextField.StyleSheet.prototype.doTransform = function (name) {
333 if (!this._styles) {
334 this._styles = {};
336 this._styles[name] = this.transform (this._css[name]);
339 TextField.StyleSheet.prototype.transform = function (style) {
340 if (style == null)
341 return null;
343 var format = new TextFormat ();
345 if (style.textAlign)
346 format.align = style.textAlign;
348 if (style.fontWeight == "bold") {
349 format.bold = true;
350 } else if (style.fontWeight == "normal") {
351 format.bold = false;
354 if (style.color) {
355 var tmp = this.parseColor (style.color);
356 if (tmp != null)
357 format.color = tmp;
360 format.display = style.display;
362 if (style.fontFamily)
363 format.font = this.parseCSSFontFamily (style.fontFamily);
365 if (style.textIndent)
366 format.indent = parseInt (style.textIndent);
368 if (style.fontStyle == "italic") {
369 format.italic = true;
370 } else if (style.fontStyle == "normal") {
371 format.italic = false;
374 if (style.kerning == "true") {
375 format.kerning = true;
376 } else if (style.kerning == "false") {
377 format.kerning = false;
378 } else {
379 format.kerning = parseInt (style.kerning);
382 if (style.leading)
383 format.leading = parseInt (style.leading);
385 if (style.marginLeft)
386 format.leftMargin = parseInt (style.marginLeft);
388 if (style.letterSpacing)
389 format.letterSpacing = parseInt (style.letterSpacing);
391 if (style.marginRight)
392 format.rightMargin = parseInt (style.marginRight);
394 if (style.fontSize) {
395 var tmp = parseInt (style.fontSize);
396 if (tmp > 0)
397 format.size = tmp;
400 if (style.textDecoration == "underline") {
401 format.underline = true;
402 } else if (style.textDecoration == "none") {
403 format.underline = false;
406 return format;
409 TextField.StyleSheet.prototype.parseCSS = function (css) {
410 var result = this.parseCSSInternal (css);
411 if (typeof (result) == "null")
412 return false;
414 if (!this._css)
415 this._css = {};
417 for (var prop in result) {
418 this._css[prop] = this._copy (result[prop]);
419 this.doTransform (prop);
422 return true;
425 TextField.StyleSheet.prototype.parse = TextField.StyleSheet.prototype.parseCSS;
427 TextField.StyleSheet.prototype.load = ASnative (301, 0);
429 TextField.StyleSheet.prototype.onLoad = function () {
432 TextField.StyleSheet.prototype.onData = function (src) {
433 if (src != null) {
434 var result = this.parse (src);
435 this.loaded = result;
436 this.onLoad (result);
437 } else {
438 this.onLoad (false);
442 TextField.StyleSheet.prototype.parseCSSInternal = ASnative (113, 101);
443 TextField.StyleSheet.prototype.parseCSSFontFamily = ASnative (113, 102);
444 TextField.StyleSheet.prototype.parseColor = ASnative (113, 103);
445 ASSetPropFlags (TextField.StyleSheet.prototype, null, 1027);
446 ASSetPropFlags (TextField, "StyleSheet", 1027);
448 /* Global Functions */
450 setInterval = ASnative (250, 0);
451 clearInterval = ASnative (250, 1);
452 setTimeout = ASnative(250, 2);
453 clearTimeout = clearInterval;
455 /*** OH THE HUMANITY ***/
457 o = null;
459 /*** GLOBAL PROPFLAGS */
461 ASSetPropFlags (this, null, 1, 6);