Section 1
//MD5 (com.adobe.crypto.MD5)
package com.adobe.crypto {
import flash.utils.*;
import com.adobe.utils.*;
public class MD5 {
public static var digest:ByteArray;
private static function ff(a:int, b:int, c:int, d:int, x:int, s:int, t:int):int{
return (transform(f, a, b, c, d, x, s, t));
}
private static function f(x:int, y:int, z:int):int{
return (((x & y) | (~(x) & z)));
}
private static function g(x:int, y:int, z:int):int{
return (((x & z) | (y & ~(z))));
}
private static function h(x:int, y:int, z:int):int{
return (((x ^ y) ^ z));
}
private static function i(x:int, y:int, z:int):int{
return ((y ^ (x | ~(z))));
}
private static function transform(func:Function, a:int, b:int, c:int, d:int, x:int, s:int, t:int):int{
var tmp:int = (((a + int(func(b, c, d))) + x) + t);
return ((IntUtil.rol(tmp, s) + b));
}
private static function hh(a:int, b:int, c:int, d:int, x:int, s:int, t:int):int{
return (transform(h, a, b, c, d, x, s, t));
}
public static function hash(s:String):String{
var ba:ByteArray = new ByteArray();
ba.writeUTFBytes(s);
return (hashBinary(ba));
}
private static function createBlocks(s:ByteArray):Array{
var blocks:Array = new Array();
var len:int = (s.length * 8);
var mask = 0xFF;
var i:int;
while (i < len) {
blocks[int((i >> 5))] = (blocks[int((i >> 5))] | ((s[(i / 8)] & mask) << (i % 32)));
i = (i + 8);
};
blocks[int((len >> 5))] = (blocks[int((len >> 5))] | (128 << (len % 32)));
blocks[int(((((len + 64) >>> 9) << 4) + 14))] = len;
return (blocks);
}
public static function hashBinary(s:ByteArray):String{
var aa:int;
var bb:int;
var cc:int;
var dd:int;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
var x:Array = createBlocks(s);
var len:int = x.length;
var i:int;
while (i < len) {
aa = a;
bb = b;
cc = c;
dd = d;
a = ff(a, b, c, d, x[int((i + 0))], 7, -680876936);
d = ff(d, a, b, c, x[int((i + 1))], 12, -389564586);
c = ff(c, d, a, b, x[int((i + 2))], 17, 606105819);
b = ff(b, c, d, a, x[int((i + 3))], 22, -1044525330);
a = ff(a, b, c, d, x[int((i + 4))], 7, -176418897);
d = ff(d, a, b, c, x[int((i + 5))], 12, 1200080426);
c = ff(c, d, a, b, x[int((i + 6))], 17, -1473231341);
b = ff(b, c, d, a, x[int((i + 7))], 22, -45705983);
a = ff(a, b, c, d, x[int((i + 8))], 7, 1770035416);
d = ff(d, a, b, c, x[int((i + 9))], 12, -1958414417);
c = ff(c, d, a, b, x[int((i + 10))], 17, -42063);
b = ff(b, c, d, a, x[int((i + 11))], 22, -1990404162);
a = ff(a, b, c, d, x[int((i + 12))], 7, 1804603682);
d = ff(d, a, b, c, x[int((i + 13))], 12, -40341101);
c = ff(c, d, a, b, x[int((i + 14))], 17, -1502002290);
b = ff(b, c, d, a, x[int((i + 15))], 22, 1236535329);
a = gg(a, b, c, d, x[int((i + 1))], 5, -165796510);
d = gg(d, a, b, c, x[int((i + 6))], 9, -1069501632);
c = gg(c, d, a, b, x[int((i + 11))], 14, 643717713);
b = gg(b, c, d, a, x[int((i + 0))], 20, -373897302);
a = gg(a, b, c, d, x[int((i + 5))], 5, -701558691);
d = gg(d, a, b, c, x[int((i + 10))], 9, 38016083);
c = gg(c, d, a, b, x[int((i + 15))], 14, -660478335);
b = gg(b, c, d, a, x[int((i + 4))], 20, -405537848);
a = gg(a, b, c, d, x[int((i + 9))], 5, 568446438);
d = gg(d, a, b, c, x[int((i + 14))], 9, -1019803690);
c = gg(c, d, a, b, x[int((i + 3))], 14, -187363961);
b = gg(b, c, d, a, x[int((i + 8))], 20, 1163531501);
a = gg(a, b, c, d, x[int((i + 13))], 5, -1444681467);
d = gg(d, a, b, c, x[int((i + 2))], 9, -51403784);
c = gg(c, d, a, b, x[int((i + 7))], 14, 1735328473);
b = gg(b, c, d, a, x[int((i + 12))], 20, -1926607734);
a = hh(a, b, c, d, x[int((i + 5))], 4, -378558);
d = hh(d, a, b, c, x[int((i + 8))], 11, -2022574463);
c = hh(c, d, a, b, x[int((i + 11))], 16, 1839030562);
b = hh(b, c, d, a, x[int((i + 14))], 23, -35309556);
a = hh(a, b, c, d, x[int((i + 1))], 4, -1530992060);
d = hh(d, a, b, c, x[int((i + 4))], 11, 1272893353);
c = hh(c, d, a, b, x[int((i + 7))], 16, -155497632);
b = hh(b, c, d, a, x[int((i + 10))], 23, -1094730640);
a = hh(a, b, c, d, x[int((i + 13))], 4, 681279174);
d = hh(d, a, b, c, x[int((i + 0))], 11, -358537222);
c = hh(c, d, a, b, x[int((i + 3))], 16, -722521979);
b = hh(b, c, d, a, x[int((i + 6))], 23, 76029189);
a = hh(a, b, c, d, x[int((i + 9))], 4, -640364487);
d = hh(d, a, b, c, x[int((i + 12))], 11, -421815835);
c = hh(c, d, a, b, x[int((i + 15))], 16, 530742520);
b = hh(b, c, d, a, x[int((i + 2))], 23, -995338651);
a = ii(a, b, c, d, x[int((i + 0))], 6, -198630844);
d = ii(d, a, b, c, x[int((i + 7))], 10, 1126891415);
c = ii(c, d, a, b, x[int((i + 14))], 15, -1416354905);
b = ii(b, c, d, a, x[int((i + 5))], 21, -57434055);
a = ii(a, b, c, d, x[int((i + 12))], 6, 1700485571);
d = ii(d, a, b, c, x[int((i + 3))], 10, -1894986606);
c = ii(c, d, a, b, x[int((i + 10))], 15, -1051523);
b = ii(b, c, d, a, x[int((i + 1))], 21, -2054922799);
a = ii(a, b, c, d, x[int((i + 8))], 6, 1873313359);
d = ii(d, a, b, c, x[int((i + 15))], 10, -30611744);
c = ii(c, d, a, b, x[int((i + 6))], 15, -1560198380);
b = ii(b, c, d, a, x[int((i + 13))], 21, 1309151649);
a = ii(a, b, c, d, x[int((i + 4))], 6, -145523070);
d = ii(d, a, b, c, x[int((i + 11))], 10, -1120210379);
c = ii(c, d, a, b, x[int((i + 2))], 15, 718787259);
b = ii(b, c, d, a, x[int((i + 9))], 21, -343485551);
a = (a + aa);
b = (b + bb);
c = (c + cc);
d = (d + dd);
i = (i + 16);
};
digest = new ByteArray();
digest.writeInt(a);
digest.writeInt(b);
digest.writeInt(c);
digest.writeInt(d);
digest.position = 0;
return ((((IntUtil.toHex(a) + IntUtil.toHex(b)) + IntUtil.toHex(c)) + IntUtil.toHex(d)));
}
private static function gg(a:int, b:int, c:int, d:int, x:int, s:int, t:int):int{
return (transform(g, a, b, c, d, x, s, t));
}
private static function ii(a:int, b:int, c:int, d:int, x:int, s:int, t:int):int{
return (transform(i, a, b, c, d, x, s, t));
}
public static function hashBytes(s:ByteArray):String{
return (hashBinary(s));
}
}
}//package com.adobe.crypto
Section 2
//PNGEncoder (com.adobe.images.PNGEncoder)
package com.adobe.images {
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
public class PNGEncoder {
private static var crcTableComputed:Boolean = false;
private static var crcTable:Array;
private static function writeChunk(png:ByteArray, type:uint, data:ByteArray):void{
var c:uint;
var n:uint;
var k:uint;
if (!crcTableComputed){
crcTableComputed = true;
crcTable = [];
n = 0;
while (n < 0x0100) {
c = n;
k = 0;
while (k < 8) {
if ((c & 1)){
c = uint((uint(3988292384) ^ uint((c >>> 1))));
} else {
c = uint((c >>> 1));
};
k++;
};
crcTable[n] = c;
n++;
};
};
var len:uint;
if (data != null){
len = data.length;
};
png.writeUnsignedInt(len);
var p:uint = png.position;
png.writeUnsignedInt(type);
if (data != null){
png.writeBytes(data);
};
var e:uint = png.position;
png.position = p;
c = 4294967295;
var i:int;
while (i < (e - p)) {
c = uint((crcTable[((c ^ png.readUnsignedByte()) & uint(0xFF))] ^ uint((c >>> 8))));
i++;
};
c = uint((c ^ uint(4294967295)));
png.position = e;
png.writeUnsignedInt(c);
}
public static function encode(img:BitmapData):ByteArray{
var p:uint;
var j:int;
var png:ByteArray = new ByteArray();
png.writeUnsignedInt(2303741511);
png.writeUnsignedInt(218765834);
var IHDR:ByteArray = new ByteArray();
IHDR.writeInt(img.width);
IHDR.writeInt(img.height);
IHDR.writeUnsignedInt(134610944);
IHDR.writeByte(0);
writeChunk(png, 1229472850, IHDR);
var IDAT:ByteArray = new ByteArray();
var i:int;
while (i < img.height) {
IDAT.writeByte(0);
if (!img.transparent){
j = 0;
while (j < img.width) {
p = img.getPixel(j, i);
IDAT.writeUnsignedInt(uint((((p & 0xFFFFFF) << 8) | 0xFF)));
j++;
};
} else {
j = 0;
while (j < img.width) {
p = img.getPixel32(j, i);
IDAT.writeUnsignedInt(uint((((p & 0xFFFFFF) << 8) | (p >>> 24))));
j++;
};
};
i++;
};
IDAT.compress();
writeChunk(png, 1229209940, IDAT);
writeChunk(png, 1229278788, null);
return (png);
}
}
}//package com.adobe.images
Section 3
//JSON (com.adobe.serialization.json.JSON)
package com.adobe.serialization.json {
public class JSON {
public static function decode(s:String){
var decoder:JSONDecoder = new JSONDecoder(s);
return (decoder.getValue());
}
public static function encode(o:Object):String{
var encoder:JSONEncoder = new JSONEncoder(o);
return (encoder.getString());
}
}
}//package com.adobe.serialization.json
Section 4
//JSONDecoder (com.adobe.serialization.json.JSONDecoder)
package com.adobe.serialization.json {
public class JSONDecoder {
private var value;
private var tokenizer:JSONTokenizer;
private var token:JSONToken;
public function JSONDecoder(s:String){
super();
this.tokenizer = new JSONTokenizer(s);
this.nextToken();
this.value = this.parseValue();
}
private function parseObject():Object{
var key:String;
var o:Object = new Object();
this.nextToken();
if (this.token.type == JSONTokenType.RIGHT_BRACE){
return (o);
};
while (true) {
if (this.token.type == JSONTokenType.STRING){
key = String(this.token.value);
this.nextToken();
if (this.token.type == JSONTokenType.COLON){
this.nextToken();
o[key] = this.parseValue();
this.nextToken();
if (this.token.type == JSONTokenType.RIGHT_BRACE){
return (o);
};
if (this.token.type == JSONTokenType.COMMA){
this.nextToken();
} else {
this.tokenizer.parseError(("Expecting } or , but found " + this.token.value));
};
} else {
this.tokenizer.parseError(("Expecting : but found " + this.token.value));
};
} else {
this.tokenizer.parseError(("Expecting string but found " + this.token.value));
};
};
return (null);
}
private function parseValue():Object{
if (this.token == null){
this.tokenizer.parseError("Unexpected end of input");
};
switch (this.token.type){
case JSONTokenType.LEFT_BRACE:
return (this.parseObject());
case JSONTokenType.LEFT_BRACKET:
return (this.parseArray());
case JSONTokenType.STRING:
case JSONTokenType.NUMBER:
case JSONTokenType.TRUE:
case JSONTokenType.FALSE:
case JSONTokenType.NULL:
return (this.token.value);
default:
this.tokenizer.parseError(("Unexpected " + this.token.value));
};
return (null);
}
private function nextToken():JSONToken{
return ((this.token = this.tokenizer.getNextToken()));
}
public function getValue(){
return (this.value);
}
private function parseArray():Array{
var a:Array = new Array();
this.nextToken();
if (this.token.type == JSONTokenType.RIGHT_BRACKET){
return (a);
};
while (true) {
a.push(this.parseValue());
this.nextToken();
if (this.token.type == JSONTokenType.RIGHT_BRACKET){
return (a);
};
if (this.token.type == JSONTokenType.COMMA){
this.nextToken();
} else {
this.tokenizer.parseError(("Expecting ] or , but found " + this.token.value));
};
};
return (null);
}
}
}//package com.adobe.serialization.json
Section 5
//JSONEncoder (com.adobe.serialization.json.JSONEncoder)
package com.adobe.serialization.json {
import flash.utils.*;
public class JSONEncoder {
private var jsonString:String;
public function JSONEncoder(value){
super();
this.jsonString = this.convertToString(value);
}
private function escapeString(str:String):String{
var ch:String;
var hexCode:String;
var zeroPad:String;
var s:String = "";
var len:Number = str.length;
var i:int;
while (i < len) {
ch = str.charAt(i);
switch (ch){
case "\"":
s = (s + "\\\"");
break;
case "\\":
s = (s + "\\\\");
break;
case "\b":
s = (s + "\\b");
break;
case "\f":
s = (s + "\\f");
break;
case "\n":
s = (s + "\\n");
break;
case "\r":
s = (s + "\\r");
break;
case "\t":
s = (s + "\\t");
break;
default:
if (ch < " "){
hexCode = ch.charCodeAt(0).toString(16);
zeroPad = ((hexCode.length == 2)) ? "00" : "000";
s = (s + (("\\u" + zeroPad) + hexCode));
} else {
s = (s + ch);
};
};
i++;
};
return ((("\"" + s) + "\""));
}
private function arrayToString(a:Array):String{
var s:String = "";
var i:int;
while (i < a.length) {
if (s.length > 0){
s = (s + ",");
};
s = (s + this.convertToString(a[i]));
i++;
};
return ((("[" + s) + "]"));
}
public function getString():String{
return (this.jsonString);
}
private function objectToString(o:Object):String{
var value:Object;
var key:String;
var v:XML;
var o = o;
var s = "";
var classInfo:XML = describeType(o);
if (classInfo.@name.toString() == "Object"){
for (key in o) {
value = o[key];
if ((value is Function)){
} else {
if (s.length > 0){
s = (s + ",");
};
s = (s + ((this.escapeString(key) + ":") + this.convertToString(value)));
};
};
} else {
for each (v in classInfo..*.(((name() == "variable")) || ((name() == "accessor")))) {
if (s.length > 0){
s = (s + ",");
};
s = (s + ((this.escapeString(v.@name.toString()) + ":") + this.convertToString(o[v.@name])));
};
};
return ((("{" + s) + "}"));
}
private function convertToString(value):String{
if ((value is String)){
return (this.escapeString((value as String)));
};
if ((value is Number)){
return ((isFinite((value as Number))) ? value.toString() : "null");
} else {
if ((value is Boolean)){
return ((value) ? "true" : "false");
} else {
if ((value is Array)){
return (this.arrayToString((value as Array)));
};
if ((((value is Object)) && (!((value == null))))){
return (this.objectToString(value));
};
};
};
return ("null");
}
}
}//package com.adobe.serialization.json
Section 6
//JSONParseError (com.adobe.serialization.json.JSONParseError)
package com.adobe.serialization.json {
public class JSONParseError extends Error {
private var _location:int;
private var _text:String;
public function JSONParseError(message:String="", location:int=0, text:String=""){
super(message);
name = "JSONParseError";
this._location = location;
this._text = text;
}
public function get location():int{
return (this._location);
}
public function get text():String{
return (this._text);
}
}
}//package com.adobe.serialization.json
Section 7
//JSONToken (com.adobe.serialization.json.JSONToken)
package com.adobe.serialization.json {
public class JSONToken {
private var _value:Object;
private var _type:int;
public function JSONToken(type:int=-1, value:Object=null){
super();
this._type = type;
this._value = value;
}
public function get value():Object{
return (this._value);
}
public function get type():int{
return (this._type);
}
public function set type(value:int):void{
this._type = value;
}
public function set value(v:Object):void{
this._value = v;
}
}
}//package com.adobe.serialization.json
Section 8
//JSONTokenizer (com.adobe.serialization.json.JSONTokenizer)
package com.adobe.serialization.json {
public class JSONTokenizer {
private var loc:int;
private var ch:String;
private var obj:Object;
private var jsonString:String;
public function JSONTokenizer(s:String){
super();
this.jsonString = s;
this.loc = 0;
this.nextChar();
}
private function skipComments():void{
if (this.ch == "/"){
this.nextChar();
switch (this.ch){
case "/":
do {
this.nextChar();
} while (((!((this.ch == "\n"))) && (!((this.ch == "")))));
this.nextChar();
break;
case "*":
this.nextChar();
while (true) {
if (this.ch == "*"){
this.nextChar();
if (this.ch == "/"){
this.nextChar();
break;
};
} else {
this.nextChar();
};
if (this.ch == ""){
this.parseError("Multi-line comment not closed");
};
};
break;
default:
this.parseError((("Unexpected " + this.ch) + " encountered (expecting '/' or '*' )"));
};
};
}
private function isDigit(ch:String):Boolean{
return ((((ch >= "0")) && ((ch <= "9"))));
}
private function readString():JSONToken{
var _local5:String;
var i:int;
var token:JSONToken = new JSONToken();
token.type = JSONTokenType.STRING;
var string:String = "";
this.nextChar();
while (((!((this.ch == "\""))) && (!((this.ch == ""))))) {
if (this.ch == "\\"){
this.nextChar();
switch (this.ch){
case "\"":
string = (string + "\"");
break;
case "/":
string = (string + "/");
break;
case "\\":
string = (string + "\\");
break;
case "b":
string = (string + "\b");
break;
case "f":
string = (string + "\f");
break;
case "n":
string = (string + "\n");
break;
case "r":
string = (string + "\r");
break;
case "t":
string = (string + "\t");
break;
case "u":
_local5 = "";
i = 0;
while (i < 4) {
if (!this.isHexDigit(this.nextChar())){
this.parseError((" Excepted a hex digit, but found: " + this.ch));
};
_local5 = (_local5 + this.ch);
i++;
};
string = (string + String.fromCharCode(parseInt(_local5, 16)));
break;
default:
string = (string + ("\\" + this.ch));
};
} else {
string = (string + this.ch);
};
this.nextChar();
};
if (this.ch == ""){
this.parseError("Unterminated string literal");
};
this.nextChar();
token.value = string;
return (token);
}
private function nextChar():String{
return ((this.ch = this.jsonString.charAt(this.loc++)));
}
public function getNextToken():JSONToken{
var _local2:String;
var _local3:String;
var _local4:String;
var token:JSONToken = new JSONToken();
this.skipIgnored();
switch (this.ch){
case "{":
token.type = JSONTokenType.LEFT_BRACE;
token.value = "{";
this.nextChar();
break;
case "}":
token.type = JSONTokenType.RIGHT_BRACE;
token.value = "}";
this.nextChar();
break;
case "[":
token.type = JSONTokenType.LEFT_BRACKET;
token.value = "[";
this.nextChar();
break;
case "]":
token.type = JSONTokenType.RIGHT_BRACKET;
token.value = "]";
this.nextChar();
break;
case ",":
token.type = JSONTokenType.COMMA;
token.value = ",";
this.nextChar();
break;
case ":":
token.type = JSONTokenType.COLON;
token.value = ":";
this.nextChar();
break;
case "t":
_local2 = ((("t" + this.nextChar()) + this.nextChar()) + this.nextChar());
if (_local2 == "true"){
token.type = JSONTokenType.TRUE;
token.value = true;
this.nextChar();
} else {
this.parseError(("Expecting 'true' but found " + _local2));
};
break;
case "f":
_local3 = (((("f" + this.nextChar()) + this.nextChar()) + this.nextChar()) + this.nextChar());
if (_local3 == "false"){
token.type = JSONTokenType.FALSE;
token.value = false;
this.nextChar();
} else {
this.parseError(("Expecting 'false' but found " + _local3));
};
break;
case "n":
_local4 = ((("n" + this.nextChar()) + this.nextChar()) + this.nextChar());
if (_local4 == "null"){
token.type = JSONTokenType.NULL;
token.value = null;
this.nextChar();
} else {
this.parseError(("Expecting 'null' but found " + _local4));
};
break;
case "\"":
token = this.readString();
break;
default:
if (((this.isDigit(this.ch)) || ((this.ch == "-")))){
token = this.readNumber();
} else {
if (this.ch == ""){
return (null);
};
this.parseError((("Unexpected " + this.ch) + " encountered"));
};
};
return (token);
}
private function skipWhite():void{
while (this.isWhiteSpace(this.ch)) {
this.nextChar();
};
}
public function parseError(message:String):void{
throw (new JSONParseError(message, this.loc, this.jsonString));
}
private function isWhiteSpace(ch:String):Boolean{
return ((((((((ch == " ")) || ((ch == "\t")))) || ((ch == "\n")))) || ((ch == "\r"))));
}
private function skipIgnored():void{
var originalLoc:int;
do {
originalLoc = this.loc;
this.skipWhite();
this.skipComments();
} while (originalLoc != this.loc);
}
private function isHexDigit(ch:String):Boolean{
var uc:String = ch.toUpperCase();
return (((this.isDigit(ch)) || ((((uc >= "A")) && ((uc <= "F"))))));
}
private function readNumber():JSONToken{
var token:JSONToken = new JSONToken();
token.type = JSONTokenType.NUMBER;
var input:String = "";
if (this.ch == "-"){
input = (input + "-");
this.nextChar();
};
if (!this.isDigit(this.ch)){
this.parseError("Expecting a digit");
};
if (this.ch == "0"){
input = (input + this.ch);
this.nextChar();
if (this.isDigit(this.ch)){
this.parseError("A digit cannot immediately follow 0");
};
} else {
while (this.isDigit(this.ch)) {
input = (input + this.ch);
this.nextChar();
};
};
if (this.ch == "."){
input = (input + ".");
this.nextChar();
if (!this.isDigit(this.ch)){
this.parseError("Expecting a digit");
};
while (this.isDigit(this.ch)) {
input = (input + this.ch);
this.nextChar();
};
};
if ((((this.ch == "e")) || ((this.ch == "E")))){
input = (input + "e");
this.nextChar();
if ((((this.ch == "+")) || ((this.ch == "-")))){
input = (input + this.ch);
this.nextChar();
};
if (!this.isDigit(this.ch)){
this.parseError("Scientific notation number needs exponent value");
};
while (this.isDigit(this.ch)) {
input = (input + this.ch);
this.nextChar();
};
};
var num:Number = Number(input);
if (((isFinite(num)) && (!(isNaN(num))))){
token.value = num;
return (token);
};
this.parseError((("Number " + num) + " is not valid!"));
return (null);
}
}
}//package com.adobe.serialization.json
Section 9
//JSONTokenType (com.adobe.serialization.json.JSONTokenType)
package com.adobe.serialization.json {
public class JSONTokenType {
public static const NUMBER:int = 11;
public static const FALSE:int = 8;
public static const RIGHT_BRACKET:int = 4;
public static const NULL:int = 9;
public static const TRUE:int = 7;
public static const RIGHT_BRACE:int = 2;
public static const UNKNOWN:int = -1;
public static const COMMA:int = 0;
public static const LEFT_BRACKET:int = 3;
public static const STRING:int = 10;
public static const LEFT_BRACE:int = 1;
public static const COLON:int = 6;
}
}//package com.adobe.serialization.json
Section 10
//IntUtil (com.adobe.utils.IntUtil)
package com.adobe.utils {
public class IntUtil {
private static var hexChars:String = "0123456789abcdef";
public static function toHex(n:int, bigEndian:Boolean=false):String{
var i:int;
var x:int;
var s:String = "";
if (bigEndian){
i = 0;
while (i < 4) {
s = (s + (hexChars.charAt(((n >> (((3 - i) * 8) + 4)) & 15)) + hexChars.charAt(((n >> ((3 - i) * 8)) & 15))));
i++;
};
} else {
x = 0;
while (x < 4) {
s = (s + (hexChars.charAt(((n >> ((x * 8) + 4)) & 15)) + hexChars.charAt(((n >> (x * 8)) & 15))));
x++;
};
};
return (s);
}
public static function ror(x:int, n:int):uint{
var nn:int = (32 - n);
return (((x << nn) | (x >>> (32 - nn))));
}
public static function rol(x:int, n:int):int{
return (((x << n) | (x >>> (32 - n))));
}
}
}//package com.adobe.utils
Section 11
//FlashAd (com.newgrounds.components.FlashAd)
package com.newgrounds.components {
import flash.events.*;
import flash.display.*;
import com.newgrounds.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
public class FlashAd extends Sprite {
private var _adURLLoader:URLLoader;
private var _ad:Loader;
private var _adRect:Sprite;
private var _mask:Shape;
private var _showBackground:Boolean;
public var background:MovieClip;
private static const REMOVED_FROM_STAGE:String = "removedFromStage";
private static const DEBUG_AD_URL:String = "http://www.ngads.com/adtest.php";
private static var _adResetTime:uint = 0;
private static var _adURL:URLRequest;
public function FlashAd(showBackground:Boolean=true){
super();
if (((!((parent == null))) && ((getQualifiedClassName(parent) == "fl.livepreview::LivePreviewParent")))){
return;
};
this._adRect = new Sprite();
this._adRect.graphics.beginFill(0);
this._adRect.graphics.moveTo(0, 0);
this._adRect.graphics.lineTo(300, 0);
this._adRect.graphics.lineTo(300, 250);
this._adRect.graphics.lineTo(0, 250);
this._adRect.graphics.lineTo(0, 0);
this._adRect.graphics.endFill();
this._mask = new Shape();
this._mask.graphics.beginFill(0);
this._mask.graphics.moveTo(0, 0);
this._mask.graphics.lineTo(300, 0);
this._mask.graphics.lineTo(300, 250);
this._mask.graphics.lineTo(0, 250);
this._mask.graphics.lineTo(0, 0);
this._mask.graphics.endFill();
addChild(this._adRect);
this._adRect.addChild(this._mask);
this._adRect.visible = false;
x = Math.round(x);
y = Math.round(y);
scaleX = 1;
scaleY = 1;
if (this.background){
if (this.background.ngLinkButton){
this.background.ngLinkButton.addEventListener(MouseEvent.CLICK, this.linkClickHandler);
};
if (this.background.loadingClip){
this.background.loadingClip.visible = false;
};
};
if (API.isFlashVersion(9, 0, 28)){
addEventListener(REMOVED_FROM_STAGE, this.onRemovedFromStage);
};
if (API.adsApproved){
this.loadAdFeed(API.adFeedURL);
} else {
API.addEventListener(APIEvent.ADS_APPROVED, this.onAdsApproved, false, 0, true);
};
this.showBackground = showBackground;
}
private function onAdFeedLoaded(e:Event):void{
var loader:URLLoader = URLLoader(e.target);
if (((loader.data) && (!((loader.data == ""))))){
this.loadAd((loader.data as String));
} else {
dispatchEvent(new APIEvent(APIEvent.AD_ATTACHED, false, new APIError("FLASH_ADS_NOT_APPROVED", "Unable to render ad")));
if (((this.background) && (this.background.loadingClip))){
this.background.loadingClip.visible = false;
};
};
}
private function onAdFeedError(e:Event):void{
trace("[NewgroundsAPI] :: Unable to load ad feed!");
if (((this.background) && (this.background.loadingClip))){
this.background.loadingClip.visible = false;
};
}
private function onAdError(e:Event):void{
dispatchEvent(new APIEvent(APIEvent.AD_ATTACHED, false, new APIError("FLASH_ADS_NOT_APPROVED", "Unable to render ad")));
this.removeAd();
}
private function onAdLoaded(e:Event):void{
this._adRect.addChild(this._ad);
this._ad.mask = this._mask;
this._adRect.visible = true;
if (this.background){
if (this._showBackground){
this._adRect.mask = this.background.adMask;
};
if (this.background.loadingClip){
this.background.loadingClip.visible = false;
};
};
trace("[NewgroundsAPI] :: Ad loaded!");
dispatchEvent(new APIEvent(APIEvent.AD_ATTACHED, true));
}
public function get showBackground():Boolean{
return (this._showBackground);
}
public function set showBackground(value:Boolean):void{
this._showBackground = value;
if (this.background){
this.background.visible = value;
this._adRect.mask = (value) ? this.background.adMask : null;
};
}
private function get hasAdElapsed():Boolean{
if (getTimer() >= _adResetTime){
_adResetTime = (getTimer() + ((1000 * 60) * 5));
return (true);
};
return (false);
}
private function loadAdFeed(adFeedURL:String):void{
var adFeedURL = adFeedURL;
this._adURLLoader = new URLLoader();
this._adURLLoader.addEventListener(Event.COMPLETE, this.onAdFeedLoaded);
this._adURLLoader.addEventListener(IOErrorEvent.IO_ERROR, this.onAdError);
this._adURLLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onAdError);
if (!adFeedURL){
trace("[Newgrounds API] :: Invalid feed URL!");
return;
};
if (this.hasAdElapsed){
if (adFeedURL.indexOf("?") > -1){
_adURL = new URLRequest(((adFeedURL + "&random=") + Math.random()));
} else {
_adURL = new URLRequest(((adFeedURL + "?random=") + Math.random()));
};
};
this._adURLLoader.load(_adURL);
//unresolved jump
var _slot1 = e;
onAdError(null);
if (((this.background) && (this.background.loadingClip))){
this.background.loadingClip.visible = true;
};
}
private function onAdsApproved(e:APIEvent):void{
API.removeEventListener(APIEvent.ADS_APPROVED, this.onAdsApproved, false);
if (e.success){
this.loadAdFeed(API.adFeedURL);
} else {
trace("[NewgroundsAPI] :: No ad feed URL supplied to Newgrounds API ad!");
};
}
private function loadAd(url:String):void{
if (this._ad){
this.removeAd();
};
this._ad = new Loader();
this._ad.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onAdLoaded);
this._ad.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.onAdError);
this._ad.load(new URLRequest(url), new LoaderContext(false, new ApplicationDomain(null)));
if (((this.background) && (this.background.loadingClip))){
this.background.loadingClip.visible = true;
};
}
public function removeAd():void{
removeEventListener(REMOVED_FROM_STAGE, this.onRemovedFromStage);
if (((this.background) && (this.background.loadingClip))){
this.background.loadingClip.visible = false;
};
if (this._adURLLoader){
this._adURLLoader.close();
//unresolved jump
var _slot1 = e;
};
if (this._adRect){
this._adRect.visible = false;
};
if (this._ad){
trace("[NewgroundsAPI] :: Ad removed");
this._ad.close();
//unresolved jump
var _slot1 = e;
Object(this._ad).unloadAndStop(true);
//unresolved jump
var _slot1 = e;
_ad.unload();
if (this._ad.parent){
this._ad.parent.removeChild(this._ad);
};
};
this._ad = null;
}
private function onRemovedFromStage(e:Event):void{
this.removeAd();
}
private function linkClickHandler(event:MouseEvent):void{
API.loadNewgrounds();
}
}
}//package com.newgrounds.components
Section 12
//API (com.newgrounds.API)
package com.newgrounds {
import flash.events.*;
import flash.display.*;
import com.newgrounds.components.*;
import flash.utils.*;
import com.adobe.serialization.json.*;
import flash.net.*;
import com.adobe.crypto.*;
import com.adobe.images.*;
import flash.system.*;
public class API {
private static const COMMANDS_WIKI_URL:String = "http://www.newgrounds.com/wiki/flashapi/commands/";
private static const AD_TERMS_URL:String = "http://www.newgrounds.com/wiki/flashads/terms/";
private static const GATEWAY_URL:String = "http://www.ngads.com/gateway_v2.php";
public static const VERSION:String = "2.3";
private static var connected:Boolean;
private static var user_id:uint;
private static var _preloadComplete:Boolean = false;
private static var user_email:String;
private static var _movieId:String;
private static var _saveFileId:uint;
private static var _isMetadataLoaded:Boolean = false;
private static var publisher_id:uint;
private static var _imageFilePath:String;
private static var _saveFilePath:String;
private static var ad_url:String;
private static var _debug:Boolean = true;
private static var _saveGroups:Array = [];
private static var do_echo:Boolean = false;
private static var session_id:String;
public static var errors:Dictionary = APIError.init_codes();
private static var timeoutTimer:Timer = new Timer(8000, 1);
private static var _medals:Array;
private static var user_name:String;
private static var period_aliases:Object = {t:{name:"Today", alias:"TODAY"}, p:{name:"Yesterday", alias:"YESTERDAY"}, w:{name:"This Week", alias:"THIS_WEEK"}, m:{name:"This Month", alias:"THIS_MONTH"}, y:{name:"This Year", alias:"THIS_YEAR"}, a:{name:"All-Time", alias:"ALL_TIME"}};
private static var _host:String;
private static var _connected:Boolean = false;
private static var _userpageFormat:String;
private static var _scoreboards:Array = new Array();
private static var _eventDispatcher:EventDispatcher = new EventDispatcher();
private static var compressor:BaseN = new BaseN(compression_radix);
private static var score_page_counts:Object = new Object();
private static var _adsApproved:Boolean = false;
private static var version:String;
public static var periods:Object = getPeriodAliases();
private static var _encryptionKey:String;
private static var root:DisplayObject;
private static var compression_radix:String = "/g8236klvBQ#&|;Zb*7CEA59%s`Oue1wziFp$rDVY@TKxUPWytSaGHJ>dmoMR^<0~4qNLhc(I+fjn)X";
private static var _preloadAssets:Array = [];
private static var sharedObjects:Dictionary = new Dictionary();
private static var _trackerId:uint;
private static var _saveFile:SaveFile;
private static var userpage_format:String;
private static var _saveGroupId:uint;
public static function loadUserPage(userId:uint=0, userName:String=null):Boolean{
var userPage:String;
if ((((userId == 0)) && ((userName == null)))){
if (hasUserSession()){
userId = user_id;
userName = user_name;
} else {
return (false);
};
};
if (publisher_id == 1){
userPage = (("http://" + userName.toLowerCase()) + ".newgrounds.com");
navigateToURL(new URLRequest(userPage), "_blank");
return (true);
};
if (userpage_format){
userPage = userpage_format;
userPage = userPage.split(":user_id:").join(userId.toString());
userPage = userPage.split(":user_name:").join(escape(userName));
navigateToURL(new URLRequest(userPage), "_blank");
return (true);
};
return (false);
}
public static function getPeriodAlias(p:String):String{
var i:String;
for (i in period_aliases) {
if (i == p){
return (period_aliases[i].alias);
};
};
return (null);
}
private static function onCommandError(e:Event):void{
var loader:SmartURLLoader = SmartURLLoader(e.target);
var i:uint;
while (i < _preloadAssets.length) {
if (_preloadAssets[i] == loader){
_preloadAssets.splice(i, 1);
break;
};
i++;
};
}
private static function sendWarning(m:String, c:String=null):void{
if (c){
m = (m + ((("\n[NewgroundsAPI WARNING] :: \tSee " + COMMANDS_WIKI_URL) + c.toLowerCase()) + " for additional information."));
};
trace(("[NewgroundsAPI WARNING] :: " + m));
}
public static function unlockMedal(medalName:String):void{
var params:Object;
var medalsUnlocked:Object;
if (((!(medalName)) || ((medalName == "")))){
sendError({command_id:getCommandID("unlockMedal")}, new APIError("MISSING_PARAM", "missing required medal name"));
return;
};
var medal:Medal = getMedalByName(medalName);
if (!medal){
sendMessage(("No medal with name: " + medalName));
return;
};
if (((hasUserSession()) || (debugMode))){
sendMessage((("Attempting to unlock '" + medal.name) + "'"));
if (medal.unlocked){
sendWarning((("Medal '" + medal.name) + "' is already unlocked!"));
return;
};
params = new Object();
params.medal_id = medal.id;
sendSecureCommand("unlockMedal", params);
} else {
sendMessage(("Locally unlocking " + medal.name));
if (medal.unlocked){
sendWarning((("Medal '" + medal.name) + "' is already unlocked!"));
return;
};
medal.unlocked = true;
medalsUnlocked = loadLocal("medals_unlocked");
if (!medalsUnlocked){
medalsUnlocked = new Object();
};
medalsUnlocked[medal.id.toString()] = true;
saveLocal("medals_unlocked", medalsUnlocked);
callListener(APIEvent.MEDAL_UNLOCKED, true, medal);
};
}
public static function setVersion(v:String):void{
if (((v) && (!((v == ""))))){
version = v;
};
}
public static function isFlashVersion(major:uint, minor:uint=0, buildNumber:uint=0, internalBuildNumber:uint=0):Boolean{
var version:Array = Capabilities.version.split(" ")[1].split(",");
var requiredVersion:Array = arguments;
var i:uint;
while (i < requiredVersion.length) {
version[i] = uint(version[i]);
i++;
};
i = 0;
while (i < requiredVersion.length) {
if (version[i] > requiredVersion[i]){
return (true);
};
if (version[i] < requiredVersion[i]){
return (false);
};
i++;
};
return (true);
}
public static function getUserID():uint{
return (user_id);
}
private static function getHost():String{
return (_host);
}
public static function hasUserEmail():Boolean{
return (((!((user_email == null))) && (!((user_email == "")))));
}
private static function uncompressHex(base_value:String):String{
var hl:uint;
var chunk:String;
var num:uint;
var hex:String;
var offset:uint = uint(base_value.charAt(0));
var hex_value:String = "";
var i:uint = 1;
while (i < base_value.length) {
chunk = base_value.substr(i, 4);
num = uint(compressor.decode(chunk));
hex = num.toString(16);
if ((i + 4) < base_value.length){
hl = 6;
} else {
hl = offset;
};
while (hex.length < hl) {
hex = ("0" + hex);
};
hex_value = (hex_value + hex);
i = (i + 4);
};
return (hex_value);
}
public static function getMedalByName(medalName:String):Medal{
var medal:Medal;
for each (medal in _medals) {
if (medal.name == medalName){
return (medal);
};
};
return (null);
}
private static function callListener(type:String, success:Boolean=true, data=undefined):void{
dispatchEvent(new APIEvent(type, success, data));
}
public static function loadLocal(save_id:String):Object{
var sharedObj:SharedObject;
var save_id = save_id;
if (!sharedObjects[save_id]){
sharedObjects[save_id] = SharedObject.getLocal(((("ng_ap_secure_" + _trackerId) + "_") + save_id));
};
sharedObj = sharedObjects[save_id];
if (((((sharedObj) && (sharedObj.data))) && (sharedObj.data[save_id]))){
return (decodeData(sharedObj.data[save_id]));
} else {
return (null);
};
//unresolved jump
var _slot1 = e;
sendWarning(("loadLocal ERROR: " + _slot1));
return (null);
}
private static function populateScoreBoards(scoreBoards:Array):void{
_scoreboards = [];
var i:uint;
while (i < scoreBoards.length) {
_scoreboards.push(new ScoreBoard(scoreBoards[i].id, scoreBoards[i].name, ""));
i++;
};
}
public static function set debugMode(value:Boolean):void{
_debug = value;
}
public static function createAd():FlashAd{
sendMessage("You may see a security sandbox violation. This is normal!");
return (new FlashAd());
}
private static function populateSaveGroups(saveGroupList:Array):void{
var saveGroup:SaveGroup;
_saveGroups = [];
var i:uint;
while (i < saveGroupList.length) {
saveGroup = SaveGroup.createFromObject(saveGroupList[i]);
_saveGroups.push(saveGroup);
i++;
};
}
public static function getSaveGroupById(groupId:uint):SaveGroup{
if (((!(_saveGroups)) || ((_saveGroups.length < 1)))){
sendWarning("No save groups found");
return (null);
};
var i:uint;
while (i < _saveGroups.length) {
if (_saveGroups[i].id == groupId){
return (_saveGroups[i]);
};
i++;
};
return (null);
}
private static function dispatchEvent(event:Event):void{
_eventDispatcher.dispatchEvent(event);
echo(("Fired Event: " + event.type));
}
public static function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void{
_eventDispatcher.removeEventListener(type, listener, useCapture);
}
public static function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:uint=0, useWeakReference:Boolean=false):void{
_eventDispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
public static function get adFeedURL():String{
return (ad_url);
}
public static function setUserEmail(e:String):void{
user_email = e;
}
public static function hasUserSession():Boolean{
return (((((!((session_id == null))) && (!((session_id == ""))))) && (!((publisher_id == 0)))));
}
private static function echo(m:String):void{
if (do_echo){
trace(m);
};
}
public static function getOfficialURL():String{
var o_url:String = ((((((GATEWAY_URL + "?tracker_id=") + _movieId) + "&command_id=") + getCommandID("loadOfficalVersion")) + "&seed=") + Math.random());
if (debugMode){
o_url = (o_url + "&debug=1");
};
return (o_url);
}
public static function executeSaveQuery(query:SaveGroupQuery):void{
sendCommand("lookupSaveFiles", {publisher_id:publisher_id, group_id:query.groupId, query:JSON.encode(query.toObject())}, false, null, query);
trace(JSON.encode(query.toObject()));
}
public static function getScoreBoardById(id:uint):ScoreBoard{
var board:ScoreBoard;
for each (board in _scoreboards) {
if (board.id == id){
return (board);
};
};
return (null);
}
private static function getPeriodAliases():Object{
var i:String;
var aliases:Object = new Object();
for (i in period_aliases) {
aliases[period_aliases[i].alias] = i;
};
return (aliases);
}
private static function compressHex(hex_value:String):String{
var offset:uint = (hex_value.length % 6);
var basen_value:String = "";
var i:uint;
while (i < hex_value.length) {
basen_value = (basen_value + compressor.encode(uint(("0x" + hex_value.substr(i, 6))), 4));
i = (i + 6);
};
return ((offset.toString() + basen_value));
}
public static function get preloadComplete():Boolean{
return (_preloadComplete);
}
private static function assertConnected():Boolean{
if (!_connected){
return (false);
};
return (true);
}
public static function sendSecureCommand(command:String, secure_params:Object, unsecure_params:Object=null, files:Object=null, owner=null):void{
if (((((!(debugMode)) && (!(hasUserSession())))) && (!(hasUserEmail())))){
sendError({command_id:getCommandID(command)}, new APIError("IDENTIFICATION_REQUIRED", (("You must be logged in or provide an e-mail address ( using NewgroundsAPI.setUserEmail(\"name@domain.com\"); ) to use " + command) + "().")));
return;
};
if (!command){
fatalError("Missing command", "sendSecureCommand");
};
if (!secure_params){
fatalError("Missing secure_params", "sendSecureCommand");
};
if (!unsecure_params){
unsecure_params = new Object();
};
var seed:String = "";
var i:uint;
while (i < 16) {
seed = (seed + compression_radix.charAt(Math.floor((Math.random() * compression_radix.length))));
i++;
};
if (((debugMode) && (!(session_id)))){
secure_params.session_id = "";
} else {
secure_params.session_id = session_id;
};
secure_params.as_version = 3;
secure_params.user_email = user_email;
secure_params.publisher_id = publisher_id;
secure_params.seed = seed;
secure_params.command_id = getCommandID(command);
var hash:String = MD5.hash(seed);
var rc4enc:String = RC4.encrypt(JSON.encode(secure_params), _encryptionKey);
var hex_value:String = (hash + rc4enc);
unsecure_params.secure = compressHex(hex_value);
sendCommand("securePacket", unsecure_params, false, files, owner);
}
private static function sendError(c:Object, e:APIError):void{
trace(((((("[NewgroundsAPI ERROR] :: " + getCommandName(c.command_id)) + "() - ") + e.name) + ":\n\t\t\t\t") + e.message));
}
public static function getUserName():String{
return (user_name);
}
private static function getCommandName(id:String):String{
return (id);
}
public static function sendMessage(m:String, r:Boolean=false):void{
var msg:String = ("[NewgroundsAPI] :: " + m);
trace(msg);
}
public static function newSaveFile(groupName:String):SaveFile{
var group:SaveGroup = getSaveGroupByName(groupName);
if (group){
return (new SaveFile(group));
};
sendError({command_id:"newSaveFile"}, new APIError("INVALID_SAVE_GROUP", (("'" + group) + "' is not a valid save group.")));
return (null);
}
public static function get medals():Array{
return ((_medals) ? _medals.concat() : []);
}
public static function connectionTimeOut(e:Event=null):void{
dispatchEvent(new APIEvent(APIEvent.API_CONNECTED, false, new APIError("CONNECTION_FAILED", "Connection to NewgroundsAPI gateway timed out.")));
}
private static function fatalError(m:String, c:String):void{
if (c){
m = (m + ((("\n\tSee " + COMMANDS_WIKI_URL) + c.toLowerCase()) + " for additional information."));
};
throw (new Error(("***ERROR*** class=API\n\n" + m)));
}
public static function getScoreBoardByName(name:String):ScoreBoard{
var board:ScoreBoard;
for each (board in _scoreboards) {
if (board.name == name){
return (board);
};
};
return (null);
}
private static function sendNotice(m:String, c:String=null):void{
if (c){
m = (m + ((("\n[NewgroundsAPI NOTICE] :: \tSee " + COMMANDS_WIKI_URL) + c.toLowerCase()) + " for additional information."));
};
trace(("[NewgroundsAPI NOTICE] :: " + m));
}
public static function get debugMode():Boolean{
return (_debug);
}
public static function loadCustomLink(link:String):void{
sendCommand("loadCustomLink", {host:getHost(), link:link}, true);
}
public static function loadMySite():void{
sendCommand("loadMySite", {host:getHost()}, true);
}
public static function getTrackerID():uint{
return (_trackerId);
}
public static function get adsApproved():Boolean{
return (_adsApproved);
}
private static function sendCommand(command:String, params:Object, openBrowser:Boolean=false, files:Object=null, owner=null):void{
var msg:String;
var key:String;
var name:String;
if (((!(connected)) && (!((command == "connectMovie"))))){
msg = (("NewgroundsAPI." + command) + "() - NewgroundsAPI.connectMovie() must be called before this command can be called\n");
fatalError(msg, "connectMovie");
};
var loader:SmartURLLoader = new SmartURLLoader();
loader.addVariable("command_id", getCommandID(command));
loader.addVariable("tracker_id", _movieId);
if (debugMode){
loader.addVariable("debug", 1);
};
if (params){
for (key in params) {
loader.addVariable(key, params[key]);
};
};
if (files){
for (name in files) {
loader.addFile(name, files[name], name);
};
};
if (openBrowser){
loader.method = URLRequestMethod.GET;
} else {
loader.method = URLRequestMethod.POST;
};
loader.preventCache = true;
if (openBrowser){
loader.openBrowser = true;
loader.method = URLRequestMethod.GET;
} else {
loader.addEventListener(Event.COMPLETE, onCommandComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR, onCommandError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onCommandError);
loader.method = URLRequestMethod.POST;
};
loader.owner = owner;
loader.load(GATEWAY_URL);
}
public static function checkFilePrivledges(file:SaveFile):void{
sendCommand("checkFilePrivs", {group:file.groupId, filename:file.name, user_id:(user_id) ? user_id : 0, publisher_id:publisher_id});
}
public static function isPublishedHost():Boolean{
return (((!((getHost() == "localhost"))) && ((getHost().indexOf("file://") == -1))));
}
public static function loadOfficialVersion():void{
navigateToURL(new URLRequest(getOfficialURL()));
}
public static function createSaveQuery(groupName:String):SaveGroupQuery{
var group:SaveGroup = getSaveGroupByName(groupName);
if (group){
return (group.createQuery());
};
return (null);
}
public static function saveFile(file:SaveFile, overwrite:Boolean=false):void{
var params:Object = file.toObject();
params.user_name = user_name;
params.overwrite = (overwrite) ? 1 : 0;
var byteArray:ByteArray = new ByteArray();
if ((file.contents is ByteArray)){
byteArray.writeByte(0);
byteArray.writeBytes(file.contents);
} else {
byteArray.writeByte(1);
byteArray.writeObject(file.contents);
};
byteArray.compress();
var files:Object = new Object();
files.file = byteArray;
if (file.thumbnail){
files.thumbnail = PNGEncoder.encode(file.thumbnail);
};
sendSecureCommand("saveFile", params, null, files, file);
}
public static function getMedalById(medalId:uint):Medal{
var medal:Medal;
for each (medal in _medals) {
if (medal.id == medalId){
return (medal);
};
};
return (null);
}
public static function loadSaveFile(save_id:Number, get_contents:Boolean=true){
var packet:Object = {publisher_id:publisher_id, save_id:save_id, get_contents:get_contents};
sendCommand("loadSaveFile", packet);
}
public static function loadNewgrounds():void{
sendCommand("loadNewgrounds", {host:getHost()}, true);
}
public static function rateSaveFile(file:SaveFile, rating:SaveRating, vote:Number):void{
sendSecureCommand("rateSaveFile", {group:file.groupId, save_id:file.id, rating_id:rating.id, vote:vote, user_id:user_id}, null, null, file);
}
public static function IsCompatible():Boolean{
return (!((publisher_id == 0)));
}
public static function loadScores(board:ScoreBoard, tag:String=null):void{
var command_name:String = "loadScores";
if (!board.id){
sendError({command_id:getCommandID(command_name)}, new APIError("MISSING_PARAM", "missing required ScoreBoard instance"));
return;
};
if (!hasUserSession()){
callListener(APIEvent.SCORES_LOADED, false, new APIError("SITE_ID_REQUIRED", (("Host '" + getHost()) + "' does not have high scores enabled")));
return;
};
var params:Object = {};
params.publisher_id = publisher_id;
params.period = board.period;
params.board = board.id;
params.num_results = board.num_results;
params.page = board.page;
if (((!(tag)) || ((tag == "")))){
params.tag = board.tag;
} else {
params.tag = tag;
};
sendCommand(command_name, params);
}
public static function logCustomEvent(event:String):void{
sendCommand("logCustomEvent", {host:getHost(), event:event});
}
public static function decodeData(base:String){
return (JSON.decode(RC4.decrypt(uncompressHex(base), _encryptionKey)));
}
public static function postScore(boardName:String, value:uint, tag:String=""):void{
if (((!(boardName)) || ((boardName == "")))){
sendError({command_id:getCommandID("postScore")}, new APIError("MISSING_PARAM", "missing required parameter(s)"));
return;
};
if (tag == null){
tag = "";
};
sendSecureCommand("postScore", {user_name:user_name, board:boardName, value:value, publisher_id:publisher_id, tag:tag});
}
private static function onCommandComplete(e:Event):void{
var response:Object;
var error:APIError;
var loader:SmartURLLoader = SmartURLLoader(e.target);
echo((("INPUT: \n" + loader.response) + "\n"));
var i:uint;
while (i < _preloadAssets.length) {
if (_preloadAssets[i] == loader){
_preloadAssets.splice(i, 1);
break;
};
i++;
};
if (loader.response){
response = JSON.decode(loader.response);
} else {
response = {success:false};
};
if (!response.success){
trace(("Error: " + response));
error = new APIError(response.error_code, response.error_msg);
sendError(response, error);
} else {
response.owner = loader.owner;
doEvent(response);
};
}
public static function encodeData(data:Object):String{
return (compressHex(RC4.encrypt(JSON.encode(data), _encryptionKey)));
}
private static function populateMedals(medal_list:Array):void{
var i:uint;
var m:Object;
if (_medals === null){
_medals = new Array();
i = 0;
while (i < medal_list.length) {
m = medal_list[i];
_medals.push(Medal.createFromObject(m));
i++;
};
};
trace("[NewgroundsAPI] :: Medals loaded!");
}
private static function doEvent(e:Object):void{
var msg:String;
var packet:Object;
var user:String;
var _local7:Boolean;
var _local8:ScoreBoard;
var _local9:SaveFile;
var _local10:Array;
var medalsUnlocked:*;
var medalId:String;
var medal:Medal;
var group:SaveGroup;
var i:uint;
var fileData:Object;
var j:uint;
switch (getCommandName(e.command_id)){
case "connectMovie":
timeoutTimer.stop();
sendMessage("You have successfully connected to the Newgrounds API Gateway");
sendMessage((("Movie identified as \"" + e.movie_name) + "\""));
callListener(APIEvent.API_CONNECTED, e.success, {title:e.movie_name});
_local7 = false;
if (e.ad_status === -1){
msg = "This movie was not approved to run Flash Ads.";
sendWarning(msg);
sendWarning((("visit " + AD_TERMS_URL) + " to view our approval guidelines"));
if (!e.ad_url){
callListener(APIEvent.ADS_APPROVED, false, new APIError("FLASH_ADS_NOT_APPROVED", msg));
} else {
_local7 = true;
};
} else {
if (e.ad_status === 0){
msg = "Flash Ads are currently awaiting approval.";
sendNotice(msg);
if (!e.ad_url){
callListener(APIEvent.ADS_APPROVED, false, new APIError("FLASH_ADS_NOT_APPROVED", msg));
} else {
_local7 = true;
};
};
};
if (e.ad_url){
ad_url = unescape(e.ad_url);
if (!_local7){
sendMessage("This movie has been approved to run Flash Ads!");
};
_adsApproved = true;
callListener(APIEvent.ADS_APPROVED, true);
};
if (e.deny_host){
msg = (getHost() + " does not have permission to run this movie!");
sendWarning(msg);
sendWarning(("\tUpdate your API configuration to unblock " + getHost()));
callListener(APIEvent.HOST_BLOCKED, true, {real_url:unescape(e.movie_url), url:getOfficialURL()});
};
if (e.movie_version){
sendWarning("According to your API Configuration, this version is out of date.");
if (version){
sendWarning(("\tThe this movie is version " + version));
};
sendWarning(("\tThe most current version is " + e.movie_version));
callListener(APIEvent.NEW_VERSION_AVAILABLE, true, {version:e.movie_version, real_url:unescape(e.movie_url), url:getOfficialURL()});
};
if (e.request_portal_url){
sendCommand("setPortalID", {portal_url:_host});
};
sendCommand("preloadSettings", {publisher_id:publisher_id, user_id:user_id});
break;
case "preloadSettings":
if (e.medals){
populateMedals(e.medals);
if (((!(hasUserSession())) && (!(debugMode)))){
echo("Checking for SharedObject Medals...");
medalsUnlocked = loadLocal("medals_unlocked");
if (medalsUnlocked){
for (medalId in medalsUnlocked) {
if (medalsUnlocked[medalId]){
medal = getMedalById(uint(medalId));
echo(("Now unlocking " + medal.name));
medal.unlocked = true;
};
};
};
};
};
if (e.save_groups){
populateSaveGroups(e.save_groups);
};
if (e.save_file_path){
_saveFilePath = (e.save_file_path + "/");
};
if (e.image_file_path){
_imageFilePath = (e.image_file_path + "/");
};
if (e.score_boards){
populateScoreBoards(e.score_boards);
};
trace("[NewgroundsAPI] :: Metadata loaded!");
callListener(APIEvent.METADATA_LOADED);
if (((_saveFileId) && (_saveGroupId))){
group = getSaveGroupById(_saveGroupId);
if (group){
callListener(APIEvent.FILE_REQUESTED, true, {save_id:_saveFileId, group:group});
};
};
_preloadComplete = true;
break;
case "logCustomEvent":
if (e.success){
sendMessage((("Event '" + e.event) + "' was logged."));
};
callListener(APIEvent.EVENT_LOGGED, e.success, {event:e.event});
break;
case "postScore":
if (e.success){
user = "User";
if (user_email){
user = user_email;
} else {
if (user_name){
user = user_name;
};
};
_local8 = getScoreBoardById(e.board);
if (_local8){
sendMessage((((((user + " posted ") + e.value) + " to '") + _local8.name) + "'"));
};
packet = {score:e.score, value:e.value, username:user};
};
callListener(APIEvent.SCORE_POSTED, e.success, packet);
break;
case "loadScores":
packet = new Object();
_local8 = getScoreBoardById(e.board);
if (_local8){
_local8.setScores(e.scores, e.period, e.page, e.num_results);
};
callListener(APIEvent.SCORES_LOADED, e.success, _local8);
break;
case "unlockMedal":
if (_medals){
medal = getMedalByName(e.medal_name);
if (medal.unlocked){
return;
};
medal.unlocked = true;
callListener(APIEvent.MEDAL_UNLOCKED, e.success, medal);
};
break;
case "getMedals":
populateMedals(e.medals);
callListener(APIEvent.MEDALS_LOADED, e.success, packet);
break;
case "loadSaveFile":
group = getSaveGroupById(e.group_id);
_local9 = new SaveFile(group);
_local9.id = e.file.save_id;
_local9.name = e.file.filename;
_local9.fileUrl = (_saveFilePath + e.file.file);
_local9.thumbnailUrl = (_imageFilePath + e.file.thumb);
_local9.authorName = e.file.user_name;
_local9.authorId = e.file.user_id;
_local9.description = e.file.description;
if (((e.file.keys) && (e.file.keys.length))){
i = 0;
while (i < e.file.keys.length) {
_local9.setKey(e.file.keys[i].id, e.file.keys[i].value);
i++;
};
};
if (((e.file.ratings) && (e.file.ratings.length))){
i = 0;
while (i < e.file.ratings.length) {
_local9.setRating(e.file.ratings[i].id, e.file.ratings[i].votes, e.file.ratings[i].score);
i++;
};
};
if (e.get_contents){
_local9.loadContents();
};
callListener(APIEvent.FILE_INITIALIZED, e.success, _local9);
break;
case "lookupSaveFiles":
_local10 = [];
i = 0;
while (i < e.files.length) {
fileData = e.files[i];
_local9 = new SaveFile(getSaveGroupById(e.group_id));
_local9.name = fileData.filename;
_local9.id = fileData.save_id;
_local9.description = fileData.description;
_local9.thumbnailUrl = (_imageFilePath + fileData.thumb);
_local9.fileUrl = (_saveFilePath + fileData.file);
_local9.authorName = fileData.user_name;
_local9.authorId = fileData.user_id;
if (((fileData.keys) && (fileData.keys.length))){
j = 0;
while (j < fileData.keys.length) {
_local9.setKey(fileData.keys[j].id, fileData.keys[j].value);
j++;
};
};
if (((fileData.ratings) && (fileData.ratings.length))){
j = 0;
while (j < fileData.ratings.length) {
_local9.setRating(fileData.ratings[j].id, fileData.ratings[j].votes, fileData.ratings[j].score);
j++;
};
};
_local10.push(_local9);
i++;
};
e.owner.dispatchEvent(new APIEvent(APIEvent.QUERY_COMPLETE, e.success, _local10));
break;
case "rateSaveFile":
_local9 = e.owner;
if (e.success){
_local9.setRating(e.rating_id, e.votes, e.score);
};
_local9.dispatchEvent(new APIEvent(APIEvent.VOTE_COMPLETE, e.success, e));
break;
case "saveFile":
packet = {save_id:e.save_id, filename:e.filename, file_url:e.file_url, thumbnail:e.thumbnail, icon:e.icon};
e.owner.dispatchEvent(new APIEvent(APIEvent.FILE_SAVED, e.success, packet));
break;
case "checkFilePrivs":
packet = {filename:e.filename, folder:e.folder, can_read:e.can_read, can_write:e.can_write};
callListener(APIEvent.FILE_PRIVS_LOADED, e.success, packet);
break;
};
}
public static function loadMedals():void{
if (_medals){
dispatchEvent(new APIEvent(APIEvent.MEDALS_LOADED, true, medals));
return;
};
var params:Object = new Object();
if (hasUserSession()){
params.publisher_id = publisher_id;
params.user_id = user_id;
};
sendCommand("getMedals", params);
}
public static function connect(loaderInfo:LoaderInfo, m_id:String, encrypt_key:String=null):void{
var loaderInfo = loaderInfo;
var m_id = m_id;
var encrypt_key = encrypt_key;
if (!loaderInfo){
fatalError("Null loaderInfo paremeter passed in to connectMovie!", "");
return;
};
if (loaderInfo.loader){
loaderInfo = loaderInfo.loader.loaderInfo;
};
//unresolved jump
var _slot1 = error;
_host = loaderInfo.url;
if ((((_host.indexOf("http://") > -1)) || ((_host.indexOf("https://") > -1)))){
_host = _host.split("/")[2].toLowerCase();
} else {
_host = "localhost";
};
var flashVars:Object = loaderInfo.parameters;
if (isPublishedHost()){
debugMode = false;
};
if (((!(debugMode)) && (flashVars))){
if (flashVars.NewgroundsAPI_UserName){
user_name = flashVars.NewgroundsAPI_UserName;
};
if (flashVars.NewgroundsAPI_UserID){
user_id = flashVars.NewgroundsAPI_UserID;
};
if (flashVars.NewgroundsAPI_PublisherID){
publisher_id = flashVars.NewgroundsAPI_PublisherID;
} else {
publisher_id = 1;
};
if (flashVars.NewgroundsAPI_UserpageFormat){
_userpageFormat = flashVars.NewgroundsAPI_UserpageFormat;
};
if (flashVars.NewgroundsAPI_SessionID){
session_id = flashVars.NewgroundsAPI_SessionID;
};
if (flashVars.NewgroundsAPI_SaveGroupID){
_saveGroupId = flashVars.NewgroundsAPI_SaveGroupID;
};
if (flashVars.NewgroundsAPI_SaveFileID){
_saveFileId = flashVars.NewgroundsAPI_SaveFileID;
};
} else {
publisher_id = 1;
session_id = "D3bu64p1U53R";
user_id = 10;
user_name = "API-Debugger";
};
if (connected){
return;
};
timeoutTimer.start();
if (!m_id){
fatalError("NewgroundsAPI.connectMovie() - missing required movieId parameter", "connectMovie");
};
_movieId = String(m_id);
_trackerId = uint(_movieId.substring(0, _movieId.indexOf(":")));
_encryptionKey = encrypt_key;
connected = true;
sendCommand("connectMovie", {host:getHost(), movie_version:version});
}
public static function saveLocal(save_id:String, save_data:Object, size_allocation:uint=0):void{
var sharedObj:SharedObject;
var save_id = save_id;
var save_data = save_data;
var size_allocation = size_allocation;
if (!sharedObjects[save_id]){
sharedObjects[save_id] = SharedObject.getLocal(((("ng_ap_secure_" + _trackerId) + "_") + save_id));
};
sharedObj = sharedObjects[save_id];
sharedObj.data[save_id] = encodeData(save_data);
sharedObj.flush();
//unresolved jump
var _slot1 = e;
sendWarning(("saveLocal ERROR: " + _slot1));
}
public static function getPeriodName(p:String):String{
var i:String;
for (i in period_aliases) {
if (i == p){
return (period_aliases[i].name);
};
};
return (null);
}
public static function getSaveGroupByName(groupName:String):SaveGroup{
if (((!(_saveGroups)) || ((_saveGroups.length < 1)))){
sendWarning("No save groups found");
return (null);
};
var i:uint;
while (i < _saveGroups.length) {
if (_saveGroups[i].name == groupName){
return (_saveGroups[i]);
};
i++;
};
return (null);
}
private static function getCommandID(name:String):String{
return (name);
}
public static function hasEventListener(type:String):Boolean{
return (_eventDispatcher.hasEventListener(type));
}
public static function isNewgrounds():Boolean{
return ((((publisher_id == 1)) || ((getHost().toLowerCase().indexOf("ungrounded.net") > -1))));
}
public static function isConnected():Boolean{
return (_connected);
}
}
}//package com.newgrounds
Section 13
//APIError (com.newgrounds.APIError)
package com.newgrounds {
import flash.utils.*;
public class APIError {
public var alias:String;
public var message:String;
public var name:String;
public var code:Number;// = 0
private static const always_caps:Array = new Array("API", "URL", "ID");
public static const error_names:Object = init_names();
public static const aliases:Array = new Array("UNKNOWN_ERROR", "INVALID_API_ID", "MISSING_PARAM", "INVALID_STAT_ID", "INVALID_COMMAND_ID", "FLASH_ADS_NOT_APPROVED", "PERMISSION_DENIED", "IDENTIFICATION_REQUIRED", "INVALID_EMAIL_ADDRESS", "BANNED_USER", "SESSION_EXPIRED", "INVALID_SCORE", "INVALID_MEDAL", "INVALID_FOLDER", "FILE_NOT_FOUND", "SITE_ID_REQUIRED", "UPLOAD_IN_PROGRESS", "USER_CANCELLED", "CONFIRM_REQUEST", "CONNECTION_FAILED");
public static const error_codes:Object = init_codes();
public function APIError(error, msg:String){
super();
if ((error is String)){
error = error_codes[error];
} else {
if (!(error is uint)){
error = 0;
};
};
this.code = error;
this.message = msg;
this.name = error_names[error];
this.alias = aliases[error];
}
public function isError():Boolean{
return (true);
}
private static function init_names():Array{
var alias_parts:Array;
var a:uint;
var c:String;
var result:Array = new Array();
var i:uint;
while (i < aliases.length) {
alias_parts = aliases[i].toLowerCase().split("_");
a = 0;
while (a < alias_parts.length) {
alias_parts[a] = (alias_parts[a].substr(0, 1).toUpperCase() + alias_parts[a].substr(1, alias_parts[a].length));
for each (c in always_caps) {
if (alias_parts[a].toUpperCase() == c){
alias_parts[a] = alias_parts[a].toUpperCase();
};
};
a++;
};
result[i] = alias_parts.join(" ");
i++;
};
return (result);
}
public static function init_codes():Dictionary{
var result:Dictionary = new Dictionary();
var i:uint;
while (i < aliases.length) {
result[aliases[i]] = i;
i++;
};
return (result);
}
}
}//package com.newgrounds
Section 14
//APIEvent (com.newgrounds.APIEvent)
package com.newgrounds {
import flash.events.*;
public class APIEvent extends Event {
private var _error:APIError;
private var _success:Boolean;
private var _target;
private var _data;
public static const AD_ATTACHED:String = "adAttached";
public static const FILE_PRIVS_LOADED:String = "filePrivsLoaded";
public static const ADS_APPROVED:String = "adsApproved";
public static const MEDAL_UNLOCKED:String = "medalUnlocked";
public static const MEDALS_LOADED:String = "medalsLoaded";
public static const FILE_REQUESTED:String = "fileRequested";
public static const METADATA_LOADED:String = "metadataLoaded";
public static const NEW_VERSION_AVAILABLE:String = "newVersionAvailable";
public static const API_CONNECTED:String = "movieConnected";
public static const EVENT_LOGGED:String = "eventLogged";
public static const FILE_SAVED:String = "fileSaved";
public static const SCORE_POSTED:String = "scorePosted";
public static const VOTE_COMPLETE:String = "voteComplete";
public static const FILE_LOADED:String = "fileLoaded";
public static const QUERY_COMPLETE:String = "queryComplete";
public static const SCORES_LOADED:String = "scoresLoaded";
public static const HOST_BLOCKED:String = "hostBlocked";
public static const FILE_INITIALIZED:String = "fileInitialized";
public function APIEvent(type:String, success:Boolean=true, data=undefined){
super(type);
this._data = data;
this._success = success;
}
public function get success():Boolean{
return (this._success);
}
public function get data(){
return (this._data);
}
}
}//package com.newgrounds
Section 15
//BaseN (com.newgrounds.BaseN)
package com.newgrounds {
import flash.utils.*;
public class BaseN {
private var _hashVal:Dictionary;
private var _hashIndex:String;
private var _base:Number;
public function BaseN(hash:String=null){
super();
if (hash){
this._hashIndex = hash;
} else {
this._hashIndex = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~@#$%^&*()+|;/";
};
this._base = this._hashIndex.length;
this._hashVal = new Dictionary();
var i:uint;
while (i < this._base) {
this._hashVal[this._hashIndex.charAt(i)] = i;
i++;
};
}
public function encode(n:Number, minchars:uint=1):String{
var s:String = n.toString();
var str:String = "";
if (s.charAt(0) == "-"){
str = "-";
s = s.substring(1);
};
var halves:Array = s.split(".", 2);
str = (str + this.baseNEncoder(halves[0], minchars));
if (halves.length > 1){
str = (str + ("." + this.baseNEncoder(halves[1])));
};
return (str);
}
private function baseNDecoder(s:String):uint{
var val:uint;
var i:uint;
while (i < s.length) {
val = (val * this._base);
val = (val + this._hashVal[s.charAt(i)]);
i++;
};
return (val);
}
public function decode(s:String):Number{
var val:String = "";
if (s.charAt(0) == "-"){
val = "-";
s = s.substring(1);
};
var halves:Array = s.split(".", 2);
val = (val + this.baseNDecoder(halves[0]));
if (halves.length > 1){
val = (val + ".");
val = (val + this.baseNDecoder(halves[1]));
};
return (Number(val));
}
private function baseNEncoder(n:uint, minchars:uint=1):String{
var str:String = "";
var val:uint = n;
while (val != 0) {
str = (this._hashIndex.charAt((val % this._base)) + str);
val = (val / this._base);
};
if (minchars){
while (str.length < minchars) {
str = (this._hashIndex.charAt(0) + str);
};
};
return (str);
}
}
}//package com.newgrounds
Section 16
//Medal (com.newgrounds.Medal)
package com.newgrounds {
import flash.events.*;
import flash.display.*;
import flash.net.*;
import flash.system.*;
public class Medal {
private var _unlocked:Boolean;// = false
private var _iconLoader:Loader;
private var _difficultyId:uint;
private var _icon:BitmapData;
private var _value:uint;
private var _iconUrl:URLRequest;
private var _name:String;
private var _id:uint;
private static const DIFFICULT_NAMES:Array = [null, "Easy", "Moderate", "Challenging", "Difficult", "Brutal"];
private static const DEFAULT_ICON:BitmapData = new BitmapData(50, 50, false, 0);
public function Medal(id:uint, name:String, value:uint, difficulty:uint, unlocked:Boolean, iconUrl:String){
var id = id;
var name = name;
var value = value;
var difficulty = difficulty;
var unlocked = unlocked;
var iconUrl = iconUrl;
this._icon = DEFAULT_ICON;
super();
this._id = id;
this._name = name;
this._value = value;
this._difficultyId = difficulty;
this._unlocked = unlocked;
if (iconUrl){
this._iconUrl = new URLRequest(iconUrl);
this._iconLoader = new Loader();
this._iconLoader.contentLoaderInfo.addEventListener(Event.INIT, this.onIconLoaderInit);
this._iconLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.onIconLoaderError);
this._iconLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onIconLoaderError);
this._iconLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onIconLoaderComplete);
this._iconLoader.load(this._iconUrl, new LoaderContext(true));
//unresolved jump
var _slot1 = e;
onIconLoaderError(null);
};
}
public function get icon():BitmapData{
return (this._icon);
}
public function set unlocked(b:Boolean):void{
this._unlocked = b;
}
public function get bytesLoaded():uint{
return ((this._iconLoader) ? this._iconLoader.contentLoaderInfo.bytesLoaded : 0);
}
public function get name():String{
return (this._name);
}
private function onIconLoaderComplete(e:Event):void{
var bitmap:Bitmap = (this._iconLoader.content as Bitmap);
this._icon = bitmap.bitmapData;
this._iconLoader.unload();
this._iconLoader = null;
}
public function get bytesTotal():uint{
return ((this._iconLoader) ? this._iconLoader.contentLoaderInfo.bytesTotal : 0);
}
public function get id():uint{
return (this._id);
}
public function unlock():void{
if (!this._unlocked){
API.unlockMedal(this._name);
};
}
private function onIconLoaderError(e:IOErrorEvent):void{
trace((((("[NewgroundsAPI WARNING] :: Failed to load medal icon for " + this.name) + " (") + this._iconUrl.url.split("/").pop()) + ")"));
this._iconLoader.unload();
this._iconLoader = null;
}
private function onIconLoaderInit(e:Event):void{
}
public function get unlocked():Boolean{
return (this._unlocked);
}
public function createIconBitmap():Bitmap{
return (new Bitmap(this.icon));
}
public function toString():String{
return (this._name);
}
public function get value():uint{
return (this._value);
}
public function get difficultyId():uint{
return (this._difficultyId);
}
public function get difficulty():String{
return (DIFFICULT_NAMES[this._difficultyId]);
}
public static function createFromObject(medalData:Object):Medal{
return (new Medal(medalData.medal_id, medalData.medal_name, medalData.medal_value, medalData.medal_difficulty, medalData.medal_unlocked, medalData.medal_icon));
}
}
}//package com.newgrounds
Section 17
//RC4 (com.newgrounds.RC4)
package com.newgrounds {
public class RC4 {
private static var mykey:Array = new Array(0xFF);
private static var sbox:Array = new Array(0xFF);
private static function charsToHex(chars:Array):String{
var result:String = new String("");
var hexes:Array = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
var i:uint;
while (i < chars.length) {
result = (result + (hexes[(chars[i] >> 4)] + hexes[(chars[i] & 15)]));
i++;
};
return (result);
}
public static function encrypt(src:String, key:String):String{
var mtxt:Array = strToChars(src);
var mkey:Array = strToChars(key);
var result:Array = calculate(mtxt, mkey);
return (charsToHex(result));
}
private static function hexToChars(hex:String):Array{
var codes:Array = new Array();
var i:uint = ((hex.substr(0, 2))=="0x") ? 2 : 0;
while (i < hex.length) {
codes.push(parseInt(hex.substr(i, 2), 16));
i = (i + 2);
};
return (codes);
}
public static function encryptbin(src:String, key:String):Array{
var mtxt:Array = strToChars(src);
var mkey:Array = strToChars(key);
var result:Array = calculate(mtxt, mkey);
return (result);
}
public static function decrypt(src:String, key:String):String{
var mtxt:Array = hexToChars(src);
var mkey:Array = strToChars(key);
var result:Array = calculate(mtxt, mkey);
return (charsToStr(result));
}
private static function strToChars(str:String):Array{
var codes:Array = new Array();
var i:uint;
while (i < str.length) {
codes.push(str.charCodeAt(i));
i++;
};
return (codes);
}
private static function calculate(plaintxt:Array, psw:Array):Array{
var k:uint;
var temp:uint;
var cipherby:uint;
var idx:uint;
initialize(psw);
var i:uint;
var j:uint;
var cipher:Array = new Array();
var a:uint;
while (a < plaintxt.length) {
i = ((i + 1) % 0x0100);
j = ((j + sbox[i]) % 0x0100);
temp = sbox[i];
sbox[i] = sbox[j];
sbox[j] = temp;
idx = ((sbox[i] + sbox[j]) % 0x0100);
k = sbox[idx];
cipherby = (plaintxt[a] ^ k);
cipher.push(cipherby);
a++;
};
return (cipher);
}
private static function initialize(pwd:Array):void{
var tempSwap:uint;
var b:uint;
var intLength:uint = pwd.length;
var a:uint;
while (a <= 0xFF) {
mykey[a] = pwd[(a % intLength)];
sbox[a] = a;
a++;
};
a = 0;
while (a <= 0xFF) {
b = (((b + sbox[a]) + mykey[a]) % 0x0100);
tempSwap = sbox[a];
sbox[a] = sbox[b];
sbox[b] = tempSwap;
a++;
};
}
private static function charsToStr(chars:Array):String{
var result:String = new String("");
var i:uint;
while (i < chars.length) {
result = (result + String.fromCharCode(chars[i]));
i++;
};
return (result);
}
}
}//package com.newgrounds
Section 18
//SaveFile (com.newgrounds.SaveFile)
package com.newgrounds {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.net.*;
public class SaveFile extends EventDispatcher {
private var _group:SaveGroup;
private var _status:uint;
private var _fileUrl:String;
private var _ratings:Dictionary;
private var _id:uint;
private var _thumbnailUrl:String;
private var _description:String;
private var _keys:Dictionary;
private var _authorName:String;
private var _filename:String;
private var _thumbnail:BitmapData;
private var _authorId:uint;
private var _contents;
public function SaveFile(group:SaveGroup){
super();
this._keys = new Dictionary();
this._ratings = new Dictionary();
this._group = group;
this._description = "";
}
public function get authorId():uint{
return (this._authorId);
}
public function get name():String{
return (this._filename);
}
public function set authorId(value:uint):void{
this._authorId = value;
}
override public function toString():String{
var key:Object;
var rating:Object;
var str = (((((("Save File " + this._filename) + " ID: ") + this._id) + "\n ") + this._description) + "\n");
for each (key in this._keys) {
str = (str + ((((" " + this._group.getKeyById(key.id).name) + ": ") + key.val) + "\n"));
};
for each (rating in this._ratings) {
str = (str + ((((((" " + this._group.getRatingById(rating.id).name) + "\n Score: ") + rating.score) + " Votes: ") + rating.votes) + "\n"));
};
return (str);
}
public function getRating(rating):Object{
var r:SaveRating;
if ((rating is String)){
r = this._group.getRatingByName(rating);
} else {
r = this._group.getRatingById(rating);
};
if (r){
return (this._ratings[r]);
};
return (null);
}
public function set name(s:String):void{
this._filename = s;
}
public function get contents(){
return (this._contents);
}
public function get id():uint{
return (this._id);
}
public function setKey(key, value):void{
var k:SaveKey;
if ((key is String)){
k = this._group.getKeyByName(key);
} else {
k = this._group.getKeyById(key);
};
if (k){
this._keys[k] = {id:k.id, val:value};
};
}
public function setRating(rating, votes:Number, score:Number):void{
var r:SaveRating;
if ((rating is String)){
r = this._group.getRatingByName(rating);
} else {
r = this._group.getRatingById(rating);
};
if (r){
this._ratings[r] = {id:r.id, name:r.name, votes:votes, score:score};
};
}
public function loadContents():void{
var loader:SmartURLLoader;
if (this._fileUrl){
loader = new SmartURLLoader();
loader.responseFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, this.onContentsLoaded);
loader.load(this._fileUrl);
};
}
public function toObject():Object{
var key:Object;
var obj:Object = {group:this.groupId, filename:this.name, description:this.description, shared:true};
obj.keys = [];
for each (key in this._keys) {
obj.keys.push({id:key.id, value:key.val});
};
return (obj);
}
public function getKey(key){
var k:SaveKey;
if ((key is String)){
k = this._group.getKeyByName(key);
} else {
k = this._group.getKeyById(key);
};
if (k){
return (this._keys[k]);
};
return (null);
}
public function set fileUrl(s:String):void{
this._fileUrl = s;
}
public function get groupName():String{
return (this._group.name);
}
public function set contents(o):void{
this._contents = o;
}
public function get authorName():String{
return (this._authorName);
}
public function set id(i:uint):void{
this._id = i;
}
public function loadAuthorPage(){
API.loadUserPage(this._authorId, this._authorName);
}
public function sendRating(rating:String, vote:Number):void{
var ratingObject:SaveRating = this._group.getRatingByName(rating);
if (!ratingObject){
trace((("[NewgroundsAPISaveFile] " + rating) + " is not a recognized save file"));
return;
};
if ((((vote < ratingObject.minValue)) || ((vote > ratingObject.maxValue)))){
trace(((("[NewgroundsAPISaveFile] Vote must be between " + ratingObject.minValue) + " and ") + ratingObject.maxValue));
return;
};
ratingObject.voted = true;
API.rateSaveFile(this, ratingObject, vote);
}
public function set thumbnailUrl(s:String):void{
this._thumbnailUrl = s;
}
public function set thumbnail(bData:BitmapData):void{
if (this._thumbnail){
this._thumbnail.dispose();
};
this._thumbnail = bData.clone();
}
public function get groupType():uint{
return (this._group.type);
}
public function get fileUrl():String{
return (this._fileUrl);
}
public function get thumbnailUrl():String{
return (this._thumbnailUrl);
}
public function get shared():Boolean{
return (true);
}
public function set authorName(value:String):void{
this._authorName = value;
}
public function get thumbnail():BitmapData{
return (this._thumbnail);
}
public function set description(s:String):void{
this._description = s;
}
public function get groupId():uint{
return (this._group.id);
}
public function get description():String{
return (this._description);
}
public function save():void{
API.saveFile(this);
}
private function onContentsLoaded(e:Event):void{
var byteArray:ByteArray = e.target.response;
byteArray.uncompress();
var tag:uint = byteArray.readUnsignedByte();
if (tag == 0){
this._contents = new ByteArray();
this._contents.writeBytes(byteArray, 1);
} else {
this._contents = byteArray.readObject();
};
dispatchEvent(new APIEvent(APIEvent.FILE_LOADED, true, this.contents));
}
}
}//package com.newgrounds
Section 19
//SaveGroup (com.newgrounds.SaveGroup)
package com.newgrounds {
public class SaveGroup {
private var _id:uint;
private var _keys:Array;
private var _type:uint;
private var _name:String;
private var _ratings:Array;
private var _files:Array;
public static const TYPE_SYSTEM:uint = 0;
public static const TYPE_PRIVATE:uint = 1;
public static const TYPE_MODERATED:uint = 3;
public static const TYPE_PUBLIC:uint = 2;
public function SaveGroup(groupId:uint, groupName:String, groupType:uint){
super();
this._name = groupName;
this._id = groupId;
this._type = groupType;
this._ratings = [];
this._keys = [];
this._files = [];
}
public function toString():String{
return ((((((("SaveGroup { name: " + this._name) + ", id: ") + this._id) + ", keys: ") + this._keys) + "}"));
}
public function getRatingById(ratingId:uint):SaveRating{
var i:uint;
while (i < this._ratings.length) {
if (this._ratings[i].id == ratingId){
return (this._ratings[i]);
};
i++;
};
return (null);
}
public function getKeyByName(keyName:String):SaveKey{
var i:uint;
while (i < this._keys.length) {
if (this._keys[i].name == keyName){
return (this._keys[i]);
};
i++;
};
return (null);
}
public function get name():String{
return (this._name);
}
public function getKeyById(keyId:uint):SaveKey{
var i:uint;
while (i < this._keys.length) {
if (this._keys[i].id == keyId){
return (this._keys[i]);
};
i++;
};
return (null);
}
public function addRating(rating:SaveRating):void{
this._ratings.push(rating);
}
public function get id():uint{
return (this._id);
}
public function createQuery():SaveGroupQuery{
return (new SaveGroupQuery(this));
}
public function get keys():Array{
return (this._keys.concat());
}
public function getRatingByName(ratingName:String):SaveRating{
var i:uint;
while (i < this._ratings.length) {
if (this._ratings[i].name == ratingName){
return (this._ratings[i]);
};
i++;
};
return (null);
}
public function get ratings():Array{
return (this._ratings.concat());
}
public function get type():uint{
return (this._type);
}
public function addKey(key:SaveKey):void{
this._keys.push(key);
}
public static function createFromObject(groupData:Object):SaveGroup{
var keyData:Object;
var ratingData:Object;
var saveGroup:SaveGroup = new SaveGroup(groupData.group_id, groupData.group_name, groupData.group_type);
var i:uint;
while (i < groupData.keys.length) {
keyData = groupData.keys[i];
saveGroup.addKey(new SaveKey(keyData.id, keyData.name, keyData.type));
i++;
};
i = 0;
while (i < groupData.ratings.length) {
ratingData = groupData.ratings[i];
saveGroup.addRating(new SaveRating(ratingData.id, ratingData.name, ratingData.float, ratingData.min, ratingData.max));
i++;
};
return (saveGroup);
}
}
}//package com.newgrounds
Section 20
//SaveGroupQuery (com.newgrounds.SaveGroupQuery)
package com.newgrounds {
import flash.events.*;
public class SaveGroupQuery extends EventDispatcher {
private var _group:SaveGroup;
private var _fileConditions:Array;
private var _ratingConditions:Array;
private var _resultsPerPage:uint;
private var _sortConditions:Array;
private var _lookupRatings:Array;
private var _randomizeResults:Boolean;
private var _lookupKeys:Array;
private var _page:uint;
private var _groupBy:Array;
private var _keyConditions:Array;
public static const UPDATED_ON:uint = 5;
public static const TABLE_RATINGS:uint = 3;
public static const TABLE_FILES:uint = 1;
public static const TOTAL_VOTES:String = "votes";
public static const AUTHOR_ID:uint = 1;
public static const FILE_STATUS:uint = 7;
public static const TABLE_KEYS:uint = 2;
public static const FILE_NAME:uint = 3;
public static const SCORE:String = "score";
public static const TOTAL_VIEWS:uint = 6;
public static const CREATED_ON:uint = 4;
public static const FILE_ID:uint = 0;
public static const AUTHOR_NAME:uint = 2;
public function SaveGroupQuery(group:SaveGroup){
super();
this._group = group;
this.reset();
}
public function addKeyCondition(keyName:String, operator:String, value):void{
var key:SaveKey = this._group.getKeyByName(keyName);
if (!key){
return;
};
if (!this.checkValue(value, key.type)){
return;
};
this._keyConditions.push({key_id:key.id, operator:operator, value:value});
}
public function sortOn(field:uint, sortDescending:Boolean=false):void{
this.addSortCondition(TABLE_FILES, field, sortDescending);
}
public function set isRandomized(b:Boolean):void{
this._randomizeResults = b;
}
public function get isRandomized():Boolean{
return (this._randomizeResults);
}
public function groupByRating(ratingName:String):void{
var rating:SaveRating = this._group.getRatingByName(ratingName);
if (!rating){
return;
};
this._groupBy.push({table:TABLE_RATINGS, field:rating.id});
}
public function execute():void{
API.executeSaveQuery(this);
}
public function get page():uint{
return (this._page);
}
public function groupByKey(keyName:String):void{
var key:SaveKey = this._group.getKeyByName(keyName);
if (!key){
return;
};
this._groupBy.push({table:TABLE_KEYS, field:key.id});
}
public function sortOnKey(keyName:String, sortDescending:Boolean=false):void{
this.addSortCondition(TABLE_KEYS, this._group.getKeyByName(keyName).id, sortDescending);
}
public function toObject():Object{
var query:Object = {page:this._page, num_results:this._resultsPerPage};
if (this.isRandomized){
query.randomize = 1;
};
if (((this._fileConditions) && ((this._fileConditions.length > 0)))){
query.file_conditions = this._fileConditions;
};
if (((this._keyConditions) && ((this._keyConditions.length > 0)))){
query.key_conditions = this._keyConditions;
};
if (((this._ratingConditions) && ((this._ratingConditions.length > 0)))){
query.rating_conditions = this._ratingConditions;
};
if (((this._sortConditions) && ((this._sortConditions.length > 0)))){
query.sort_conditions = this._sortConditions;
};
if (((this._lookupKeys) && ((this._lookupKeys.length > 0)))){
query.lookup_keys = this._lookupKeys;
};
if (((this._lookupRatings) && ((this._lookupRatings.length > 0)))){
query.lookup_ratings = this._lookupRatings;
};
if (((this._groupBy) && ((this._groupBy.length > 0)))){
query.group_by = this._groupBy;
};
return (query);
}
public function reset():void{
this._fileConditions = [];
this._keyConditions = [];
this._ratingConditions = [];
this._sortConditions = [];
this._groupBy = [];
this._lookupKeys = [];
this._lookupRatings = [];
this._randomizeResults = false;
this._resultsPerPage = 20;
this._page = 1;
}
public function includeKey(keyName:String):void{
var key:SaveKey = this._group.getKeyByName(keyName);
if (key){
this._lookupKeys.push(key.id);
};
}
private function checkValue(obj, type:uint):Boolean{
return (true);
}
public function set page(n:uint):void{
this._page = n;
}
public function addRatingCondition(ratingName:String, operator:String, value, column:String="score"):void{
var rating:SaveRating = this._group.getRatingByName(ratingName);
if (!rating){
return;
};
this._ratingConditions.push({rating_id:rating.id, operator:operator, value:value, column:column});
}
public function includeRating(ratingName:String):void{
var rating:SaveRating = this._group.getRatingByName(ratingName);
if (rating){
this._lookupRatings.push(rating.id);
};
}
public function sortOnRating(ratingName:String, sortDescending:Boolean=false, column:String="score"):void{
this.addSortCondition(TABLE_RATINGS, this._group.getRatingByName(ratingName).id, sortDescending, column);
}
public function set resultsPerPage(n:uint):void{
this._resultsPerPage = n;
}
public function excludeRating(ratingName:String):void{
var rating:SaveRating = this._group.getRatingByName(ratingName);
var i:uint;
while (i < this._lookupRatings.length) {
if (this._lookupRatings[i] == rating.id){
this._lookupRatings.splice(i, 1);
return;
};
i++;
};
}
public function addFileCondition(field:uint, operator:String, value):void{
this._fileConditions.push({field:field, operator:operator, value:value});
}
public function excludeKey(keyName:String):void{
var key:SaveKey = this._group.getKeyByName(keyName);
var i:uint;
while (i < this._lookupKeys.length) {
if (this._lookupKeys[i] == key.id){
this._lookupKeys.splice(i, 1);
return;
};
i++;
};
}
public function get resultsPerPage():uint{
return (this._resultsPerPage);
}
public function get groupId():uint{
return (this._group.id);
}
override public function toString():String{
return ("");
}
private function addSortCondition(table:uint, field:uint, sortDescending:Boolean=false, extra=null):void{
var sortCondition:Object = {table:table, field:field, desc:sortDescending};
if (extra){
sortCondition.extra = extra;
};
this._sortConditions.push(sortCondition);
}
public function groupBy(field:uint):void{
this._groupBy.push({table:TABLE_FILES, field:field});
}
public function get group():SaveGroup{
return (this._group);
}
}
}//package com.newgrounds
Section 21
//SaveKey (com.newgrounds.SaveKey)
package com.newgrounds {
public class SaveKey {
private var _id:uint;
private var _type:uint;
private var _name:String;
public static const TYPE_BOOLEAN:uint = 4;
public static const TYPE_STRING:uint = 3;
public static const TYPE_FLOAT:uint = 1;
public static const TYPE_INTEGER:uint = 2;
public function SaveKey(id:uint, name:String, type:uint){
super();
this._id = id;
this._name = name;
this._type = type;
}
public function isValueValid(value):Boolean{
if (this._type == TYPE_INTEGER){
return ((((value is int)) || ((value is uint))));
};
if (this._type == TYPE_FLOAT){
return ((((((value is int)) || ((value is uint)))) || ((value is Number))));
};
if (this._type == TYPE_STRING){
return ((value is String));
};
if (this._type == TYPE_BOOLEAN){
return ((((((((value is Boolean)) || ((value === 0)))) || ((value === 1)))) || ((value == ""))));
};
return (false);
}
public function get name():String{
return (this._name);
}
public function get type():uint{
return (this._type);
}
public function get id():uint{
return (this._id);
}
public function toString():String{
return (this._name);
}
}
}//package com.newgrounds
Section 22
//SaveRating (com.newgrounds.SaveRating)
package com.newgrounds {
public class SaveRating {
private var _voted:Boolean;
private var _name:String;
private var _maxValue:Number;
private var _isFloat:Boolean;
private var _id:uint;
private var _minValue:Number;
public function SaveRating(id:uint, name:String, isFloat:Boolean, minValue:Number=-INF, maxValue:Number=INF){
super();
this._id = id;
this._name = name;
this._isFloat = isFloat;
this._minValue = minValue;
this._maxValue = maxValue;
}
public function get voted():Boolean{
return (this._voted);
}
public function set voted(b:Boolean):void{
this._voted = b;
}
public function toString():String{
return (this._name);
}
public function get maxValue():Number{
return (this._maxValue);
}
public function get name():String{
return (this._name);
}
public function get isFloat():Boolean{
return (this._isFloat);
}
public function get id():uint{
return (this._id);
}
public function get minValue():Number{
return (this._minValue);
}
}
}//package com.newgrounds
Section 23
//Score (com.newgrounds.Score)
package com.newgrounds {
public class Score {
private var _board:ScoreBoard;
private var _position:uint;
private var _numeric_value:uint;
private var _value:String;
private var _username:String;
private var _tag:String;
public function Score(board:ScoreBoard, position:Number, username:String, value:String, numeric_value:uint, tag:String){
super();
this._board = board;
this._position = position;
this._username = username;
this._value = value;
this._numeric_value = numeric_value;
this._tag = tag;
}
public function get tag():String{
return (this._tag);
}
public function get board():ScoreBoard{
return (this._board);
}
public function get position():uint{
return (this._position);
}
public function get value():String{
return (this._value);
}
public function get username():String{
return (this._username);
}
public function get numeric_value():uint{
return (this._numeric_value);
}
}
}//package com.newgrounds
Section 24
//ScoreBoard (com.newgrounds.ScoreBoard)
package com.newgrounds {
import flash.events.*;
public class ScoreBoard extends EventDispatcher {
private var _scores:Array;
private var _tag:String;
private var _period:String;// = "Today"
private var _name:String;
private var _page:uint;// = 1
private var _id:uint;
private var _num_results:uint;// = 10
public function ScoreBoard(id:uint, name:String, tag:String){
super();
this._name = name;
this._id = id;
this._scores = [];
this._tag = tag;
}
public function get period():String{
return (this._period);
}
public function get name():String{
return (this._name);
}
public function postScore(value:uint):void{
API.postScore(this._name, value);
}
public function get page():uint{
return (this._page);
}
public function get tag():String{
return (this._tag);
}
public function exists():Boolean{
return ((this._id > 0));
}
public function get scores():Array{
return (this._scores);
}
public function get id():Number{
return (this._id);
}
public function loadScores(period:String="Today", page:uint=1, num_results:uint=10):void{
this._period = period;
if (((!(this._period)) || ((this._period == "")))){
this._period = ScoreBoardPeriod.TODAY;
};
this._page = page;
this._num_results = num_results;
API.loadScores(this);
}
function setScores(scores:Array, period:String, page:Number, num_results:Number):void{
var position:uint;
this._period = period;
this._page = page;
this._num_results = num_results;
this._scores = [];
var i:uint;
while (i < scores.length) {
position = (((this._num_results * (this._page - 1)) + 1) + i);
this._scores.push(new Score(this, position, scores[i].username, scores[i].value, scores[i].numeric_value, scores[i].tag));
i++;
};
}
public function get num_results():uint{
return (this._num_results);
}
}
}//package com.newgrounds
Section 25
//ScoreBoardPeriod (com.newgrounds.ScoreBoardPeriod)
package com.newgrounds {
public class ScoreBoardPeriod {
public static const MONTH:String = "This Month";
public static const TODAY:String = "Today";
public static const WEEK:String = "This Week";
public static const ALL_TIME:String = "All-Time";
public static const YEAR:String = "This Year";
}
}//package com.newgrounds
Section 26
//SmartURLLoader (com.newgrounds.SmartURLLoader)
package com.newgrounds {
import flash.events.*;
import flash.utils.*;
import flash.net.*;
import flash.errors.*;
public class SmartURLLoader extends EventDispatcher {
private var _urlRequest:URLRequest;
private var _method:String;// = "GET"
private var _files:Dictionary;
private var _hasVariables:Boolean;
private var _dataFormat:String;// = "text"
private var _urlLoader:URLLoader;
private var _preventCache:Boolean;// = false
private var _variables:Dictionary;
public var owner;
private var _openBrowser:Boolean;// = false
private static const CRLF:String = "
";
private static var _loaders:Dictionary = new Dictionary();
public function SmartURLLoader(){
super();
this._urlRequest = new URLRequest();
this._variables = new Dictionary();
}
public function get response(){
return (this._urlLoader.data);
}
public function set method(m:String):void{
if (((this.hasFiles) && ((m == URLRequestMethod.GET)))){
throw (new IllegalOperationError("GET cannot be used to upload files."));
};
this._method = m;
}
private function onIOError(e:IOErrorEvent):void{
dispatchEvent(e);
this.dispose();
}
public function addVariable(name:String, value=""):void{
this._variables[name] = value;
if (value){
this._hasVariables = true;
};
}
private function onSecurityError(e:SecurityErrorEvent):void{
dispatchEvent(e);
this.dispose();
}
public function get preventCache():Boolean{
return (this._preventCache);
}
public function addFile(fileName:String, data:ByteArray, dataField:String, contentType:String="application/octect-stream"):void{
this.method = URLRequestMethod.POST;
if (!this._files){
this._files = new Dictionary();
};
this._files[fileName] = new File(fileName, data, dataField, contentType);
}
public function get openBrowser():Boolean{
return (this._openBrowser);
}
public function set preventCache(b:Boolean):void{
this._preventCache = b;
}
public function get responseFormat():String{
return (this._dataFormat);
}
private function onComplete(e:Event):void{
dispatchEvent(e);
this.dispose();
}
public function dispose():void{
this._files = null;
this._variables = null;
if (this._urlLoader){
this._urlLoader.removeEventListener(Event.COMPLETE, this.onComplete);
this._urlLoader.removeEventListener(ProgressEvent.PROGRESS, this.onProgress);
this._urlLoader.removeEventListener(IOErrorEvent.IO_ERROR, this.onIOError);
this._urlLoader.removeEventListener(HTTPStatusEvent.HTTP_STATUS, this.onHTTPStatus);
this._urlLoader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError);
this._urlLoader = null;
};
this._urlRequest = null;
_loaders[this] = null;
}
public function get method():String{
return (this._method);
}
public function close():void{
this._urlLoader.close();
//unresolved jump
var _slot1 = e;
}
private function buildMultipartData(boundary:String):ByteArray{
var key:String;
var file:File;
var postData:ByteArray = new ByteArray();
postData.endian = Endian.BIG_ENDIAN;
boundary = ("--" + boundary);
for (key in this._variables) {
postData.writeUTFBytes((boundary + CRLF));
postData.writeUTFBytes(((("Content-Disposition: form-data; name=\"" + key) + "\"") + CRLF));
postData.writeUTFBytes(CRLF);
postData.writeUTFBytes((this._variables[key] + CRLF));
};
if (this.hasFiles){
for each (file in this._files) {
postData.writeUTFBytes((boundary + CRLF));
postData.writeUTFBytes(("Content-Disposition: form-data; name=\"Filename\"" + CRLF));
postData.writeUTFBytes(CRLF);
postData.writeUTFBytes((file.fileName + CRLF));
postData.writeUTFBytes((boundary + CRLF));
postData.writeUTFBytes(((((("Content-Disposition: form-data; name=\"" + file.dataField) + "\"; filename=\"") + file.fileName) + "\"") + CRLF));
postData.writeUTFBytes((("Content-Type: " + file.contentType) + CRLF));
postData.writeUTFBytes(CRLF);
postData.writeBytes(file.data);
postData.writeUTFBytes(CRLF);
};
postData.writeUTFBytes((boundary + CRLF));
postData.writeUTFBytes(("Content-Disposition: form-data; name=\"Upload\"" + CRLF));
postData.writeUTFBytes(CRLF);
postData.writeUTFBytes(("Submit Query" + CRLF));
};
postData.writeUTFBytes((boundary + "--"));
postData.position = 0;
trace(postData.readUTFBytes(postData.length));
postData.position = 0;
return (postData);
}
public function clearVariables():void{
this._variables = new Dictionary();
}
private function onProgress(e:ProgressEvent):void{
dispatchEvent(e);
}
public function load(url:String):void{
var urlVariables:URLVariables;
var key:String;
var boundary:String;
var i:uint;
var event:SecurityErrorEvent;
var url = url;
this._urlRequest.url = url;
if (this._preventCache){
url = (url + ("?seed=" + Math.random()));
if (this._hasVariables){
url = (url + "&");
};
};
this._urlRequest.method = this._method;
if ((((this._urlRequest.method == URLRequestMethod.GET)) || (!(this.hasFiles)))){
this._urlRequest.contentType = "application/x-www-form-urlencoded";
if (this._hasVariables){
urlVariables = new URLVariables();
for (key in this._variables) {
urlVariables[key] = this._variables[key];
};
this._urlRequest.data = urlVariables;
};
} else {
boundary = "";
i = 0;
while (i < 32) {
boundary = (boundary + String.fromCharCode(uint((97 + (Math.random() * 25)))));
i = (i + 1);
};
this._urlRequest.contentType = (("multipart/form-data; boundary=\"" + boundary) + "\"");
this._urlRequest.data = this.buildMultipartData(boundary);
};
if (this.openBrowser){
navigateToURL(this._urlRequest, "_blank");
} else {
this._urlLoader = new URLLoader();
this._urlLoader.dataFormat = this._dataFormat;
this._urlLoader.addEventListener(Event.COMPLETE, this.onComplete);
this._urlLoader.addEventListener(ProgressEvent.PROGRESS, this.onProgress);
this._urlLoader.addEventListener(IOErrorEvent.IO_ERROR, this.onIOError);
this._urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, this.onHTTPStatus);
this._urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError);
_loaders[this._urlLoader] = this;
this._urlLoader.load(this._urlRequest);
//unresolved jump
var _slot1 = error;
event = new SecurityErrorEvent(SecurityErrorEvent.SECURITY_ERROR, false, false, _slot1.message);
onSecurityError(event);
};
}
public function set responseFormat(s:String):void{
this._dataFormat = s;
}
public function clearFiles():void{
this._files = null;
}
private function onHTTPStatus(e:HTTPStatusEvent):void{
dispatchEvent(e);
}
public function set openBrowser(b:Boolean):void{
this._openBrowser = b;
}
public function get hasFiles():Boolean{
return (Boolean(this._files));
}
}
}//package com.newgrounds
import flash.utils.*;
class File {
private var dataField:String;
private var contentType:String;
private var fileName:String;
private var data:ByteArray;
private function File(fileName:String, data:ByteArray, dataField:String="Filedata", contentType:String="application/octet-stream"){
super();
this.fileName = fileName;
this.data = data;
this.dataField = dataField;
this.contentType = contentType;
}
}
Section 27
//BitmapAsset (mx.core.BitmapAsset)
package mx.core {
import flash.display.*;
public class BitmapAsset extends FlexBitmap implements IFlexAsset, IFlexDisplayObject {
mx_internal static const VERSION:String = "3.4.1.10084";
public function BitmapAsset(bitmapData:BitmapData=null, pixelSnapping:String="auto", smoothing:Boolean=false){
super(bitmapData, pixelSnapping, smoothing);
}
public function get measuredWidth():Number{
if (bitmapData){
return (bitmapData.width);
};
return (0);
}
public function get measuredHeight():Number{
if (bitmapData){
return (bitmapData.height);
};
return (0);
}
public function setActualSize(newWidth:Number, newHeight:Number):void{
width = newWidth;
height = newHeight;
}
public function move(x:Number, y:Number):void{
this.x = x;
this.y = y;
}
}
}//package mx.core
Section 28
//ByteArrayAsset (mx.core.ByteArrayAsset)
package mx.core {
import flash.utils.*;
public class ByteArrayAsset extends ByteArray implements IFlexAsset {
mx_internal static const VERSION:String = "3.4.1.10084";
public function ByteArrayAsset(){
super();
}
}
}//package mx.core
Section 29
//EdgeMetrics (mx.core.EdgeMetrics)
package mx.core {
public class EdgeMetrics {
public var top:Number;
public var left:Number;
public var bottom:Number;
public var right:Number;
mx_internal static const VERSION:String = "3.4.1.10084";
public static const EMPTY:EdgeMetrics = new EdgeMetrics(0, 0, 0, 0);
;
public function EdgeMetrics(left:Number=0, top:Number=0, right:Number=0, bottom:Number=0){
super();
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public function clone():EdgeMetrics{
return (new EdgeMetrics(left, top, right, bottom));
}
}
}//package mx.core
Section 30
//FlexBitmap (mx.core.FlexBitmap)
package mx.core {
import flash.display.*;
import mx.utils.*;
public class FlexBitmap extends Bitmap {
mx_internal static const VERSION:String = "3.4.1.10084";
public function FlexBitmap(bitmapData:BitmapData=null, pixelSnapping:String="auto", smoothing:Boolean=false){
var bitmapData = bitmapData;
var pixelSnapping = pixelSnapping;
var smoothing = smoothing;
super(bitmapData, pixelSnapping, smoothing);
name = NameUtil.createUniqueName(this);
//unresolved jump
var _slot1 = e;
}
override public function toString():String{
return (NameUtil.displayObjectToString(this));
}
}
}//package mx.core
Section 31
//FlexMovieClip (mx.core.FlexMovieClip)
package mx.core {
import flash.display.*;
import mx.utils.*;
public class FlexMovieClip extends MovieClip {
mx_internal static const VERSION:String = "3.4.1.10084";
public function FlexMovieClip(){
super();
name = NameUtil.createUniqueName(this);
//unresolved jump
var _slot1 = e;
}
override public function toString():String{
return (NameUtil.displayObjectToString(this));
}
}
}//package mx.core
Section 32
//IBorder (mx.core.IBorder)
package mx.core {
public interface IBorder {
function get borderMetrics():EdgeMetrics;
}
}//package mx.core
Section 33
//IFlexAsset (mx.core.IFlexAsset)
package mx.core {
public interface IFlexAsset {
}
}//package mx.core
Section 34
//IFlexDisplayObject (mx.core.IFlexDisplayObject)
package mx.core {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import flash.accessibility.*;
public interface IFlexDisplayObject extends IBitmapDrawable, IEventDispatcher {
function get visible():Boolean;
function get rotation():Number;
function localToGlobal(void:Point):Point;
function get name():String;
function set width(flash.display:Number):void;
function get measuredHeight():Number;
function get blendMode():String;
function get scale9Grid():Rectangle;
function set name(flash.display:String):void;
function set scaleX(flash.display:Number):void;
function set scaleY(flash.display:Number):void;
function get measuredWidth():Number;
function get accessibilityProperties():AccessibilityProperties;
function set scrollRect(flash.display:Rectangle):void;
function get cacheAsBitmap():Boolean;
function globalToLocal(void:Point):Point;
function get height():Number;
function set blendMode(flash.display:String):void;
function get parent():DisplayObjectContainer;
function getBounds(String:DisplayObject):Rectangle;
function get opaqueBackground():Object;
function set scale9Grid(flash.display:Rectangle):void;
function setActualSize(_arg1:Number, _arg2:Number):void;
function set alpha(flash.display:Number):void;
function set accessibilityProperties(flash.display:AccessibilityProperties):void;
function get width():Number;
function hitTestPoint(_arg1:Number, _arg2:Number, _arg3:Boolean=false):Boolean;
function set cacheAsBitmap(flash.display:Boolean):void;
function get scaleX():Number;
function get scaleY():Number;
function get scrollRect():Rectangle;
function get mouseX():Number;
function get mouseY():Number;
function set height(flash.display:Number):void;
function set mask(flash.display:DisplayObject):void;
function getRect(String:DisplayObject):Rectangle;
function get alpha():Number;
function set transform(flash.display:Transform):void;
function move(_arg1:Number, _arg2:Number):void;
function get loaderInfo():LoaderInfo;
function get root():DisplayObject;
function hitTestObject(mx.core:IFlexDisplayObject/mx.core:IFlexDisplayObject:stage/get:DisplayObject):Boolean;
function set opaqueBackground(flash.display:Object):void;
function set visible(flash.display:Boolean):void;
function get mask():DisplayObject;
function set x(flash.display:Number):void;
function set y(flash.display:Number):void;
function get transform():Transform;
function set filters(flash.display:Array):void;
function get x():Number;
function get y():Number;
function get filters():Array;
function set rotation(flash.display:Number):void;
function get stage():Stage;
}
}//package mx.core
Section 35
//IRepeaterClient (mx.core.IRepeaterClient)
package mx.core {
public interface IRepeaterClient {
function get instanceIndices():Array;
function set instanceIndices(C:\autobuild\3.4.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get isDocument():Boolean;
function set repeaters(C:\autobuild\3.4.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function initializeRepeaterArrays(C:\autobuild\3.4.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:IRepeaterClient):void;
function get repeaters():Array;
function set repeaterIndices(C:\autobuild\3.4.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get repeaterIndices():Array;
}
}//package mx.core
Section 36
//MovieClipAsset (mx.core.MovieClipAsset)
package mx.core {
public class MovieClipAsset extends FlexMovieClip implements IFlexAsset, IFlexDisplayObject, IBorder {
private var _measuredHeight:Number;
private var _measuredWidth:Number;
mx_internal static const VERSION:String = "3.4.1.10084";
public function MovieClipAsset(){
super();
_measuredWidth = width;
_measuredHeight = height;
}
public function get measuredWidth():Number{
return (_measuredWidth);
}
public function get measuredHeight():Number{
return (_measuredHeight);
}
public function setActualSize(newWidth:Number, newHeight:Number):void{
width = newWidth;
height = newHeight;
}
public function move(x:Number, y:Number):void{
this.x = x;
this.y = y;
}
public function get borderMetrics():EdgeMetrics{
if (scale9Grid == null){
return (EdgeMetrics.EMPTY);
};
return (new EdgeMetrics(scale9Grid.left, scale9Grid.top, Math.ceil((measuredWidth - scale9Grid.right)), Math.ceil((measuredHeight - scale9Grid.bottom))));
}
}
}//package mx.core
Section 37
//MovieClipLoaderAsset (mx.core.MovieClipLoaderAsset)
package mx.core {
import flash.events.*;
import flash.utils.*;
import flash.display.*;
import flash.system.*;
public class MovieClipLoaderAsset extends MovieClipAsset implements IFlexAsset, IFlexDisplayObject {
protected var initialHeight:Number;// = 0
private var loader:Loader;// = null
private var initialized:Boolean;// = false
protected var initialWidth:Number;// = 0
private var requestedHeight:Number;
private var requestedWidth:Number;
mx_internal static const VERSION:String = "3.4.1.10084";
public function MovieClipLoaderAsset(){
super();
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
if (("allowLoadBytesCodeExecution" in loaderContext)){
loaderContext["allowLoadBytesCodeExecution"] = true;
};
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.loadBytes(movieClipData, loaderContext);
addChild(loader);
}
override public function get width():Number{
if (!initialized){
return (initialWidth);
};
return (super.width);
}
override public function set width(value:Number):void{
if (!initialized){
requestedWidth = value;
} else {
loader.width = value;
};
}
override public function get measuredHeight():Number{
return (initialHeight);
}
private function completeHandler(event:Event):void{
initialized = true;
initialWidth = loader.width;
initialHeight = loader.height;
if (!isNaN(requestedWidth)){
loader.width = requestedWidth;
};
if (!isNaN(requestedHeight)){
loader.height = requestedHeight;
};
dispatchEvent(event);
}
override public function set height(value:Number):void{
if (!initialized){
requestedHeight = value;
} else {
loader.height = value;
};
}
override public function get measuredWidth():Number{
return (initialWidth);
}
override public function get height():Number{
if (!initialized){
return (initialHeight);
};
return (super.height);
}
public function get movieClipData():ByteArray{
return (null);
}
}
}//package mx.core
Section 38
//mx_internal (mx.core.mx_internal)
package mx.core {
public namespace mx_internal = "http://www.adobe.com/2006/flex/mx/internal";
}//package mx.core
Section 39
//NameUtil (mx.utils.NameUtil)
package mx.utils {
import flash.display.*;
import flash.utils.*;
import mx.core.*;
public class NameUtil {
mx_internal static const VERSION:String = "3.4.1.10084";
private static var counter:int = 0;
public function NameUtil(){
super();
}
public static function displayObjectToString(displayObject:DisplayObject):String{
var result:String;
var o:DisplayObject;
var s:String;
var indices:Array;
var displayObject = displayObject;
o = displayObject;
while (o != null) {
if (((((o.parent) && (o.stage))) && ((o.parent == o.stage)))){
break;
};
s = o.name;
if ((o is IRepeaterClient)){
indices = IRepeaterClient(o).instanceIndices;
if (indices){
s = (s + (("[" + indices.join("][")) + "]"));
};
};
result = ((result == null)) ? s : ((s + ".") + result);
o = o.parent;
};
//unresolved jump
var _slot1 = e;
return (result);
}
public static function createUniqueName(object:Object):String{
if (!object){
return (null);
};
var name:String = getQualifiedClassName(object);
var index:int = name.indexOf("::");
if (index != -1){
name = name.substr((index + 2));
};
var charCode:int = name.charCodeAt((name.length - 1));
if ((((charCode >= 48)) && ((charCode <= 57)))){
name = (name + "_");
};
return ((name + counter++));
}
}
}//package mx.utils
Section 40
//NewgroundsAPIAsset_FlashAd_Container_23 (NewgroundsAPI_fla.NewgroundsAPIAsset_FlashAd_Container_23)
package NewgroundsAPI_fla {
import flash.events.*;
import flash.display.*;
import com.newgrounds.*;
public dynamic class NewgroundsAPIAsset_FlashAd_Container_23 extends MovieClip {
public var ngLinkButton:SimpleButton;
public var adMask:MovieClip;
public function NewgroundsAPIAsset_FlashAd_Container_23(){
addFrameScript(0, this.frame1, 10, this.frame11);
}
function frame1(){
this.ngLinkButton.addEventListener(MouseEvent.CLICK, this.onNGLinkClicked);
}
public function onNGLinkClicked(e:MouseEvent):void{
API.loadNewgrounds();
}
function frame11(){
gotoAndPlay(1);
}
}
}//package NewgroundsAPI_fla
Section 41
//NewgroundsAPIAsset_Load_Indicator_3 (NewgroundsAPI_fla.NewgroundsAPIAsset_Load_Indicator_3)
package NewgroundsAPI_fla {
import flash.events.*;
import flash.display.*;
public dynamic class NewgroundsAPIAsset_Load_Indicator_3 extends MovieClip {
public function NewgroundsAPIAsset_Load_Indicator_3(){
addFrameScript(0, this.frame1);
}
function frame1(){
addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
}
public function onEnterFrame(e:Event):void{
if (((visible) && (stage))){
rotation = (rotation + 30);
} else {
removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
};
}
}
}//package NewgroundsAPI_fla
Section 42
//Log (SWFStats.Log)
package SWFStats {
import flash.events.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
import flash.external.*;
public final class Log {
private static const PingR:Timer = new Timer(30000);
private static const Random:Number = Math.random();
private static const PingF:Timer = new Timer(60000);
public static var GUID:String = "";
private static var Plays:int = 0;
private static var Enabled:Boolean = false;
private static var FirstPing:Boolean = true;
private static var Pings:int = 0;
public static var SourceUrl:String;
private static var HighestGoal:int = 0;
public static var SWFID:int = 0;
public function Log(){
super();
}
private static function GetCookie(n:String):int{
var cookie:SharedObject = SharedObject.getLocal("swfstats");
if (cookie.data[n] == undefined){
return (0);
};
return (int(cookie.data[n]));
}
private static function SaveCookie(n:String, v:int):void{
var cookie:SharedObject = SharedObject.getLocal("swfstats");
cookie.data[n] = v.toString();
cookie.flush();
}
public static function View(swfid:int=0, guid:String="", defaulturl:String=""):void{
SWFID = swfid;
GUID = guid;
Enabled = true;
if ((((SWFID == 0)) || ((GUID == "")))){
Enabled = false;
return;
};
if (((((!((defaulturl.indexOf("http://") == 0))) && (!((Security.sandboxType == "localWithNetwork"))))) && (!((Security.sandboxType == "localTrusted"))))){
Enabled = false;
return;
};
SourceUrl = GetUrl(defaulturl);
if ((((SourceUrl == null)) || ((SourceUrl == "")))){
Enabled = false;
return;
};
Security.allowDomain("http://tracker.swfstats.com/");
Security.allowInsecureDomain("http://tracker.swfstats.com/");
Security.loadPolicyFile("http://tracker.swfstats.com/crossdomain.xml");
Security.allowDomain("http://utils.swfstats.com/");
Security.allowInsecureDomain("http://utils.swfstats.com/");
Security.loadPolicyFile("http://utils.swfstats.com/crossdomain.xml");
var views:int = GetCookie("views");
views++;
SaveCookie("views", views);
Send("View", ("views=" + views));
PingF.addEventListener(TimerEvent.TIMER, PingServer);
PingF.start();
}
public static function LevelCounterMetric(name:String, level):void{
if (!Enabled){
return;
};
Send("LevelMetric", ((("name=" + escape(name)) + "&level=") + level));
}
private static function Send(page:String, data:String):void{
var sendaction:URLLoader = new URLLoader();
sendaction.addEventListener(IOErrorEvent.IO_ERROR, ErrorHandler);
sendaction.addEventListener(HTTPStatusEvent.HTTP_STATUS, StatusChange);
sendaction.addEventListener(SecurityErrorEvent.SECURITY_ERROR, ErrorHandler);
sendaction.load(new URLRequest(((((((((((("http://tracker.swfstats.com/Games/" + page) + ".html?guid=") + GUID) + "&swfid=") + SWFID) + "&") + data) + "&url=") + SourceUrl) + "&") + Random)));
}
public static function Play():void{
if (!Enabled){
return;
};
Plays++;
Send("Play", ("plays=" + Plays));
}
private static function GetUrl(defaulturl:String):String{
var url:String;
var defaulturl = defaulturl;
if (ExternalInterface.available){
url = String(ExternalInterface.call("window.location.href.toString"));
//unresolved jump
var _slot1 = s;
url = defaulturl;
} else {
if (defaulturl.indexOf("http://") == 0){
url = defaulturl;
};
};
if ((((((url == null)) || ((url == "")))) || ((url == "null")))){
if ((((Security.sandboxType == "localWithNetwork")) || ((Security.sandboxType == "localTrusted")))){
url = "http://local-testing/";
} else {
url = null;
};
};
return (url);
}
private static function ErrorHandler(... _args):void{
Enabled = false;
}
public static function LevelRangedMetric(name:String, level, value:int):void{
if (!Enabled){
return;
};
Send("LevelMetricRanged", ((((("name=" + escape(name)) + "&level=") + level) + "&value=") + value));
}
private static function StatusChange(... _args):void{
}
public static function Goal(n:int, name:String):void{
if (!Enabled){
return;
};
if (HighestGoal >= n){
return;
};
HighestGoal = n;
Send("Goal", ((("goal=" + n) + "&name=") + escape(name)));
}
private static function PingServer(... _args):void{
if (!Enabled){
return;
};
Pings++;
Send("Ping", (((FirstPing) ? "&firstping=yes" : "" + "&pings=") + Pings));
if (FirstPing){
PingF.stop();
PingR.addEventListener(TimerEvent.TIMER, PingServer);
PingR.start();
FirstPing = false;
};
}
public static function LevelAverageMetric(name:String, level, value:int):void{
if (!Enabled){
return;
};
Send("LevelMetricAverage", ((((("name=" + escape(name)) + "&level=") + level) + "&value=") + value));
}
public static function CustomMetric(name:String, group:String=null):void{
if (!Enabled){
return;
};
if (group == null){
group = "";
};
Send("CustomMetric", ((("name=" + escape(name)) + "&group=") + escape(group)));
}
}
}//package SWFStats
Section 43
//Main (Main)
package {
import com.newgrounds.*;
import flash.events.*;
import flash.display.*;
import flash.net.*;
import SWFStats.*;
public class Main extends Sprite {
public var Logo:Class;
private var LC:LocalConnection;
public var logo:MovieClip;
public function Main():void{
Logo = Main_Logo;
logo = new Logo();
super();
if (stage){
init();
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
};
}
private function init(e:Event=null):void{
var e = e;
removeEventListener(Event.ADDED_TO_STAGE, init);
LC = new LocalConnection();
LC.connect("xEPLUMBERS");
//unresolved jump
var _slot1 = error;
LC.client = this;
API.addEventListener(APIEvent.MEDAL_UNLOCKED, onMedalUnlocked);
addChild(logo);
}
public function onLCStatus(statusEvent:StatusEvent):void{
if (statusEvent.level == "error"){
trace("LCE");
};
}
private function onMedalUnlocked(e:APIEvent):void{
trace((("Medal " + e.data.name) + " unlocked!"));
LC.send("xEPLUMBERS_ACH", "connectionHandler", ("MEDAL " + e.data.name));
}
public function connectionHandler(LCMessage:String):void{
trace(("LC: " + LCMessage));
switch (LCMessage){
case "x_play":
Log.Play();
Log.CustomMetric("NG_play");
API.logCustomEvent("Play");
break;
case "x_sponsorclick":
Log.CustomMetric("click_doppler");
API.logCustomEvent("sponsorclick");
break;
case "x_NGclick":
API.logCustomEvent("clickNG");
API.loadNewgrounds();
break;
case "x_walkthroughclick":
Log.CustomMetric("click_dopplerwalkthrough");
API.logCustomEvent("clickWalk");
break;
case "x_win":
Log.CustomMetric("endingscreen");
Log.CustomMetric("NG_endingscreen");
API.logCustomEvent("Endingscreen");
API.unlockMedal("King Krusher");
break;
case "x_klikscene":
Log.CustomMetric("click_klikscene");
API.logCustomEvent("clickKlikscene");
API.loadMySite();
break;
case "x_challenge_cheap19":
API.unlockMedal("Easy Way Out");
break;
case "x_challenge_lv8":
API.unlockMedal("Survivalist");
break;
case "x_challenge_6pacifist":
API.unlockMedal("Pacifist");
break;
default:
if (LCMessage.substring(0, 8) == "x_level_"){
Log.LevelCounterMetric("NG_levelstart", LCMessage.substr(8, 2));
};
};
}
}
}//package
Section 44
//Main_Logo (Main_Logo)
package {
import mx.core.*;
import flash.utils.*;
public class Main_Logo extends MovieClipLoaderAsset {
public var dataClass:Class;
private static var bytes:ByteArray = null;
public function Main_Logo(){
dataClass = Main_Logo_dataClass;
super();
initialWidth = (15200 / 20);
initialHeight = (10000 / 20);
}
override public function get movieClipData():ByteArray{
if (bytes == null){
bytes = ByteArray(new dataClass());
};
return (bytes);
}
}
}//package
Section 45
//Main_Logo_dataClass (Main_Logo_dataClass)
package {
import mx.core.*;
public class Main_Logo_dataClass extends ByteArrayAsset {
}
}//package
Section 46
//MochiBot (MochiBot)
package {
import flash.display.*;
import flash.net.*;
import flash.system.*;
public dynamic class MochiBot extends Sprite {
public function MochiBot(){
super();
}
public static function track(parent:Sprite, tag:String):MochiBot{
if (Security.sandboxType == "localWithFile"){
return (null);
};
var self:MochiBot = new (MochiBot);
parent.addChild(self);
Security.allowDomain("*");
Security.allowInsecureDomain("*");
var server:String = "http://core.mochibot.com/my/core.swf";
var lv:URLVariables = new URLVariables();
lv["sb"] = Security.sandboxType;
lv["v"] = Capabilities.version;
lv["swfid"] = tag;
lv["mv"] = "8";
lv["fv"] = "9";
var url:String = self.root.loaderInfo.loaderURL;
if (url.indexOf("http") == 0){
lv["url"] = url;
} else {
lv["url"] = "local";
};
var req:URLRequest = new URLRequest(server);
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
var loader:Loader = new Loader();
self.addChild(loader);
loader.load(req);
return (self);
}
}
}//package
Section 47
//Preloader (Preloader)
package {
import flash.events.*;
import flash.display.*;
import com.newgrounds.*;
import com.newgrounds.components.*;
import flash.utils.*;
import flash.text.*;
import SWFStats.*;
public class Preloader extends MovieClip {
private var Img:Class;
private var adBox:FlashAd;
private var preloader:Shape;
private var progressText:TextField;
private static var playbutton:Sprite = new Sprite();
private static var ready:Boolean = false;
private static var Aub:Class = Preloader_Aub;
private static var buzz:Boolean = false;
private static var Play:Class = Preloader_Play;
private static var playb:Bitmap = new Play();
private static var aub:Bitmap = new Aub();
public function Preloader(){
Img = Preloader_Img;
adBox = new FlashAd();
super();
Log.View(247, "032d84ac-72dd-412e-9077-1ab97eca986e", root.loaderInfo.loaderURL);
MochiBot.track(this, "1b769028");
API.connect(loaderInfo, "11988:oNL8FN9K", "D8iz9tIPdqsDEwKMD2meVkNyjKdrHc5E");
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var _bg:Bitmap = new Img();
addChild(_bg);
var url:String = stage.loaderInfo.url;
var urlStart:Number = (url.indexOf("://") + 3);
var urlEnd:Number = url.indexOf("/", urlStart);
var domain:String = url.substring(urlStart, urlEnd);
var LastDot:Number = (domain.lastIndexOf(".") - 1);
var domEnd:Number = (domain.lastIndexOf(".", LastDot) + 1);
domain = domain.substring(domEnd, domain.length);
addChild(playbutton);
playbutton.addChild(playb);
playbutton.x = 90;
playbutton.y = -80;
playbutton.buttonMode = true;
playbutton.useHandCursor = true;
addChild(adBox);
adBox.x = (380 - (adBox.width / 2));
adBox.y = (200 - (adBox.height / 2));
addEventListener(Event.ENTER_FRAME, checkFrame);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
preloader = new Shape();
preloader.graphics.beginFill(0xFFFFFF);
preloader.graphics.drawRect(0, 0, 8, 8);
preloader.graphics.endFill();
addChild(preloader);
addChild(aub);
playbutton.addEventListener(MouseEvent.MOUSE_OVER, overPlay);
playbutton.addEventListener(MouseEvent.MOUSE_OUT, outPlay);
playbutton.addEventListener(MouseEvent.CLICK, clickPlay);
progressText = new TextField();
var progressTextFormat:TextFormat = new TextFormat("_sans", 10, 0xFFFFFF, true);
progressTextFormat.align = TextFormatAlign.CENTER;
progressText.defaultTextFormat = progressTextFormat;
addChild(progressText);
stage.addEventListener(Event.RESIZE, onResize);
onResize();
}
private function outPlay(e:MouseEvent):void{
buzz = false;
}
private function checkFrame(e:Event):void{
if (buzz){
playbutton.x = ((90 + (Math.random() * 3)) - 1);
};
if (currentFrame == totalFrames){
playbutton.y = 355;
if (ready){
removeEventListener(Event.ENTER_FRAME, checkFrame);
startup();
};
};
}
private function onResize(e:Event=null):void{
if (preloader){
preloader.x = 80;
preloader.y = 420;
};
if (progressText){
progressText.x = 90;
progressText.y = 416;
};
aub.x = 80;
aub.y = 408;
}
private function progress(e:ProgressEvent):void{
if (progressText){
progressText.text = (Math.round(((e.bytesLoaded / e.bytesTotal) * 100)).toString() + " %");
};
if (preloader){
preloader.width = Math.round(((e.bytesLoaded / e.bytesTotal) * 600));
preloader.x = (680 - preloader.width);
aub.x = (preloader.x - 16);
progressText.x = 655;
};
}
private function overPlay(e:MouseEvent):void{
buzz = true;
}
private function clickPlay(e:MouseEvent):void{
ready = true;
playbutton.removeEventListener(MouseEvent.CLICK, clickPlay);
}
private function startup():void{
stop();
removeChild(preloader);
removeChild(progressText);
removeChild(aub);
playbutton.removeEventListener(MouseEvent.MOUSE_OVER, overPlay);
playbutton.removeEventListener(MouseEvent.MOUSE_OUT, outPlay);
removeChild(playbutton);
if (adBox){
removeChild(adBox);
};
this.stage.frameRate = 50;
preloader = null;
progressText = null;
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
var mainClass:Class = (getDefinitionByName("Main") as Class);
addChildAt((new (mainClass) as DisplayObject), 0);
}
}
}//package
Section 48
//Preloader_Aub (Preloader_Aub)
package {
import mx.core.*;
public class Preloader_Aub extends BitmapAsset {
}
}//package
Section 49
//Preloader_Img (Preloader_Img)
package {
import mx.core.*;
public class Preloader_Img extends BitmapAsset {
}
}//package
Section 50
//Preloader_Play (Preloader_Play)
package {
import mx.core.*;
public class Preloader_Play extends BitmapAsset {
}
}//package