|
1 | 1 | package { |
2 | | - import flash.display.MovieClip; |
3 | | - import flash.external.ExternalInterface; |
4 | | - import flash.utils.getQualifiedClassName; |
5 | | - import flash.utils.setTimeout; |
6 | | - |
7 | | - |
8 | | - public class Test extends MovieClip { |
9 | | - public function Test() { |
10 | | - log("ExternalInterface.available: " + repr(ExternalInterface.available)); |
11 | | - log("ExternalInterface.objectID: " + repr(ExternalInterface.objectID)); |
12 | | - |
13 | | - try { |
14 | | - ExternalInterface.addCallback("callMethodImmediately", function(name: String) { |
15 | | - log("callMethodImmediately called with " + arguments.length + " argument" + (arguments.length == 1 ? "" : "s")); |
16 | | - log(" " + repr(arguments, " ")); |
17 | | - try { |
18 | | - log(" call(" + name + ", ...) = " + repr(ExternalInterface.call.apply(null, arguments))); |
19 | | - } catch (e) { |
20 | | - log(" call(" + name + ", ...) = " + e); |
21 | | - } |
22 | | - }); |
23 | | - ExternalInterface.addCallback("callMethodWithDelay", function(name: String) { |
24 | | - log("callMethodWithDelay called with " + arguments.length + " argument" + (arguments.length == 1 ? "" : "s")); |
25 | | - log(" " + repr(arguments, " ")); |
26 | | - var args = arguments; |
27 | | - setTimeout(function() { |
28 | | - try { |
29 | | - log(" call(" + name + ", ...) = " + repr(ExternalInterface.call.apply(null, args))); |
30 | | - } catch (e) { |
31 | | - log(" call(" + name + ", ...) = " + e); |
32 | | - } |
33 | | - }, 1); |
34 | | - }); |
35 | | - ExternalInterface.addCallback("log", function() { |
36 | | - log("log called with " + arguments.length + " argument" + (arguments.length == 1 ? "" : "s")); |
37 | | - log(" " + repr(arguments, " ")); |
38 | | - }); |
39 | | - ExternalInterface.addCallback("returnAValue", function(value: *) { |
40 | | - log("returnAValue called with " + repr(value)); |
41 | | - log(" " + repr(arguments, " ")); |
42 | | - return value; |
43 | | - }); |
44 | | - ExternalInterface.addCallback("throwAnException", function() { |
45 | | - log("throwAnException called"); |
46 | | - throw new ArgumentError("Custom Argument Error!", 123); |
47 | | - }); |
48 | | - ExternalInterface.addCallback("setMarshallExceptions", function(value: Boolean) { |
49 | | - log("setMarshallExceptions called with " + repr(value)); |
50 | | - ExternalInterface.marshallExceptions = value; |
51 | | - }); |
52 | | - ExternalInterface.addCallback("addAnotherCallback", function(name: String, returnValue: *) { |
53 | | - log("addAnotherCallback called for " + repr(name) + " to return " + repr(returnValue)); |
54 | | - ExternalInterface.addCallback(name, function() { |
55 | | - log(name + " called"); |
56 | | - return returnValue; |
57 | | - }); |
58 | | - }); |
59 | | - } catch (e) { |
60 | | - log("Error adding callbacks: " + e); |
61 | | - } |
62 | | - } |
| 2 | + import flash.display.MovieClip; |
| 3 | + import flash.external.ExternalInterface; |
| 4 | + import flash.utils.getQualifiedClassName; |
| 5 | + import flash.utils.setTimeout; |
63 | 6 |
|
64 | | - function log(value: *) { |
65 | | - trace(value); |
66 | | - result.text += value + "\n"; |
67 | | - } |
68 | | - |
69 | | - function repr(value: *, indent: String = " ") { |
70 | | - if (value === undefined || value === null || value === true || value === false || value is Number) { |
71 | | - return value; |
72 | | - } else if (value is String) { |
73 | | - return escapeString(value); |
74 | | - } else if (value is Array) { |
75 | | - if (value.length == 0) { |
76 | | - return "[]"; |
77 | | - } else { |
78 | | - var result = "[\n"; |
79 | | - var nextIndent = indent + " "; |
80 | | - for (var i = 0; i < value.length; i++) { |
81 | | - result += nextIndent + repr(value[i], indent + nextIndent) + "\n"; |
82 | | - } |
83 | | - return result + indent + "]"; |
84 | | - } |
85 | | - } else { |
86 | | - var keys = []; |
87 | | - for (var key in value) { |
88 | | - keys.push(key); |
89 | | - } |
90 | | - keys.sort(); |
91 | | - |
92 | | - var result = getQualifiedClassName(value) + " {"; |
93 | | - |
94 | | - if (keys.length == 0) { |
95 | | - return result + "}"; |
96 | | - } else { |
97 | | - result += "\n"; |
98 | | - var nextIndent = indent + " "; |
99 | | - for (var i = 0; i < keys.length; i++) { |
100 | | - result += nextIndent + keys[i] + " = " + repr(value[keys[i]], nextIndent) + "\n"; |
101 | | - } |
102 | | - return result + indent + "}"; |
103 | | - } |
104 | | - } |
105 | | - } |
106 | | - |
107 | | - function escapeString(input: String): String { |
108 | | - var output:String = "\""; |
109 | | - for (var i:int = 0; i < input.length; i++) { |
110 | | - var char:String = input.charAt(i); |
111 | | - switch (char) { |
112 | | - case "\\": |
113 | | - output += "\\\\"; |
114 | | - break; |
115 | | - case "\"": |
116 | | - output += "\\\""; |
117 | | - break; |
118 | | - case "\n": |
119 | | - output += "\\n"; |
120 | | - break; |
121 | | - case "\r": |
122 | | - output += "\\r"; |
123 | | - break; |
124 | | - case "\t": |
125 | | - output += "\\t"; |
126 | | - break; |
127 | | - default: |
128 | | - output += char; |
129 | | - } |
130 | | - } |
131 | | - return output + "\""; |
132 | | - } |
133 | | - } |
134 | | - |
| 7 | + public class Test extends MovieClip { |
| 8 | + public function Test() { |
| 9 | + log("ExternalInterface.available: " + repr(ExternalInterface.available)); |
| 10 | + log("ExternalInterface.objectID: " + repr(ExternalInterface.objectID)); |
| 11 | + |
| 12 | + try { |
| 13 | + ExternalInterface.addCallback("callMethodImmediately", function(name: String) { |
| 14 | + log("callMethodImmediately called with " + arguments.length + " argument" + (arguments.length == 1 ? "" : "s")); |
| 15 | + log(" " + repr(arguments, " ")); |
| 16 | + try { |
| 17 | + log(" call(" + name + ", ...) = " + repr(ExternalInterface.call.apply(null, arguments))); |
| 18 | + } catch (e) { |
| 19 | + log(" call(" + name + ", ...) = " + e); |
| 20 | + } |
| 21 | + }); |
| 22 | + ExternalInterface.addCallback("callMethodWithDelay", function(name: String) { |
| 23 | + log("callMethodWithDelay called with " + arguments.length + " argument" + (arguments.length == 1 ? "" : "s")); |
| 24 | + log(" " + repr(arguments, " ")); |
| 25 | + var args = arguments; |
| 26 | + setTimeout(function() { |
| 27 | + try { |
| 28 | + log(" call(" + name + ", ...) = " + repr(ExternalInterface.call.apply(null, args))); |
| 29 | + } catch (e) { |
| 30 | + log(" call(" + name + ", ...) = " + e); |
| 31 | + } |
| 32 | + }, 1); |
| 33 | + }); |
| 34 | + ExternalInterface.addCallback("log", function() { |
| 35 | + log("log called with " + arguments.length + " argument" + (arguments.length == 1 ? "" : "s")); |
| 36 | + log(" " + repr(arguments, " ")); |
| 37 | + }); |
| 38 | + ExternalInterface.addCallback("returnAValue", function(value: *) { |
| 39 | + log("returnAValue called with " + repr(value)); |
| 40 | + log(" " + repr(arguments, " ")); |
| 41 | + return value; |
| 42 | + }); |
| 43 | + ExternalInterface.addCallback("throwAnException", function() { |
| 44 | + log("throwAnException called"); |
| 45 | + throw new ArgumentError("Custom Argument Error!", 123); |
| 46 | + }); |
| 47 | + ExternalInterface.addCallback("setMarshallExceptions", function(value: Boolean) { |
| 48 | + log("setMarshallExceptions called with " + repr(value)); |
| 49 | + ExternalInterface.marshallExceptions = value; |
| 50 | + }); |
| 51 | + ExternalInterface.addCallback("addAnotherCallback", function(name: String, returnValue: *) { |
| 52 | + log("addAnotherCallback called for " + repr(name) + " to return " + repr(returnValue)); |
| 53 | + ExternalInterface.addCallback(name, function() { |
| 54 | + log(name + " called"); |
| 55 | + return returnValue; |
| 56 | + }); |
| 57 | + }); |
| 58 | + } catch (e) { |
| 59 | + log("Error adding callbacks: " + e); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + function log(value: *) { |
| 64 | + trace(value); |
| 65 | + result.text += value + "\n"; |
| 66 | + } |
| 67 | + |
| 68 | + function repr(value: *, indent: String = " ") { |
| 69 | + if (value === undefined || value === null || value === true || value === false || value is Number) { |
| 70 | + return value; |
| 71 | + } else if (value is String) { |
| 72 | + return escapeString(value); |
| 73 | + } else if (value is Array) { |
| 74 | + if (value.length == 0) { |
| 75 | + return "[]"; |
| 76 | + } else { |
| 77 | + var result = "[\n"; |
| 78 | + var nextIndent = indent + " "; |
| 79 | + for (var i = 0; i < value.length; i++) { |
| 80 | + result += nextIndent + repr(value[i], indent + nextIndent) + "\n"; |
| 81 | + } |
| 82 | + return result + indent + "]"; |
| 83 | + } |
| 84 | + } else { |
| 85 | + var keys = []; |
| 86 | + for (var key in value) { |
| 87 | + keys.push(key); |
| 88 | + } |
| 89 | + keys.sort(); |
| 90 | + |
| 91 | + var result = getQualifiedClassName(value) + " {"; |
| 92 | + |
| 93 | + if (keys.length == 0) { |
| 94 | + return result + "}"; |
| 95 | + } else { |
| 96 | + result += "\n"; |
| 97 | + var nextIndent = indent + " "; |
| 98 | + for (var i = 0; i < keys.length; i++) { |
| 99 | + result += nextIndent + keys[i] + " = " + repr(value[keys[i]], nextIndent) + "\n"; |
| 100 | + } |
| 101 | + return result + indent + "}"; |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + function escapeString(input: String): String { |
| 107 | + var output:String = "\""; |
| 108 | + for (var i:int = 0; i < input.length; i++) { |
| 109 | + var char:String = input.charAt(i); |
| 110 | + switch (char) { |
| 111 | + case "\\": |
| 112 | + output += "\\\\"; |
| 113 | + break; |
| 114 | + case "\"": |
| 115 | + output += "\\\""; |
| 116 | + break; |
| 117 | + case "\n": |
| 118 | + output += "\\n"; |
| 119 | + break; |
| 120 | + case "\r": |
| 121 | + output += "\\r"; |
| 122 | + break; |
| 123 | + case "\t": |
| 124 | + output += "\\t"; |
| 125 | + break; |
| 126 | + default: |
| 127 | + output += char; |
| 128 | + } |
| 129 | + } |
| 130 | + return output + "\""; |
| 131 | + } |
| 132 | + } |
135 | 133 | } |
0 commit comments