Section 1
//MainTimeline (clap_fla.MainTimeline)
package clap_fla {
import flash.utils.*;
import flash.display.*;
import flash.events.*;
import flash.net.*;
import com.newgrounds.components.*;
public dynamic class MainTimeline extends MovieClip {
public var __setPropDict:Dictionary;
public var __id0_:APIConnector;
public var replay:SimpleButton;
public var lesson1:SimpleButton;
public function MainTimeline(){
__setPropDict = new Dictionary(true);
super();
addFrameScript(1, frame2, 3070, frame3071, 0, frame1);
}
function frame3071(){
stop();
lesson1.addEventListener(MouseEvent.CLICK, onLesson1);
replay.addEventListener(MouseEvent.CLICK, onReplay);
}
function __setProp___id0__preload_Layer12_1(){
try {
__id0_["componentInspectorSetting"] = true;
} catch(e:Error) {
};
__id0_.apiId = "21959:exjvRPux ";
__id0_.encryptionKey = "7YTh9Bz0ez2jXQTIs0ThujpzCPMnzy4m ";
__id0_.debugMode = "Simulate Logged-in User";
__id0_.movieVersion = "";
__id0_.connectorType = "Flash Ad + Preloader";
__id0_.redirectOnNewVersion = true;
__id0_.redirectOnHostBlocked = true;
__id0_.adType = "Video";
try {
__id0_["componentInspectorSetting"] = false;
} catch(e:Error) {
};
}
public function onLesson1(_arg1:Event):void{
navigateToURL(new URLRequest("http://www.newgrounds.com/portal/view/574510"), "_blank");
}
function frame1(){
if ((((__setPropDict[__id0_] == undefined)) || (!((int(__setPropDict[__id0_]) == 1))))){
__setPropDict[__id0_] = currentFrame;
__setProp___id0__preload_Layer12_1();
};
}
function frame2(){
play();
}
public function onReplay(_arg1:MouseEvent):void{
gotoAndPlay(1);
}
}
}//package clap_fla
Section 2
//Timeline_14 (clap_fla.Timeline_14)
package clap_fla {
import flash.display.*;
public dynamic class Timeline_14 extends MovieClip {
public function Timeline_14(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
buttonMode = true;
}
}
}//package clap_fla
Section 3
//Timeline_18 (clap_fla.Timeline_18)
package clap_fla {
import flash.display.*;
public dynamic class Timeline_18 extends MovieClip {
public function Timeline_18(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package clap_fla
Section 4
//DefaultMedalIcon (com.newgrounds.assets.DefaultMedalIcon)
package com.newgrounds.assets {
import flash.display.*;
public dynamic class DefaultMedalIcon extends BitmapData {
public function DefaultMedalIcon(_arg1:Number, _arg2:Number){
super(_arg1, _arg2);
}
}
}//package com.newgrounds.assets
Section 5
//DefaultSaveIcon (com.newgrounds.assets.DefaultSaveIcon)
package com.newgrounds.assets {
import flash.display.*;
public dynamic class DefaultSaveIcon extends BitmapData {
public function DefaultSaveIcon(_arg1:Number, _arg2:Number){
super(_arg1, _arg2);
}
}
}//package com.newgrounds.assets
Section 6
//APIConnector (com.newgrounds.components.APIConnector)
package com.newgrounds.components {
import flash.utils.*;
import flash.display.*;
import com.newgrounds.*;
import flash.text.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
import flash.geom.*;
import adobe.utils.*;
import flash.accessibility.*;
import flash.errors.*;
import flash.external.*;
import flash.filters.*;
import flash.media.*;
import flash.printing.*;
import flash.ui.*;
import flash.xml.*;
public dynamic class APIConnector extends MovieClip {
public var encryptionKey:String;
public var loader:Preloader;
public var ad:FlashAd;
public var connectorType:String;
public var className:String;
public var _redirect:Boolean;
public var redirectOnHostBlocked:Boolean;
public var __setPropDict:Dictionary;
public var redirectOnNewVersion:Boolean;
public var movieVersion:String;
public var debugMode:String;
public var apiId:String;
public var adType:String;
public function APIConnector(){
__setPropDict = new Dictionary(true);
super();
addFrameScript(0, frame1, 1, frame2, 2, frame3, 3, frame4, 4, frame5, 5, frame6, 6, frame7, 7, frame8, 8, frame9, 9, frame10, 10, frame11, 11, frame12, 12, frame13, 13, frame14, 14, frame15, 15, frame16, 16, frame17, 17, frame18, 18, frame19, 19, frame20, 20, frame21);
}
public function _apiConnect():void{
var _local1:*;
_local1 = API;
if (((_local1) && (!(_local1.connected)))){
if (!apiId){
Logger.logError("No API ID entered in the API Connector component.", "You can create an API ID for this submission at http://newgrounds.com/account/flashapi", "Enter your API ID into the API Connector using the Component Inspector (Window -> Component Inspector).");
return;
};
switch (debugMode){
case "Off":
default:
_local1.debugMode = _local1.RELEASE_MODE;
break;
case "Simulate Logged-in User":
_local1.debugMode = _local1.DEBUG_MODE_LOGGED_IN;
break;
case "Simulate Logged-out User":
_local1.debugMode = _local1.DEBUG_MODE_LOGGED_OUT;
break;
case "Simulate New Version":
_local1.debugMode = _local1.DEBUG_MODE_NEW_VERSION;
break;
case "Simulate Host Blocked":
_local1.debugMode = _local1.DEBUG_MODE_HOST_BLOCKED;
break;
};
_local1.addEventListener(APIEvent.API_CONNECTED, _onConnected);
_local1.connect(root, apiId, encryptionKey, movieVersion);
};
}
public function _onConnected(_arg1:APIEvent):void{
if (((((redirectOnNewVersion) && (_arg1.success))) && (_arg1.data.newVersion))){
_redirect = true;
};
if (((((redirectOnHostBlocked) && (!(_arg1.success)))) && ((_arg1.error == APIEvent.ERROR_HOST_BLOCKED)))){
_redirect = true;
};
if (_redirect){
gotoAndStop("adPreloader");
forceAlwaysOnTop();
};
}
public function forceAlwaysOnTop():void{
var _local1:uint;
if (parent){
_local1 = (parent.numChildren - 1);
if (parent.getChildIndex(this) != _local1){
parent.setChildIndex(this, _local1);
};
};
if (stage){
x = ((stage.stageWidth - width) / 2);
y = ((stage.stageHeight - height) / 2);
visible = true;
};
if (((root) && ((root is MovieClip)))){
MovieClip(root).stop();
};
}
function __setProp_ad_APIConnector_AD_1(){
try {
ad["componentInspectorSetting"] = true;
} catch(e:Error) {
};
ad.apiId = "";
ad.showBorder = true;
ad.adType = "Video";
try {
ad["componentInspectorSetting"] = false;
} catch(e:Error) {
};
}
public function _onLoaded():void{
var mainClass:Class;
var main:*;
gotoAndStop("invisible");
if (_redirect){
API.loadOfficialVersion();
return;
};
if (className){
try {
mainClass = (getDefinitionByName(className) as Class);
if (((mainClass) && (parent))){
main = new (mainClass);
parent.addChild(main);
parent.removeChild(this);
};
} catch(error) {
Logger.logError(("Unable to create main class: " + className));
};
};
}
function frame10(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame14(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame18(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame3(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame6(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame7(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame19(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame12(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame13(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame17(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame5(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame9(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame1(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
stop();
if (((root) && ((root is MovieClip)))){
MovieClip(root).stop();
};
x = int(x);
y = int(y);
if (!debugMode){
debugMode = "Simulate Logged-in User";
};
if (!connectorType){
connectorType = "Flash Ad + Preloader";
};
if (!adType){
adType = "Video";
};
if (ad){
ad.adType = adType;
};
switch (connectorType){
case "Flash Ad + Preloader":
gotoAndStop("adPreloader");
break;
case "Flash Ad Only":
gotoAndStop("ad");
break;
case "Invisible":
gotoAndStop("invisible");
break;
};
_apiConnect();
}
function frame8(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame21(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame2(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame15(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame16(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame11(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame4(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
function frame20(){
if ((((__setPropDict[ad] == undefined)) || (!((((int(__setPropDict[ad]) >= 1)) && ((int(__setPropDict[ad]) <= 21))))))){
__setPropDict[ad] = currentFrame;
__setProp_ad_APIConnector_AD_1();
};
}
}
}//package com.newgrounds.components
Section 7
//FlashAd (com.newgrounds.components.FlashAd)
package com.newgrounds.components {
import flash.utils.*;
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
import flash.geom.*;
import adobe.utils.*;
import flash.accessibility.*;
import flash.errors.*;
import flash.external.*;
import flash.filters.*;
import flash.media.*;
import flash.printing.*;
import flash.ui.*;
import flash.xml.*;
public dynamic class FlashAd extends FlashAdBase {
public function FlashAd(){
addFrameScript(0, frame1, 29, frame30);
}
function frame1(){
stop();
}
function frame30(){
if (this["playButton"]){
this["playButton"].addEventListener(MouseEvent.CLICK, onPlayClick);
};
}
public function onPlayClick(_arg1:MouseEvent):void{
removeAd();
if (parent){
parent.removeChild(this);
};
}
}
}//package com.newgrounds.components
Section 8
//FlashAdBase (com.newgrounds.components.FlashAdBase)
package com.newgrounds.components {
import flash.display.*;
import com.newgrounds.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
public class FlashAdBase extends MovieClip {
private var _showBorder:Boolean;// = true
public var showPlayButton:Boolean;
private var _fullScreen:Boolean;
public var adType:String;
public var VIDEO_ADS:String;// = "Video"
public var SIMPLE_ADS:String;// = "Simple"
private var _adFeedLoader:URLLoader;
private var _ad:Loader;
public function FlashAdBase(){
this.adType = this.VIDEO_ADS;
super();
try {
Security.allowDomain("server.cpmstar.com");
Security.allowInsecureDomain("server.cpmstar.com");
} catch(error) {
};
x = int(x);
y = int(y);
stop();
if (this["newgroundsButton"]){
this["newgroundsButton"].addEventListener(MouseEvent.CLICK, this.onNGClick);
};
addEventListener(Event.REMOVED_FROM_STAGE, this.onRemovedFromStage);
addEventListener(Event.ENTER_FRAME, this.init);
}
public function get _adContainer():Sprite{
return (this["adContainer"]);
}
public function get _newgroundsButton():DisplayObject{
return (this["newgroundsButton"]);
}
public function get fullScreen():Boolean{
return (this._fullScreen);
}
public function set fullScreen(_arg1:Boolean):void{
this._fullScreen = _arg1;
if (_arg1){
if (stage){
this.drawFullScreenRect();
} else {
addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
};
} else {
graphics.clear();
};
}
public function get showBorder():Boolean{
return (this._showBorder);
}
public function set showBorder(_arg1:Boolean):void{
this._showBorder = _arg1;
if (this._showBorder){
if (this._ad){
if (this._ad.content){
if (this.showPlayButton){
gotoAndStop("loadedPlay");
} else {
gotoAndStop("loaded");
};
} else {
gotoAndStop("loading");
};
} else {
gotoAndStop("idle");
};
} else {
gotoAndStop("noBorder");
};
}
private function init(_arg1:Event):void{
removeEventListener(Event.ENTER_FRAME, this.init);
if (API.adFeedURL){
this.loadAdFeed();
} else {
API.addEventListener(APIEvent.API_CONNECTED, this.loadAdFeed);
};
}
private function loadAdFeed(_arg1:APIEvent=null):void{
var event = _arg1;
if (!API.adFeedURL){
return;
};
if (this._showBorder){
gotoAndStop("loading");
};
this._adFeedLoader = new URLLoader();
this._adFeedLoader.addEventListener(Event.COMPLETE, this.onAdFeedLoaded);
this._adFeedLoader.addEventListener(IOErrorEvent.IO_ERROR, this.onAdError);
this._adFeedLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onAdError);
var adFeedRequest:URLRequest = new URLRequest(API.adFeedURL);
try {
this._adFeedLoader.load(adFeedRequest);
} catch(e:Error) {
onAdError();
};
}
private function onAdFeedLoaded(_arg1:Event):void{
if (((((this._adFeedLoader) && (this._adFeedLoader.data))) && (!((this._adFeedLoader.data == ""))))){
this.loadAd(this._adFeedLoader.data);
} else {
this.onAdError();
};
}
private function loadAd(_arg1:String):void{
var adURL = _arg1;
if (this._ad){
this.removeAd();
};
Logger.logMessage("Loading flash ad...");
this._ad = new Loader();
this._ad.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.onAdError);
try {
Object(this._ad.contentLoaderInfo).uncaughtErrorEvents.addEventListener("uncaughtError", function (_arg1:Event):void{
_arg1.preventDefault();
});
} catch(error:Error) {
};
try {
if (this.adType != this.VIDEO_ADS){
if (adURL.indexOf("?") >= 0){
adURL = (adURL + "&");
} else {
adURL = (adURL + "?");
};
adURL = (adURL + "blockoverlays=1");
};
this._ad.load(new URLRequest(adURL), new LoaderContext(false, new ApplicationDomain(null)));
if (this._adContainer){
this._adContainer.addChild(this._ad);
};
if (this._showBorder){
if (this.showPlayButton){
gotoAndStop("loadedPlay");
} else {
gotoAndStop("loaded");
};
};
} catch(error:Error) {
onAdError();
};
}
private function drawFullScreenRect():void{
if (stage){
x = ((stage.stageWidth - width) / 2);
y = ((stage.stageHeight - height) / 2);
graphics.beginFill(0);
graphics.drawRect(-(stage.stageWidth), -(stage.stageHeight), (stage.stageWidth * 2), (stage.stageHeight * 2));
graphics.endFill();
};
}
public function removeAd():void{
removeEventListener(Event.REMOVED_FROM_STAGE, this.onRemovedFromStage);
if (this._adFeedLoader){
try {
this._adFeedLoader.close();
} catch(e:Error) {
};
};
if (this._ad){
try {
this._ad.close();
} catch(e:Error) {
};
try {
Object(this._ad).unloadAndStop(true);
} catch(e:Error) {
_ad.unload();
};
if (this._ad.parent){
this._ad.parent.removeChild(this._ad);
};
this._ad = null;
};
Logger.logError("Ad destroyed.");
}
private function onAdError(_arg1:Event=null):void{
Logger.logError("Unable to load ad.");
this.removeAd();
}
private function onRemovedFromStage(_arg1:Event):void{
this.removeAd();
}
private function onAddedToStage(_arg1:Event):void{
removeEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
if (this.fullScreen){
this.drawFullScreenRect();
};
}
private function onNGClick(_arg1:MouseEvent):void{
API.loadNewgrounds();
}
}
}//package com.newgrounds.components
Section 9
//Preloader (com.newgrounds.components.Preloader)
package com.newgrounds.components {
import flash.utils.*;
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
import flash.geom.*;
import adobe.utils.*;
import flash.accessibility.*;
import flash.errors.*;
import flash.external.*;
import flash.filters.*;
import flash.media.*;
import flash.printing.*;
import flash.ui.*;
import flash.xml.*;
public dynamic class Preloader extends MovieClip {
public var className:String;
public var loadingBar:MovieClip;
public var autoPlay:Boolean;
public var playButton:MovieClip;
public function Preloader(){
addFrameScript(0, frame1, 9, frame10);
}
public function enterFrameHandler(_arg1:Event):void{
var _local2:Number;
_local2 = 0;
if (loaderInfo){
_local2 = (loaderInfo.bytesLoaded / loaderInfo.bytesTotal);
};
if (loadingBar){
loadingBar.gotoAndStop((int((_local2 * (loadingBar.totalFrames - 1))) + 1));
};
if (_local2 >= 1){
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
gotoAndStop("loaded");
};
}
function frame10(){
if (playButton){
playButton.addEventListener(MouseEvent.CLICK, _onPlayClick);
playButton.stop();
playButton.buttonMode = true;
};
if (autoPlay){
_onPlayClick(null);
};
}
function frame1(){
stop();
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
public function _onPlayClick(_arg1:MouseEvent):void{
var _local2:MovieClip;
var _local3:MovieClip;
_local2 = (root as MovieClip);
_local3 = (parent as MovieClip);
if (_local2){
_local2.play();
_local2.nextFrame();
};
if (((_local3) && (_local3._onLoaded))){
_local3._onLoaded();
};
}
}
}//package com.newgrounds.components
Section 10
//MD5 (com.newgrounds.crypto.MD5)
package com.newgrounds.crypto {
import flash.utils.*;
public class MD5 {
public static var digest:ByteArray;
private static var hexChars:String = "0123456789abcdef";
public static function hash(_arg1:String):String{
var _local2:ByteArray = new ByteArray();
_local2.writeUTFBytes(_arg1);
return (hashBinary(_local2));
}
public static function hashBytes(_arg1:ByteArray):String{
return (hashBinary(_arg1));
}
public static function hashBinary(_arg1:ByteArray):String{
var _local6:int;
var _local7:int;
var _local8:int;
var _local9:int;
var _local2 = 1732584193;
var _local3 = -271733879;
var _local4 = -1732584194;
var _local5 = 271733878;
var _local10:Array = createBlocks(_arg1);
var _local11:int = _local10.length;
var _local12:int;
while (_local12 < _local11) {
_local6 = _local2;
_local7 = _local3;
_local8 = _local4;
_local9 = _local5;
_local2 = ff(_local2, _local3, _local4, _local5, _local10[int((_local12 + 0))], 7, -680876936);
_local5 = ff(_local5, _local2, _local3, _local4, _local10[int((_local12 + 1))], 12, -389564586);
_local4 = ff(_local4, _local5, _local2, _local3, _local10[int((_local12 + 2))], 17, 606105819);
_local3 = ff(_local3, _local4, _local5, _local2, _local10[int((_local12 + 3))], 22, -1044525330);
_local2 = ff(_local2, _local3, _local4, _local5, _local10[int((_local12 + 4))], 7, -176418897);
_local5 = ff(_local5, _local2, _local3, _local4, _local10[int((_local12 + 5))], 12, 1200080426);
_local4 = ff(_local4, _local5, _local2, _local3, _local10[int((_local12 + 6))], 17, -1473231341);
_local3 = ff(_local3, _local4, _local5, _local2, _local10[int((_local12 + 7))], 22, -45705983);
_local2 = ff(_local2, _local3, _local4, _local5, _local10[int((_local12 + 8))], 7, 1770035416);
_local5 = ff(_local5, _local2, _local3, _local4, _local10[int((_local12 + 9))], 12, -1958414417);
_local4 = ff(_local4, _local5, _local2, _local3, _local10[int((_local12 + 10))], 17, -42063);
_local3 = ff(_local3, _local4, _local5, _local2, _local10[int((_local12 + 11))], 22, -1990404162);
_local2 = ff(_local2, _local3, _local4, _local5, _local10[int((_local12 + 12))], 7, 1804603682);
_local5 = ff(_local5, _local2, _local3, _local4, _local10[int((_local12 + 13))], 12, -40341101);
_local4 = ff(_local4, _local5, _local2, _local3, _local10[int((_local12 + 14))], 17, -1502002290);
_local3 = ff(_local3, _local4, _local5, _local2, _local10[int((_local12 + 15))], 22, 1236535329);
_local2 = gg(_local2, _local3, _local4, _local5, _local10[int((_local12 + 1))], 5, -165796510);
_local5 = gg(_local5, _local2, _local3, _local4, _local10[int((_local12 + 6))], 9, -1069501632);
_local4 = gg(_local4, _local5, _local2, _local3, _local10[int((_local12 + 11))], 14, 643717713);
_local3 = gg(_local3, _local4, _local5, _local2, _local10[int((_local12 + 0))], 20, -373897302);
_local2 = gg(_local2, _local3, _local4, _local5, _local10[int((_local12 + 5))], 5, -701558691);
_local5 = gg(_local5, _local2, _local3, _local4, _local10[int((_local12 + 10))], 9, 38016083);
_local4 = gg(_local4, _local5, _local2, _local3, _local10[int((_local12 + 15))], 14, -660478335);
_local3 = gg(_local3, _local4, _local5, _local2, _local10[int((_local12 + 4))], 20, -405537848);
_local2 = gg(_local2, _local3, _local4, _local5, _local10[int((_local12 + 9))], 5, 568446438);
_local5 = gg(_local5, _local2, _local3, _local4, _local10[int((_local12 + 14))], 9, -1019803690);
_local4 = gg(_local4, _local5, _local2, _local3, _local10[int((_local12 + 3))], 14, -187363961);
_local3 = gg(_local3, _local4, _local5, _local2, _local10[int((_local12 + 8))], 20, 1163531501);
_local2 = gg(_local2, _local3, _local4, _local5, _local10[int((_local12 + 13))], 5, -1444681467);
_local5 = gg(_local5, _local2, _local3, _local4, _local10[int((_local12 + 2))], 9, -51403784);
_local4 = gg(_local4, _local5, _local2, _local3, _local10[int((_local12 + 7))], 14, 1735328473);
_local3 = gg(_local3, _local4, _local5, _local2, _local10[int((_local12 + 12))], 20, -1926607734);
_local2 = hh(_local2, _local3, _local4, _local5, _local10[int((_local12 + 5))], 4, -378558);
_local5 = hh(_local5, _local2, _local3, _local4, _local10[int((_local12 + 8))], 11, -2022574463);
_local4 = hh(_local4, _local5, _local2, _local3, _local10[int((_local12 + 11))], 16, 1839030562);
_local3 = hh(_local3, _local4, _local5, _local2, _local10[int((_local12 + 14))], 23, -35309556);
_local2 = hh(_local2, _local3, _local4, _local5, _local10[int((_local12 + 1))], 4, -1530992060);
_local5 = hh(_local5, _local2, _local3, _local4, _local10[int((_local12 + 4))], 11, 1272893353);
_local4 = hh(_local4, _local5, _local2, _local3, _local10[int((_local12 + 7))], 16, -155497632);
_local3 = hh(_local3, _local4, _local5, _local2, _local10[int((_local12 + 10))], 23, -1094730640);
_local2 = hh(_local2, _local3, _local4, _local5, _local10[int((_local12 + 13))], 4, 681279174);
_local5 = hh(_local5, _local2, _local3, _local4, _local10[int((_local12 + 0))], 11, -358537222);
_local4 = hh(_local4, _local5, _local2, _local3, _local10[int((_local12 + 3))], 16, -722521979);
_local3 = hh(_local3, _local4, _local5, _local2, _local10[int((_local12 + 6))], 23, 76029189);
_local2 = hh(_local2, _local3, _local4, _local5, _local10[int((_local12 + 9))], 4, -640364487);
_local5 = hh(_local5, _local2, _local3, _local4, _local10[int((_local12 + 12))], 11, -421815835);
_local4 = hh(_local4, _local5, _local2, _local3, _local10[int((_local12 + 15))], 16, 530742520);
_local3 = hh(_local3, _local4, _local5, _local2, _local10[int((_local12 + 2))], 23, -995338651);
_local2 = ii(_local2, _local3, _local4, _local5, _local10[int((_local12 + 0))], 6, -198630844);
_local5 = ii(_local5, _local2, _local3, _local4, _local10[int((_local12 + 7))], 10, 1126891415);
_local4 = ii(_local4, _local5, _local2, _local3, _local10[int((_local12 + 14))], 15, -1416354905);
_local3 = ii(_local3, _local4, _local5, _local2, _local10[int((_local12 + 5))], 21, -57434055);
_local2 = ii(_local2, _local3, _local4, _local5, _local10[int((_local12 + 12))], 6, 1700485571);
_local5 = ii(_local5, _local2, _local3, _local4, _local10[int((_local12 + 3))], 10, -1894986606);
_local4 = ii(_local4, _local5, _local2, _local3, _local10[int((_local12 + 10))], 15, -1051523);
_local3 = ii(_local3, _local4, _local5, _local2, _local10[int((_local12 + 1))], 21, -2054922799);
_local2 = ii(_local2, _local3, _local4, _local5, _local10[int((_local12 + 8))], 6, 1873313359);
_local5 = ii(_local5, _local2, _local3, _local4, _local10[int((_local12 + 15))], 10, -30611744);
_local4 = ii(_local4, _local5, _local2, _local3, _local10[int((_local12 + 6))], 15, -1560198380);
_local3 = ii(_local3, _local4, _local5, _local2, _local10[int((_local12 + 13))], 21, 1309151649);
_local2 = ii(_local2, _local3, _local4, _local5, _local10[int((_local12 + 4))], 6, -145523070);
_local5 = ii(_local5, _local2, _local3, _local4, _local10[int((_local12 + 11))], 10, -1120210379);
_local4 = ii(_local4, _local5, _local2, _local3, _local10[int((_local12 + 2))], 15, 718787259);
_local3 = ii(_local3, _local4, _local5, _local2, _local10[int((_local12 + 9))], 21, -343485551);
_local2 = (_local2 + _local6);
_local3 = (_local3 + _local7);
_local4 = (_local4 + _local8);
_local5 = (_local5 + _local9);
_local12 = (_local12 + 16);
};
digest = new ByteArray();
digest.writeInt(_local2);
digest.writeInt(_local3);
digest.writeInt(_local4);
digest.writeInt(_local5);
digest.position = 0;
return ((((toHex(_local2) + toHex(_local3)) + toHex(_local4)) + toHex(_local5)));
}
private static function f(_arg1:int, _arg2:int, _arg3:int):int{
return (((_arg1 & _arg2) | (~(_arg1) & _arg3)));
}
private static function g(_arg1:int, _arg2:int, _arg3:int):int{
return (((_arg1 & _arg3) | (_arg2 & ~(_arg3))));
}
private static function h(_arg1:int, _arg2:int, _arg3:int):int{
return (((_arg1 ^ _arg2) ^ _arg3));
}
private static function i(_arg1:int, _arg2:int, _arg3:int):int{
return ((_arg2 ^ (_arg1 | ~(_arg3))));
}
private static function transform(_arg1:Function, _arg2:int, _arg3:int, _arg4:int, _arg5:int, _arg6:int, _arg7:int, _arg8:int):int{
var _local9:int = (((_arg2 + int(_arg1(_arg3, _arg4, _arg5))) + _arg6) + _arg8);
return ((rol(_local9, _arg7) + _arg3));
}
private static function ff(_arg1:int, _arg2:int, _arg3:int, _arg4:int, _arg5:int, _arg6:int, _arg7:int):int{
return (transform(f, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7));
}
private static function gg(_arg1:int, _arg2:int, _arg3:int, _arg4:int, _arg5:int, _arg6:int, _arg7:int):int{
return (transform(g, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7));
}
private static function hh(_arg1:int, _arg2:int, _arg3:int, _arg4:int, _arg5:int, _arg6:int, _arg7:int):int{
return (transform(h, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7));
}
private static function ii(_arg1:int, _arg2:int, _arg3:int, _arg4:int, _arg5:int, _arg6:int, _arg7:int):int{
return (transform(i, _arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7));
}
private static function createBlocks(_arg1:ByteArray):Array{
var _local2:Array = new Array();
var _local3:int = (_arg1.length * 8);
var _local4 = 0xFF;
var _local5:int;
while (_local5 < _local3) {
_local2[int((_local5 >> 5))] = (_local2[int((_local5 >> 5))] | ((_arg1[(_local5 / 8)] & _local4) << (_local5 % 32)));
_local5 = (_local5 + 8);
};
_local2[int((_local3 >> 5))] = (_local2[int((_local3 >> 5))] | (128 << (_local3 % 32)));
_local2[int(((((_local3 + 64) >>> 9) << 4) + 14))] = _local3;
return (_local2);
}
public static function rol(_arg1:int, _arg2:int):int{
return (((_arg1 << _arg2) | (_arg1 >>> (32 - _arg2))));
}
public static function ror(_arg1:int, _arg2:int):uint{
var _local3:int = (32 - _arg2);
return (((_arg1 << _local3) | (_arg1 >>> (32 - _local3))));
}
public static function toHex(_arg1:int, _arg2:Boolean=false):String{
var _local4:int;
var _local5:int;
var _local3 = "";
if (_arg2){
_local4 = 0;
while (_local4 < 4) {
_local3 = (_local3 + (hexChars.charAt(((_arg1 >> (((3 - _local4) * 8) + 4)) & 15)) + hexChars.charAt(((_arg1 >> ((3 - _local4) * 8)) & 15))));
_local4++;
};
} else {
_local5 = 0;
while (_local5 < 4) {
_local3 = (_local3 + (hexChars.charAt(((_arg1 >> ((_local5 * 8) + 4)) & 15)) + hexChars.charAt(((_arg1 >> (_local5 * 8)) & 15))));
_local5++;
};
};
return (_local3);
}
}
}//package com.newgrounds.crypto
Section 11
//RC4 (com.newgrounds.crypto.RC4)
package com.newgrounds.crypto {
public class RC4 {
private static var sbox:Array = new Array(0xFF);
private static var mykey:Array = new Array(0xFF);
public static function encrypt(_arg1:String, _arg2:String):String{
var _local3:Array = strToChars(_arg1);
var _local4:Array = strToChars(_arg2);
var _local5:Array = calculate(_local3, _local4);
return (charsToHex(_local5));
}
public static function encryptbin(_arg1:String, _arg2:String):Array{
var _local3:Array = strToChars(_arg1);
var _local4:Array = strToChars(_arg2);
var _local5:Array = calculate(_local3, _local4);
return (_local5);
}
public static function decrypt(_arg1:String, _arg2:String):String{
var _local3:Array = hexToChars(_arg1);
var _local4:Array = strToChars(_arg2);
var _local5:Array = calculate(_local3, _local4);
return (charsToStr(_local5));
}
private static function initialize(_arg1:Array):void{
var _local3:uint;
var _local2:uint;
var _local4:uint = _arg1.length;
var _local5:uint;
while (_local5 <= 0xFF) {
mykey[_local5] = _arg1[(_local5 % _local4)];
sbox[_local5] = _local5;
_local5++;
};
_local5 = 0;
while (_local5 <= 0xFF) {
_local2 = (((_local2 + sbox[_local5]) + mykey[_local5]) % 0x0100);
_local3 = sbox[_local5];
sbox[_local5] = sbox[_local2];
sbox[_local2] = _local3;
_local5++;
};
}
private static function calculate(_arg1:Array, _arg2:Array):Array{
var _local6:uint;
var _local7:uint;
var _local8:uint;
var _local10:uint;
initialize(_arg2);
var _local3:uint;
var _local4:uint;
var _local5:Array = new Array();
var _local9:uint;
while (_local9 < _arg1.length) {
_local3 = ((_local3 + 1) % 0x0100);
_local4 = ((_local4 + sbox[_local3]) % 0x0100);
_local7 = sbox[_local3];
sbox[_local3] = sbox[_local4];
sbox[_local4] = _local7;
_local10 = ((sbox[_local3] + sbox[_local4]) % 0x0100);
_local6 = sbox[_local10];
_local8 = (_arg1[_local9] ^ _local6);
_local5.push(_local8);
_local9++;
};
return (_local5);
}
private static function charsToHex(_arg1:Array):String{
var _local2:String = new String("");
var _local3:Array = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f");
var _local4:uint;
while (_local4 < _arg1.length) {
_local2 = (_local2 + (_local3[(_arg1[_local4] >> 4)] + _local3[(_arg1[_local4] & 15)]));
_local4++;
};
return (_local2);
}
private static function hexToChars(_arg1:String):Array{
var _local2:Array = new Array();
var _local3:uint = ((_arg1.substr(0, 2))=="0x") ? 2 : 0;
while (_local3 < _arg1.length) {
_local2.push(parseInt(_arg1.substr(_local3, 2), 16));
_local3 = (_local3 + 2);
};
return (_local2);
}
private static function charsToStr(_arg1:Array):String{
var _local2:String = new String("");
var _local3:uint;
while (_local3 < _arg1.length) {
_local2 = (_local2 + String.fromCharCode(_arg1[_local3]));
_local3++;
};
return (_local2);
}
private static function strToChars(_arg1:String):Array{
var _local2:Array = new Array();
var _local3:uint;
while (_local3 < _arg1.length) {
_local2.push(_arg1.charCodeAt(_local3));
_local3++;
};
return (_local2);
}
}
}//package com.newgrounds.crypto
Section 12
//decodeJson (com.newgrounds.encoders.json.decodeJson)
package com.newgrounds.encoders.json {
public const decodeJson:Function = initDecodeJson();
}//package com.newgrounds.encoders.json
import flash.utils.*;
private const initDecodeJson:Function = function ():Function{
var position:uint;
var byteInput:ByteArray;
var char:uint;
var charConvert:ByteArray;
var isNumberChar:ByteArray;
var stringHelper:ByteArray;
var isWhitespace:ByteArray;
var parseNumber:Function;
var parseWhitespace:Function;
var parse:Object;
charConvert = new ByteArray();
(charConvert.length = 0x0100);
(charConvert[34] = 34);
(charConvert[92] = 92);
(charConvert[47] = 47);
(charConvert[98] = 8);
(charConvert[102] = 12);
(charConvert[110] = 10);
(charConvert[114] = 13);
(charConvert[116] = 9);
isNumberChar = new ByteArray();
(isNumberChar.length = 0x0100);
(isNumberChar[43] = 1);
(isNumberChar[45] = 1);
(isNumberChar[46] = 1);
(isNumberChar[48] = 1);
(isNumberChar[49] = 1);
(isNumberChar[50] = 1);
(isNumberChar[51] = 1);
(isNumberChar[52] = 1);
(isNumberChar[53] = 1);
(isNumberChar[54] = 1);
(isNumberChar[55] = 1);
(isNumberChar[56] = 1);
(isNumberChar[57] = 1);
(isNumberChar[69] = 1);
(isNumberChar[101] = 1);
stringHelper = new ByteArray();
(stringHelper.length = 0x0100);
var i:int;
while (i < 0x0100) {
i = (i + 1);
var _local2 = i;
(stringHelper[_local2] = 1);
};
(stringHelper[34] = 0);
(stringHelper[92] = 0);
isWhitespace = new ByteArray();
(isWhitespace.length = 0x0100);
(isWhitespace[9] = 1);
(isWhitespace[10] = 1);
(isWhitespace[13] = 1);
(isWhitespace[32] = 1);
parseNumber = function ():Number{
if (position === 1){
(byteInput.position = 0);
return (parseFloat(byteInput.readUTFBytes(byteInput.length)));
};
(byteInput.position = (position - 1));
do {
} while (isNumberChar[byteInput[position++]]);
return (Number(byteInput.readUTFBytes(((position-- - byteInput.position) - 1))));
};
parseWhitespace = function ():Object{
while (isWhitespace[byteInput[position]]) {
position++;
};
return (parse[byteInput[position++]]());
};
var parseStringEscaped:Function = function (_arg1:String):String{
do {
if ((char = byteInput[position++]) === 117){
(byteInput.position = position);
(char = parseInt(byteInput.readUTFBytes(4), 16));
(position = (position + 4));
} else {
if (!(char = charConvert[char])){
throw (new Error(("Unknown escaped character encountered at position " + (position - 1))));
};
(byteInput.position = position);
};
_arg1 = (_arg1 + String.fromCharCode(char));
_arg1;
do {
} while (stringHelper[byteInput[position++]]);
if ((position - 1) > byteInput.position){
_arg1 = (_arg1 + byteInput.readUTFBytes(((position - 1) - byteInput.position)));
_arg1;
};
} while (byteInput[(position - 1)] === 92);
return (_arg1);
};
parse = {34:function ():String{
if (stringHelper[byteInput[position++]]){
(byteInput.position = (position - 1));
do {
} while (stringHelper[byteInput[position++]]);
if (byteInput[(position - 1)] === 92){
return (parseStringEscaped(byteInput.readUTFBytes(((position - 1) - byteInput.position))));
};
return (byteInput.readUTFBytes(((position - 1) - byteInput.position)));
//unresolved jump
};
if (byteInput[(position - 1)] === 92){
return (parseStringEscaped(""));
};
return ("");
}, 123:function ():Object{
var _local2:*;
while (isWhitespace[byteInput[position]]) {
position++;
};
if (byteInput[position] === 125){
position++;
return ({});
};
var _local1:* = {};
do {
do {
_local2 = parse[byteInput[position++]]();
_local2;
if (byteInput[position] !== 58){
while (isWhitespace[byteInput[position]]) {
position++;
};
if (byteInput[position++] !== 58){
throw (new Error(("Expected : at " + (position - 1))));
};
} else {
position++;
};
var _temp1 = _local2;
(_local1[_temp1] = parse[byteInput[position++]]());
} while (byteInput[position++] === 44);
if (byteInput[(position - 1)] === 125){
return (_local1);
};
while (isWhitespace[byteInput[position]]) {
position++;
};
} while (byteInput[position++] === 44);
if (byteInput[(position - 1)] !== 125){
throw (new Error(("Expected , or } at " + (position - 1))));
};
return (_local1);
}, 91:function ():Object{
while (isWhitespace[byteInput[position]]) {
position++;
};
if (byteInput[position] === 93){
position++;
return ([]);
};
var _local1:* = [];
do {
do {
(_local1[_local1.length] = parse[byteInput[position++]]());
} while (byteInput[position++] === 44);
if (byteInput[(position - 1)] === 93){
return (_local1);
};
position--;
while (isWhitespace[byteInput[position]]) {
position++;
};
} while (byteInput[position++] === 44);
if (byteInput[(position - 1)] !== 93){
throw (new Error(("Expected , or ] at " + (position - 1))));
};
return (_local1);
}, 116:function ():Boolean{
if ((((((byteInput[position] === 114)) && ((byteInput[(position + 1)] === 117)))) && ((byteInput[(position + 2)] === 101)))){
(position = (position + 3));
return (true);
};
throw (new Error(("Expected \"true\" at position " + position)));
}, 102:function ():Boolean{
if ((((((((byteInput[position] === 97)) && ((byteInput[(position + 1)] === 108)))) && ((byteInput[(position + 2)] === 115)))) && ((byteInput[(position + 3)] === 101)))){
(position = (position + 4));
return (false);
};
throw (new Error(("Expected \"false\" at position " + (position - 1))));
}, 110:function ():Object{
if ((((((byteInput[position] === 117)) && ((byteInput[(position + 1)] === 108)))) && ((byteInput[(position + 2)] === 108)))){
(position = (position + 3));
return (null);
};
throw (new Error(("Expected \"null\" at position " + position)));
}, 110:function ():void{
throw (new Error(("Unexpected end of array at " + position)));
}, 125:function ():void{
throw (new Error(("Unexpected end of object at " + position)));
}, 44:function ():void{
throw (new Error(("Unexpected comma at " + position)));
}, 45:parseNumber, 48:parseNumber, 49:parseNumber, 50:parseNumber, 51:parseNumber, 52:parseNumber, 53:parseNumber, 54:parseNumber, 55:parseNumber, 56:parseNumber, 57:parseNumber, 13:parseWhitespace, 10:parseWhitespace, 9:parseWhitespace, 32:parseWhitespace};
return (function (_arg1):Object{
var input = _arg1;
if ((input is String)){
(byteInput = new ByteArray());
byteInput.writeUTFBytes((input as String));
} else {
if ((input is ByteArray)){
(byteInput = (input as ByteArray));
} else {
throw (new Error((("Unexpected input <" + input) + ">")));
};
};
(position = 0);
try {
return (parse[byteInput[position++]]());
} catch(e:TypeError) {
if ((position - 1) < byteInput.length){
(e.message = ((((((((("Unexpected character " + String.fromCharCode(byteInput[(position - 1)])) + " (0x") + byteInput[(position - 1)].toString(16)) + ")") + " at position ") + (position - 1)) + " (") + e.message) + ")"));
};
throw (e);
};
return (null);
});
};
Section 13
//encodeJson (com.newgrounds.encoders.json.encodeJson)
package com.newgrounds.encoders.json {
public const encodeJson:Function = initDecodeJson();
}//package com.newgrounds.encoders.json
import flash.utils.*;
private const initDecodeJson:Function = function ():Function{
var result:IDataOutput;
var i:int;
var j:int;
var strLen:int;
var str:String;
var char:int;
var tempBytes:ByteArray;
var blockNonFiniteNumbers:Boolean;
var charConvert:Array;
var parseString:Function;
var parse:Object;
tempBytes = new ByteArray();
charConvert = new Array(0x0100);
j = 0;
while (j < 10) {
(charConvert[j] = ((j + 48) | 808464384));
j = (j + 1);
};
while (j < 16) {
(charConvert[j] = ((j + 55) | 808464384));
j = (j + 1);
};
while (j < 26) {
(charConvert[j] = ((j + 32) | 808464640));
j = (j + 1);
};
while (j < 32) {
(charConvert[j] = ((j + 39) | 808464640));
j = (j + 1);
};
while (j < 0x0100) {
(charConvert[j] = j);
j = (j + 1);
};
(charConvert[10] = 23662);
(charConvert[13] = 23666);
(charConvert[9] = 23668);
(charConvert[8] = 23650);
(charConvert[12] = 23654);
(charConvert[8] = 23650);
(charConvert[34] = 23586);
(charConvert[92] = 0x5C5C);
(charConvert[127] = 808466246);
var parseArray:Function = function (_arg1:Array):void{
result.writeByte(91);
var _local2:int;
var _local3:int = (_arg1.length - 1);
if (_local3 >= 0){
while (_local2 < _local3) {
parse[typeof(_arg1[_local2])](_arg1[_local2]);
result.writeByte(44);
var _temp1 = _local2;
_local2 = (_local2 + 1);
_temp1;
};
parse[typeof(_arg1[_local2])](_arg1[_local2]);
};
result.writeByte(93);
};
parseString = function (_arg1:String):void{
result.writeByte(34);
(tempBytes.position = 0);
(tempBytes.length = 0);
tempBytes.writeUTFBytes(_arg1);
(i = 0);
(j = 0);
(strLen = tempBytes.length);
while (j < strLen) {
(char = charConvert[tempBytes[j++]]);
if (char > 0x0100){
if ((j - 1) > i){
result.writeBytes(tempBytes, i, ((j - 1) - i));
};
if (char > 65536){
result.writeShort(23669);
result.writeUnsignedInt(char);
} else {
result.writeShort(char);
};
(i = j);
};
};
if (strLen > i){
result.writeBytes(tempBytes, i, (strLen - i));
};
result.writeByte(34);
};
parse = {object:function (_arg1:Object):void{
var _local2:*;
if (_arg1){
if ((_arg1 is Array)){
parseArray(_arg1);
} else {
result.writeByte(123);
_local2 = true;
for (str in _arg1) {
if (_local2){
_local2 = false;
_local2;
} else {
result.writeByte(44);
};
parseString(str);
result.writeByte(58);
parse[typeof(_arg1[str])](_arg1[str]);
};
result.writeByte(125);
};
} else {
result.writeUnsignedInt(1853189228);
};
}, string:parseString, number:function (_arg1:Number):void{
if (((blockNonFiniteNumbers) && (!(isFinite(_arg1))))){
throw (new Error((("Number " + _arg1) + " is not encodable")));
};
result.writeUTFBytes(String(_arg1));
}, boolean:function (_arg1:Boolean):void{
if (_arg1){
result.writeUnsignedInt(1953658213);
} else {
result.writeByte(102);
result.writeUnsignedInt(1634497381);
};
}, xml:function (_arg1:Object):void{
if ((((!(_arg1.toXMLString) is Function)) || ((_temp2 == null)))){
throw (new Error("unserializable XML object encountered"));
};
parseString(_arg1);
}, undefined:function (_arg1:Boolean):void{
result.writeUnsignedInt(1853189228);
}};
return (function (_arg1:Object, _arg2:IDataOutput=null, _arg3:Boolean=false):String{
var byteOutput:*;
var input = _arg1;
var writeTo = _arg2;
var strictNumberSupport = _arg3;
(blockNonFiniteNumbers = strictNumberSupport);
try {
if (writeTo){
(result = writeTo);
(result.endian = "bigEndian");
parse[typeof(input)](input);
(byteOutput.position = 0);
return (byteOutput.readUTFBytes(byteOutput.length));
} else {
switch (typeof(input)){
case "xml":
if ((((!(input.toXMLString) is Function)) || ((_local5 == null)))){
throw (new Error("unserializable XML object encountered"));
};
case "object":
case "string":
var _local5 = new ByteArray();
byteOutput = _local5;
(result = _local5);
(result.endian = "bigEndian");
parse[typeof(input)](input);
(byteOutput.position = 0);
return (byteOutput.readUTFBytes(byteOutput.length));
case "number":
if (((blockNonFiniteNumbers) && (!(isFinite((input as Number)))))){
throw (new Error((("Number " + input) + " is not encodable")));
};
return (String(input));
case "boolean":
return ((input) ? "true" : "false");
case "undefined":
return ("null");
default:
throw (new Error((("Unexpected type \"" + typeof(input)) + "\" encountered")));
};
};
} catch(e:TypeError) {
throw (new Error("Unexpected type encountered"));
};
return (null);
});
};
Section 14
//JSON (com.newgrounds.encoders.json.JSON)
package com.newgrounds.encoders.json {
public class JSON {
public static function encode(_arg1:Object):String{
return (encodeJson(_arg1));
}
public static function decode(_arg1:String):Object{
return (decodeJson(_arg1));
}
}
}//package com.newgrounds.encoders.json
Section 15
//BaseN (com.newgrounds.encoders.BaseN)
package com.newgrounds.encoders {
import flash.utils.*;
public class BaseN {
private var _hash:String;
private var _base:uint;
private var _reverseHash:Dictionary;
private static const DEFAULT_HASH:String = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`~@#$%^&*()+|;/";
public function BaseN(_arg1:String){
if (_arg1){
this._hash = _arg1;
} else {
this._hash = DEFAULT_HASH;
};
this._base = this._hash.length;
this._reverseHash = new Dictionary();
var _local2:uint;
while (_local2 < this._hash.length) {
this._reverseHash[this._hash.charAt(_local2)] = _local2;
_local2++;
};
}
public function encodeUint(_arg1:uint, _arg2:uint=1):String{
var _local3 = "";
var _local4:uint = _arg1;
while (_local4 != 0) {
_local3 = (this._hash.charAt((_local4 % this._base)) + _local3);
_local4 = (_local4 / this._base);
};
while (_local3.length < _arg2) {
_local3 = (this._hash.charAt(0) + _local3);
};
return (_local3);
}
public function decodeUint(_arg1:String):uint{
var _local2:uint;
var _local3:uint;
while (_local3 < _arg1.length) {
_local2 = (_local2 * this._base);
_local2 = (_local2 + this._reverseHash[_arg1.charAt(_local3)]);
_local3++;
};
return (_local2);
}
}
}//package com.newgrounds.encoders
Section 16
//PNGEncoder (com.newgrounds.encoders.PNGEncoder)
package com.newgrounds.encoders {
import flash.utils.*;
import flash.display.*;
import flash.geom.*;
public class PNGEncoder {
private static var crcTable:Array;
private static var crcTableComputed:Boolean = false;
public static function encode(_arg1:BitmapData):ByteArray{
var _local6:uint;
var _local7:int;
var _local2:ByteArray = new ByteArray();
_local2.writeUnsignedInt(2303741511);
_local2.writeUnsignedInt(218765834);
var _local3:ByteArray = new ByteArray();
_local3.writeInt(_arg1.width);
_local3.writeInt(_arg1.height);
_local3.writeUnsignedInt(134610944);
_local3.writeByte(0);
writeChunk(_local2, 1229472850, _local3);
var _local4:ByteArray = new ByteArray();
var _local5:int;
while (_local5 < _arg1.height) {
_local4.writeByte(0);
if (!_arg1.transparent){
_local7 = 0;
while (_local7 < _arg1.width) {
_local6 = _arg1.getPixel(_local7, _local5);
_local4.writeUnsignedInt(uint((((_local6 & 0xFFFFFF) << 8) | 0xFF)));
_local7++;
};
} else {
_local7 = 0;
while (_local7 < _arg1.width) {
_local6 = _arg1.getPixel32(_local7, _local5);
_local4.writeUnsignedInt(uint((((_local6 & 0xFFFFFF) << 8) | (_local6 >>> 24))));
_local7++;
};
};
_local5++;
};
_local4.compress();
writeChunk(_local2, 1229209940, _local4);
writeChunk(_local2, 1229278788, null);
return (_local2);
}
private static function writeChunk(_arg1:ByteArray, _arg2:uint, _arg3:ByteArray):void{
var _local8:uint;
var _local9:uint;
var _local10:uint;
if (!crcTableComputed){
crcTableComputed = true;
crcTable = [];
_local9 = 0;
while (_local9 < 0x0100) {
_local8 = _local9;
_local10 = 0;
while (_local10 < 8) {
if ((_local8 & 1)){
_local8 = uint((uint(3988292384) ^ uint((_local8 >>> 1))));
} else {
_local8 = uint((_local8 >>> 1));
};
_local10++;
};
crcTable[_local9] = _local8;
_local9++;
};
};
var _local4:uint;
if (_arg3 != null){
_local4 = _arg3.length;
};
_arg1.writeUnsignedInt(_local4);
var _local5:uint = _arg1.position;
_arg1.writeUnsignedInt(_arg2);
if (_arg3 != null){
_arg1.writeBytes(_arg3);
};
var _local6:uint = _arg1.position;
_arg1.position = _local5;
_local8 = 4294967295;
var _local7:int;
while (_local7 < (_local6 - _local5)) {
_local8 = uint((crcTable[((_local8 ^ _arg1.readUnsignedByte()) & uint(0xFF))] ^ uint((_local8 >>> 8))));
_local7++;
};
_local8 = uint((_local8 ^ uint(4294967295)));
_arg1.position = _local6;
_arg1.writeUnsignedInt(_local8);
}
}
}//package com.newgrounds.encoders
Section 17
//API (com.newgrounds.API)
package com.newgrounds {
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.net.*;
import com.newgrounds.encoders.json.*;
import com.newgrounds.crypto.*;
import flash.system.*;
public class API {
public static const RELEASE_MODE:String = "releaseMode";
public static const DEBUG_MODE_LOGGED_IN:String = "debugModeLoggedIn";
public static const DEBUG_MODE_LOGGED_OUT:String = "debugModeLoggedOut";
public static const DEBUG_MODE_NEW_VERSION:String = "debugModeNewVersion";
public static const DEBUG_MODE_HOST_BLOCKED:String = "debugModeHostBlocked";
private static const TEST_AD_FEED_URL:String = "http://www.ngads.com/adtest.php";
public static const VERSION:String = "3.0.9 AS3";
private static var _bridge:Bridge;
private static var _dispatcher:APIEventDispatcher = new APIEventDispatcher();
private static var _movieName:String;
private static var _movieVersion:String;
private static var _root:DisplayObject;
private static var _connection:APIConnection = new APIConnection();
private static var _debugMode:String = "debugModeLoggedIn";
private static var _newVersion:Boolean;
private static var _adsApproved:Boolean = false;
private static var _adFeedURL:String;
private static var _medals:Object = new Object();
private static var _medalsArray:Array = [];
private static var _scoreBoards:Object = new Object();
private static var _scoreBoardsArray:Array = [];
private static var _saveGroups:Object = new Object();
private static var _saveGroupsArray:Array = [];
private static var _imageFilePath:String;
private static var _saveFilePath:String;
private static var _sharedObjects:Object = new Object();
private static var _requestedSaveFileId:uint;
private static var _requestedSaveGroupId:uint;
public static function get connected():Boolean{
return (_connection.connected);
}
public static function get isNetworkHost():Boolean{
return (_connection.isNetworkHost);
}
public static function get apiId():String{
_connection.assertInitialized();
return (_connection.apiId);
}
public static function get debugMode():String{
return (_debugMode);
}
public static function set debugMode(_arg1:String):void{
_debugMode = _arg1;
}
public static function get publisherId():uint{
_connection.assertInitialized();
return (_connection.publisherId);
}
public static function get sessionId():String{
_connection.assertInitialized();
return (_connection.sessionId);
}
public static function get hostDomain():String{
_connection.assertInitialized();
return (_connection.hostDomain);
}
public static function get hostURL():String{
_connection.assertInitialized();
return (_connection.hostURL);
}
public static function get isNewgrounds():Boolean{
return ((_connection.publisherId == 1));
}
public static function get hasUserSession():Boolean{
_connection.assertInitialized();
return (_connection.hasUserSession);
}
public static function get username():String{
_connection.assertInitialized();
return (_connection.username);
}
public static function get userId():uint{
_connection.assertInitialized();
return (_connection.userId);
}
private static function assertConnected(_arg1:String=null):Boolean{
if (_connection.assertConnected()){
return (true);
};
if (_arg1){
dispatchEvent(_arg1, null, APIEvent.ERROR_NOT_CONNECTED);
};
return (false);
}
public static function get adsApproved():Boolean{
return (_adsApproved);
}
public static function get adFeedURL():String{
return (_adFeedURL);
}
public static function get medals():Array{
return (_medalsArray);
}
public static function get scoreBoards():Array{
return (_scoreBoardsArray);
}
public static function get saveGroups():Array{
return (_saveGroupsArray);
}
public static function connect(_arg1:DisplayObject, _arg2:String, _arg3:String=null, _arg4:String=""):void{
var _local5:uint;
APIEventDispatcher.globalDispatcher = _dispatcher;
Security.loadPolicyFile("http://apifiles.ngfiles.com/crossdomain.xml");
if (_connection.initialized){
Logger.logError("Connection already in progress. Please call API.disconnect() before attempting another connection.");
dispatchEvent(APIEvent.API_CONNECTED, false, APIEvent.ERROR_NOT_CONNECTED);
return;
};
_arg2 = trimWhitespace(_arg2);
if (_arg3){
_arg3 = trimWhitespace(_arg3);
};
if (((!(_arg2)) || ((_arg2 == "")))){
Logger.logError("No apiId given. Please use the API ID from your API settings page.");
dispatchEvent(APIEvent.API_CONNECTED, false, APIEvent.ERROR_INVALID_ARGUMENT);
return;
};
Logger.logMessage((("====== Newgrounds API v" + VERSION) + " ======"));
_connection.connectionState = APIConnection.CONNECTING;
_root = _arg1;
_movieVersion = _arg4;
_connection.apiId = _arg2;
_local5 = _arg2.indexOf(":");
if (_local5 != -1){
_connection.trackerId = uint(_arg2.substring(0, _local5));
} else {
_connection.trackerId = uint(_arg2);
};
if (!_connection.trackerId){
Logger.logError(("Invalid API ID: " + _arg2));
dispatchEvent(APIEvent.API_CONNECTED, false, APIEvent.ERROR_INVALID_ARGUMENT);
return;
};
_connection.encryptionKey = _arg3;
_connection.initialized = true;
if (!_root.loaderInfo){
Logger.logWarning("The root DisplayObject is currently not on the stage. Connection will be completed once it is added to stage.");
};
_root.addEventListener(Event.ENTER_FRAME, checkRootLoaderInfo);
checkRootLoaderInfo(null);
}
private static function doConnect(_arg1:Object):void{
if (((isNetworkHost) && (!((_debugMode == RELEASE_MODE))))){
Logger.logMessage("Live file detected, turning off debug mode.");
_debugMode = RELEASE_MODE;
};
if (((_arg1) && (_arg1.NewgroundsAPI_SandboxID))){
_bridge = new Bridge(_arg1.NewgroundsAPI_SandboxID);
APICommand.bridge = _bridge;
};
if (_debugMode == RELEASE_MODE){
if (_arg1){
if (_arg1.NewgroundsAPI_UserName){
_connection.username = _arg1.NewgroundsAPI_UserName;
};
if (_arg1.NewgroundsAPI_UserID){
_connection.userId = _arg1.NewgroundsAPI_UserID;
};
if (_arg1.NewgroundsAPI_PublisherID){
_connection.publisherId = _arg1.NewgroundsAPI_PublisherID;
};
if (_arg1.NewgroundsAPI_UserpageFormat){
_connection.userpageFormat = _arg1.NewgroundsAPI_UserpageFormat;
};
if (_arg1.NewgroundsAPI_SessionID){
_connection.sessionId = _arg1.NewgroundsAPI_SessionID;
};
if (_arg1.NewgroundsAPI_SaveGroupID){
_requestedSaveGroupId = _arg1.NewgroundsAPI_SaveGroupID;
};
if (_arg1.NewgroundsAPI_SaveFileID){
_requestedSaveFileId = _arg1.NewgroundsAPI_SaveFileID;
};
};
} else {
_connection.debug = true;
if ((((_debugMode == DEBUG_MODE_LOGGED_IN)) || ((_debugMode == DEBUG_MODE_LOGGED_OUT)))){
_connection.publisherId = 1;
};
if (_debugMode == DEBUG_MODE_LOGGED_IN){
_connection.sessionId = "D3bu64p1U53R";
_connection.userId = 10;
_connection.username = "API-Debugger";
};
};
_connection.sendSimpleCommand("connectMovie", onConnect, {host:_connection.hostDomain, movie_version:_movieVersion, publisher_id:_connection.publisherId});
}
private static function onConnect(_arg1:APIEvent):void{
var _local2:Object = _arg1.data;
if (!_arg1.success){
Logger.logError("Unable to connect to the API.");
_connection.reset();
dispatchEvent(APIEvent.API_CONNECTED, _arg1.data, _arg1.error);
return;
};
if (debugMode != RELEASE_MODE){
_adFeedURL = TEST_AD_FEED_URL;
} else {
if (_local2.ad_url){
_adFeedURL = unescape(_local2.ad_url);
};
};
switch (_local2.ad_status){
case -1:
Logger.logWarning("Your movie is not approved to run Flash Ads.");
break;
case 0:
Logger.logWarning("Your movie is still awaiting approval to run Flash Ads.");
break;
case 1:
Logger.logMessage("Your movie is approved to run Flash Ads!");
break;
};
_adsApproved = (_local2.ad_status == 1);
if ((((_debugMode == DEBUG_MODE_HOST_BLOCKED)) || (_local2.deny_host))){
Logger.logWarning((_connection.hostDomain + " does not have permission to host this movie!"), "Update your API configuration to allow this host.");
dispatchEvent(APIEvent.API_CONNECTED, {officialURL:unescape(_local2.movie_url)}, APIEvent.ERROR_HOST_BLOCKED);
_connection.reset();
return;
};
_movieName = (_local2.movieName) ? _local2.movieName : "";
Logger.logMessage("Connecting to the Newgrounds API Gateway...", (("----- " + _local2.movie_name) + " -----"));
if (_debugMode == DEBUG_MODE_NEW_VERSION){
_local2.movie_version = "Debug Mode";
};
if (_local2.movie_version){
Logger.logMessage("A new version of this movie is available.", ("Current version:\t" + _movieVersion), ("Newest version:\t" + _local2.movie_version), "Use API.loadOfficialVersion() to link to the latest version.");
_newVersion = true;
} else {
_newVersion = false;
};
if (_local2.request_portal_url){
_connection.sendSimpleCommand("setPortalID", null, {portal_url:_connection.hostURL});
};
_connection.sendSimpleCommand("preloadSettings", onMetadataLoaded, {publisher_id:_connection.publisherId, user_id:_connection.userId});
}
private static function onMetadataLoaded(_arg1:APIEvent):void{
var _local3:uint;
var _local4:uint;
var _local6:Object;
var _local7:Object;
var _local8:Boolean;
var _local9:Boolean;
var _local10:Boolean;
var _local11:Medal;
var _local12:Object;
var _local13:ScoreBoard;
var _local14:Object;
var _local15:Array;
var _local16:Array;
var _local17:SaveGroup;
var _local18:Object;
var _local19:Object;
var _local2:Object = _arg1.data;
if (!_arg1.success){
Logger.logWarning("Unable to load movie metadata.");
disconnect();
dispatchEvent(APIEvent.API_CONNECTED, null, _arg1.error);
return;
};
var _local5:uint;
if (_local2.medals){
_local5 = _local2.medals.length;
if (hasUserSession){
_local6 = loadLocal(("medals_unlocked_" + username));
} else {
_local6 = loadLocal("medals_unlocked");
};
_local3 = 0;
while (_local3 < _local5) {
_local7 = _local2.medals[_local3];
_local8 = _local7.medal_unlocked;
_local9 = ((_local6) && (_local6[_local7.medal_id]));
_local10 = (hasUserSession) ? _local8 : _local9;
if (debugMode != RELEASE_MODE){
_local10 = false;
};
_local11 = new Medal(_connection, _local7.medal_id, _local7.medal_name, _local7.medal_description, Boolean(int(_local7.secret)), _local10, _local7.medal_value, _local7.medal_difficulty, _local7.medal_icon);
_local11.addEventListener(APIEvent.MEDAL_UNLOCKED, onMedalUnlocked, false, 0, true);
_local11.addEventListener(APIEvent.MEDAL_UNLOCK_CONFIRMED, onMedalUnlockConfirmed, false, 0, true);
_medals[_local11.name] = _local11;
_medalsArray.push(_local11);
Logger.logMessage(_local11);
if (((((hasUserSession) && (_local9))) && (!(_local8)))){
Logger.logMessage((("Server missed the \"" + _local11.name) + "\" unlock. Resending..."));
_local11.unlock();
};
_local3++;
};
};
Logger.logMessage((((_local5 + " medal") + ((_local5)!=1) ? "s" : "") + " initialized."));
_local5 = 0;
if (_local2.score_boards){
_local5 = _local2.score_boards.length;
_local3 = 0;
while (_local3 < _local5) {
_local12 = _local2.score_boards[_local3];
_local13 = new ScoreBoard(_connection, _local12.name, _local12.id);
_scoreBoards[_local13.name] = _local13;
_scoreBoardsArray.push(_local13);
Logger.logMessage(_local13);
_local3++;
};
};
Logger.logMessage((((_local5 + " scoreboard") + ((_local5)!=1) ? "s" : "") + " initialized."));
_local5 = 0;
if (_local2.save_groups){
_local5 = _local2.save_groups.length;
_local3 = 0;
while (_local3 < _local5) {
_local14 = _local2.save_groups[_local3];
_local15 = [];
if (_local14.keys){
_local4 = 0;
while (_local4 < _local14.keys.length) {
_local18 = _local14.keys[_local4];
_local15.push(new SaveKey(_local18.name, _local18.id, _local18.type));
_local4++;
};
};
_local16 = [];
if (_local14.ratings){
_local3 = 0;
while (_local3 < _local14.ratings.length) {
_local19 = _local14.ratings[_local3];
_local16.push(new SaveRating(_local19.name, _local19.id, _local19.float, _local19.min, _local19.max));
_local3++;
};
};
_local17 = new SaveGroup(_connection, _local14.group_name, _local14.group_id, _local14.group_type, _local15, _local16);
_saveGroups[_local17.name] = _local17;
_saveGroupsArray.push(_local17);
Logger.logMessage(_local17);
_local3++;
};
};
Logger.logMessage((((_local5 + " save group") + ((_local5)!=1) ? "s" : "") + " initialized."));
if (_local2.save_file_path){
_saveFilePath = (_local2.save_file_path + "/");
SaveFile._saveFilePath = _saveFilePath;
Logger.logInternal(("Save file path: " + _saveFilePath));
};
if (_local2.image_file_path){
_imageFilePath = (_local2.image_file_path + "/");
SaveFile._imageFilePath = _imageFilePath;
Logger.logInternal(("Image file path: " + _imageFilePath));
};
Logger.logMessage("Connection complete!");
_connection.connectionState = APIConnection.CONNECTED;
dispatchEvent(APIEvent.API_CONNECTED, {movieName:_movieName, newVersion:_newVersion});
if (((_requestedSaveFileId) && (_requestedSaveGroupId))){
API.addEventListener(APIEvent.FILE_LOADED, onRequestedFileLoaded);
API.loadSaveFile(_requestedSaveFileId, false);
};
}
public static function disconnect():void{
var _local1:Medal;
if (!_connection.connected){
Logger.logWarning("The Newgrounds API is already disconnected.");
return;
};
_connection.reset();
for each (_local1 in _medals) {
_local1.removeEventListener(APIEvent.MEDAL_UNLOCKED, onMedalUnlocked);
_local1.removeEventListener(APIEvent.MEDAL_UNLOCK_CONFIRMED, onMedalUnlockConfirmed);
};
_newVersion = false;
_medals = new Object();
_medalsArray = [];
_scoreBoards = new Object();
_scoreBoardsArray = [];
_saveGroups = new Object();
_saveGroupsArray = [];
_sharedObjects = new Object();
_imageFilePath = null;
_saveFilePath = null;
Logger.logMessage("Disconnected from the Newgrounds API.");
}
public static function loadNewgrounds():void{
_connection.loadInBrowser("loadNewgrounds");
}
public static function loadOfficialVersion():void{
if (_connection.assertInitialized()){
_connection.loadInBrowser("loadOfficialVersion", false);
};
}
public static function loadMySite():void{
if (_connection.assertInitialized()){
_connection.loadInBrowser("loadMySite");
};
}
public static function loadCustomLink(_arg1:String):void{
if (_connection.assertInitialized()){
_connection.loadInBrowser("loadCustomLink", true, {link:_arg1});
};
}
public static function getMedal(_arg1:String):Medal{
return (_medals[_arg1]);
}
public static function unlockMedal(_arg1:String):void{
if (!assertConnected()){
return;
};
var _local2:Medal = _medals[_arg1];
if (!_local2){
Logger.logError((("No medal named \"" + _arg1) + "\" was found."));
return;
};
_local2.unlock();
}
private static function onMedalUnlocked(_arg1:APIEvent):void{
var _local2:Medal;
var _local3:Object;
if (_arg1.success){
_local2 = Medal(_arg1.data);
if (hasUserSession){
_local3 = loadLocal(("medals_unlocked_" + username));
if (!_local3){
_local3 = new Object();
};
_local3[_local2.id] = true;
saveLocal(("medals_unlocked_" + username), _local3);
} else {
_local3 = loadLocal("medals_unlocked");
if (!_local3){
_local3 = new Object();
};
_local3[Medal(_arg1.data).id] = true;
saveLocal("medals_unlocked", _local3);
Logger.logMessage((("User is not logged in. Medal \"" + _local2.name) + "\" unlocked locally."));
};
};
}
private static function onMedalUnlockConfirmed(_arg1:APIEvent):void{
var _local2:Object;
if (hasUserSession){
_local2 = loadLocal(("medals_unlocked_" + username));
if (!_local2){
_local2 = new Object();
} else {
delete _local2[Medal(_arg1.data).id];
};
saveLocal(("medals_unlocked_" + username), _local2);
};
}
public static function clearLocalMedals():void{
var _local1:Medal;
for each (_local1 in _medals) {
_local1.setUnlocked(false);
};
if (!hasUserSession){
saveLocal("medals_unlocked", new Object());
};
}
public static function getScoreBoard(_arg1:String):ScoreBoard{
if (!assertConnected()){
return (null);
};
return (_scoreBoards[_arg1]);
}
public static function loadScores(_arg1:String, _arg2:String="All-Time", _arg3:uint=1, _arg4:uint=10, _arg5:String=null):ScoreBoard{
if (!assertConnected()){
return (null);
};
var _local6:ScoreBoard = _scoreBoards[_arg1];
if (!_local6){
Logger.logError((("No scoreboard named \"" + _arg1) + "\" was found."));
dispatchEvent(APIEvent.SCORES_LOADED, null, APIEvent.ERROR_INVALID_ARGUMENT);
return (null);
};
_local6.period = _arg2;
_local6.firstResult = _arg3;
_local6.numResults = _arg4;
_local6.tag = _arg5;
_local6.loadScores();
return (_local6);
}
public static function postScore(_arg1:String, _arg2:Number, _arg3:String=null):void{
if (!assertConnected()){
return;
};
if (!hasUserSession){
Logger.logError("The user must be logged-in to post a score.");
dispatchEvent(APIEvent.SCORE_POSTED, null, APIEvent.ERROR_NOT_LOGGED_IN);
return;
};
var _local4:ScoreBoard = _scoreBoards[_arg1];
if (!_local4){
Logger.logError((("No scoreboard named \"" + _arg1) + "\" was found."));
dispatchEvent(APIEvent.SCORE_POSTED, null, APIEvent.ERROR_INVALID_ARGUMENT);
return;
};
_local4.postScore(_arg2, _arg3);
}
public static function getSaveGroup(_arg1:String):SaveGroup{
if (!assertConnected()){
return (null);
};
return (_saveGroups[_arg1]);
}
private static function getSaveGroupById(_arg1:uint):SaveGroup{
var _local2:SaveGroup;
for each (_local2 in _saveGroups) {
if (_local2.id == _arg1){
return (_local2);
};
};
return (null);
}
public static function createSaveFile(_arg1:String):SaveFile{
if (!assertConnected()){
return (null);
};
var _local2:SaveGroup = getSaveGroup(_arg1);
if (!_local2){
Logger.logError((("The save group \"" + _arg1) + "\" was not found."));
return (null);
};
return (new SaveFile(_local2));
}
public static function loadSaveFile(_arg1:uint, _arg2:Boolean=true):void{
_connection.sendSimpleCommand("loadSaveFile", onFileLoaded, {save_id:_arg1, get_contents:_arg2});
}
private static function onFileLoaded(_arg1:APIEvent):void{
var _local2:SaveFile;
if (_arg1.success){
_local2 = SaveFile.fromObject(getSaveGroupById(_arg1.data.group_id), _arg1.data.file);
if (_arg1.data.get_contents){
_local2.load();
} else {
dispatchEvent(APIEvent.FILE_LOADED, _local2);
};
} else {
Logger.logError("Unable to load file:", _arg1.error);
dispatchEvent(APIEvent.FILE_LOADED, null, _arg1.error);
};
}
public static function createSaveQuery(_arg1:String):SaveQuery{
if (!assertConnected()){
return (null);
};
var _local2:SaveGroup = getSaveGroup(_arg1);
if (!_local2){
Logger.logError((("The save group \"" + _arg1) + "\" was not found."));
return (null);
};
var _local3:SaveQuery = new SaveQuery(_local2);
return (_local3);
}
public static function createSaveQueryByDate(_arg1:String, _arg2:Boolean=true):SaveQuery{
var _local3:SaveQuery = createSaveQuery(_arg1);
if (!_local3){
return (null);
};
_local3.sortOn(SaveQuery.CREATED_ON, _arg2);
return (_local3);
}
public static function createSaveQueryByName(_arg1:String, _arg2:String, _arg3:Boolean=false, _arg4:Boolean=false):SaveQuery{
var _local5:SaveQuery = createSaveQuery(_arg1);
_local5.addCondition(SaveQuery.FILE_NAME, (_arg3) ? SaveQuery.OPERATOR_EQUAL : SaveQuery.OPERATOR_CONTAINS, _arg2);
return (_local5);
}
public static function createSaveQueryByRating(_arg1:String, _arg2:String, _arg3:Boolean=true):SaveQuery{
var _local4:SaveQuery = createSaveQuery(_arg1);
_local4.sortOn(_arg2, _arg3);
return (_local4);
}
private static function onRequestedFileLoaded(_arg1:APIEvent):void{
var _local2:SaveFile;
API.removeEventListener(APIEvent.FILE_LOADED, onRequestedFileLoaded);
if (_arg1.success){
_local2 = (_arg1.data as SaveFile);
if (_local2){
dispatchEvent(APIEvent.FILE_REQUESTED, _local2);
};
};
}
public static function addEventListener(_arg1:String, _arg2:Function, _arg3:int=0, _arg4:Boolean=true):void{
_dispatcher.addEventListener(_arg1, _arg2, false, _arg3, _arg4);
}
public static function removeEventListener(_arg1:String, _arg2:Function):void{
_dispatcher.removeEventListener(_arg1, _arg2);
}
private static function dispatchEvent(_arg1:String, _arg2=null, _arg3:String=null):void{
_dispatcher.dispatchEvent(new APIEvent(_arg1, _arg2, _arg3));
}
public static function saveLocal(_arg1:String, _arg2:Object):Boolean{
var sharedObject:SharedObject;
var sharedObjectName:String;
var saveId = _arg1;
var saveData = _arg2;
try {
sharedObjectName = ((("ng_ap_secure_" + _connection.trackerId) + "_") + RC4.encrypt(saveId, _connection.encryptionKey));
if (!_sharedObjects[saveId]){
_sharedObjects[saveId] = SharedObject.getLocal(sharedObjectName);
};
sharedObject = _sharedObjects[saveId];
sharedObject.data.data = encodeData(saveData);
} catch(error:Error) {
Logger.logError("Unable to save local data.", error);
return (false);
};
return (true);
}
public static function loadLocal(_arg1:String):Object{
var sharedObject:SharedObject;
var sharedObjectName:String;
var saveId = _arg1;
try {
sharedObjectName = ((("ng_ap_secure_" + _connection.trackerId) + "_") + RC4.encrypt(saveId, _connection.encryptionKey));
if (!_sharedObjects[saveId]){
_sharedObjects[saveId] = SharedObject.getLocal(sharedObjectName);
};
sharedObject = _sharedObjects[saveId];
if (((((sharedObject) && (sharedObject.data))) && (sharedObject.data.data))){
return (decodeData(sharedObject.data.data));
};
return (null);
} catch(error:Error) {
Logger.logError("Unable to load local data.", error);
};
return (null);
}
public static function logCustomEvent(_arg1:String):void{
if (assertConnected()){
Logger.logMessage(("Logged event: " + _arg1));
_connection.sendSimpleCommand("logCustomEvent", null, {event:_arg1});
};
}
private static function encodeData(_arg1:Object):String{
if (!_connection.assertInitialized()){
return (null);
};
return (RC4.encrypt(JSON.encode(_arg1), _connection.encryptionKey));
}
private static function decodeData(_arg1:String):Object{
if (!_connection.assertInitialized()){
return (null);
};
try {
return ((JSON.decode(RC4.decrypt(_arg1, _connection.encryptionKey)) as Object));
} catch(error:Error) {
};
return (null);
}
public static function stopPendingCommands():void{
APICommand.stopPendingCommands();
Logger.logMessage("Pending commands stopped.");
}
public static function setFont(_arg1:TextField, _arg2:String):void{
var _local3:TextFormat;
var _local4:Boolean;
var _local5:TextFormat;
if (((_arg1) && (_arg2))){
_local3 = _arg1.getTextFormat();
_local4 = _arg1.embedFonts;
_local5 = new TextFormat(_arg2);
_arg1.defaultTextFormat = _local5;
_arg1.setTextFormat(_local5);
_arg1.embedFonts = true;
if (_arg1.textWidth == 0){
_arg1.embedFonts = _local4;
_arg1.setTextFormat(_local3);
_arg1.defaultTextFormat = _local3;
} else {
_arg1.antiAliasType = "advanced";
_arg1.sharpness = 120;
};
};
}
private static function trimWhitespace(_arg1:String):String{
if (!_arg1){
return (null);
};
var _local2:int;
while (_arg1.charAt(_local2) == " ") {
_local2++;
};
var _local3:int = (_arg1.length - 1);
while ((((_arg1.charAt(_local3) == " ")) && ((_local3 >= 0)))) {
_local3--;
};
return (_arg1.slice(_local2, (_local3 + 1)));
}
private static function checkRootLoaderInfo(_arg1:Event):void{
var event = _arg1;
var loaderInfo:LoaderInfo = _root.loaderInfo;
if (loaderInfo){
try {
while (loaderInfo.loader) {
loaderInfo = loaderInfo.loader.loaderInfo;
};
} catch(error:Error) {
return;
};
_root.removeEventListener(Event.ENTER_FRAME, checkRootLoaderInfo);
_connection.hostURL = loaderInfo.url;
doConnect(loaderInfo.parameters);
};
}
}
}//package com.newgrounds
Section 18
//APICommand (com.newgrounds.APICommand)
package com.newgrounds {
import flash.utils.*;
import flash.events.*;
import flash.net.*;
import com.newgrounds.encoders.json.*;
import com.newgrounds.crypto.*;
import com.newgrounds.encoders.*;
public class APICommand extends APIEventDispatcher {
private var _command:String;
private var _parameters:Object;
private var _secureParameters:Object;
private var _files:Object;
private var _preventCache:Boolean;
private var _hasTimeout:Boolean;
private var _timeoutTimer:Timer;
private var _loader:URLLoader;
private static const TIMEOUT_INTERVAL:uint = 10000;
private static const THROTTLE_INTERVAL:uint = 10050;
private static const THROTTLE_TICK_INTERVAL:uint = 1000;
private static const THROTTLE_THRESHOLD:uint = 24;
private static const ENCRYPTOR_RADIX:String = "/g8236klvBQ#&|;Zb*7CEA59%s`Oue1wziFp$rDVY@TKxUPWytSaGHJ>dmoMR^<0~4qNLhc(I+fjn)X";
private static const CRLF:String = "
";
public static var bridge:Bridge;
private static var _throttleTimestamp:uint;
private static var _throttleCount:int = 0;
private static var _commandQueue:Array = [];
private static var _encryptor:BaseN = new BaseN(ENCRYPTOR_RADIX);
private static var _pendingCommands:Array = [];
private static var _throttleTimer:Timer = function ():Timer{
var _local1:* = new Timer(THROTTLE_TICK_INTERVAL, 0);
_local1.addEventListener(TimerEvent.TIMER, onThrottleTimer);
_local1.start();
return (_local1);
}();
public function APICommand(_arg1:String){
this._command = _arg1;
this._parameters = new Object();
this._secureParameters = new Object();
this._timeoutTimer = new Timer(TIMEOUT_INTERVAL, 1);
this._timeoutTimer.addEventListener(TimerEvent.TIMER, this.onTimeout);
this._hasTimeout = true;
}
public function get command():String{
return (this._command);
}
public function set command(_arg1:String):void{
this._command = _arg1;
}
public function get hasTimeout():Boolean{
return (this._hasTimeout);
}
public function set hasTimeout(_arg1:Boolean):void{
this._hasTimeout = _arg1;
}
public function get parameters():Object{
return (this._parameters);
}
public function set parameters(_arg1:Object):void{
var _local2:String;
this._parameters = new Object();
if (_arg1){
for (_local2 in _arg1) {
this._parameters[_local2] = _arg1[_local2];
};
};
}
public function get preventCache():Boolean{
return (this._preventCache);
}
public function set preventCache(_arg1:Boolean):void{
this._preventCache = _arg1;
}
public function get secureParameters():Object{
return (this._secureParameters);
}
public function set secureParameters(_arg1:Object):void{
var _local2:String;
this._secureParameters = new Object();
if (_arg1){
for (_local2 in _arg1) {
this._secureParameters[_local2] = _arg1[_local2];
};
};
}
public function get hasSecureParameters():Boolean{
var _local1:String;
for (_local1 in this._secureParameters) {
return (true);
};
return (false);
}
public function addFile(_arg1:String, _arg2:ByteArray, _arg3:String, _arg4:String="application/octet-stream"):void{
if (!this._files){
this._files = new Object();
};
var _local5:Object = {filename:_arg1, data:_arg2, dataField:_arg3, contentType:_arg4};
this._files[_arg1] = _local5;
}
public function removeFile(_arg1:String):void{
if (this._files){
delete this._files[_arg1];
};
}
public function clearFiles():void{
this._files = null;
}
public function close():void{
var _local1:uint;
if (this._loader){
try {
this._loader.close();
} catch(error:Error) {
};
this._timeoutTimer.stop();
_local1 = 0;
while (_local1 < _pendingCommands.length) {
if (_pendingCommands[_local1] == this){
_pendingCommands.splice(_local1, 1);
break;
};
_local1++;
};
this._loader = null;
};
}
public function loadInBrowser(_arg1:APIConnection, _arg2:Boolean):void{
var _local4:String;
var _local5:String;
this._parameters.command_id = this._command;
this._parameters.tracker_id = (_arg1.apiId) ? _arg1.apiId : 1;
if (_arg1.debug){
this._parameters.debug = 1;
};
var _local3:String = ((_arg1.apiURL + "?host=") + escape(_arg1.hostDomain));
for (_local4 in this._parameters) {
_local3 = (_local3 + ((("&" + escape(_local4)) + "=") + escape(this._parameters[_local4])));
};
if (_arg2){
_local5 = "_blank";
} else {
_local5 = "_top";
};
navigateToURL(new URLRequest(_local3), _local5);
}
public function send(_arg1:APIConnection):void{
if (_throttleCount >= THROTTLE_THRESHOLD){
_commandQueue.push({connection:_arg1, command:this});
} else {
this.sendInternal(_arg1);
};
}
private function sendInternal(_arg1:APIConnection):void{
var _local2:Object;
var _local3:String;
var _local4:*;
var _local5:uint;
var _local6:String;
var _local7:Object;
var _local8:String;
var _local9:String;
var _local10:String;
var _local11:String;
_local2 = new URLVariables();
_local2.command_id = this._command;
_local2.tracker_id = _arg1.apiId;
if (_arg1.debug){
_local2.debug = 1;
};
if (this._preventCache){
_local2.seed = Math.random();
};
for (_local3 in this._parameters) {
_local4 = this._parameters[_local3];
if (_local4 != null){
if ((_local4 is Boolean)){
_local2[_local3] = int(_local4);
} else {
_local2[_local3] = _local4;
};
};
};
if (this.hasSecureParameters){
_local7 = new Object();
for (_local3 in this._secureParameters) {
_local4 = this._secureParameters[_local3];
if (_local4 != null){
if ((_local4 is Boolean)){
_local7[_local3] = int(_local4);
} else {
_local7[_local3] = _local4;
};
};
};
_local8 = "";
_local5 = 0;
while (_local5 < 16) {
_local8 = (_local8 + ENCRYPTOR_RADIX.charAt(uint((Math.random() * ENCRYPTOR_RADIX.length))));
_local5++;
};
_local2.command_id = "securePacket";
_local7.command_id = this._command;
_local7.as_version = 3;
_local7.session_id = _arg1.sessionId;
_local7.user_email = _arg1.userEmail;
_local7.publisher_id = _arg1.publisherId;
_local7.seed = _local8;
_local9 = MD5.hash(_local8);
_local10 = RC4.encrypt(JSON.encode(_local7), _arg1.encryptionKey);
_local2.secure = encryptHex((_local9 + _local10));
};
Logger.logInternal("Sending packet:", _local2);
if (this._files){
_local11 = "";
_local5 = 0;
while (_local5 < 32) {
_local11 = (_local11 + String.fromCharCode(uint((97 + (Math.random() * 25)))));
_local5++;
};
_local6 = (("multipart/form-data; boundary=\"" + _local11) + "\"");
_local2 = this.buildMultipartData(_local11, _local2, this._files);
} else {
for (_local3 in _local2) {
if (typeof(_local2[_local3]) == "object"){
_local2[_local3] = JSON.encode(_local2[_local3]);
};
};
_local6 = "application/x-www-form-urlencoded";
};
_pendingCommands.push(this);
_throttleCount++;
_throttleTimestamp = getTimer();
this.startLoader(_arg1.apiURL, _local2, _local6);
}
private function onTimeout(_arg1):void{
this.close();
Logger.logError("Command timed out.");
dispatchEvent(new APIEvent(APIEvent.COMMAND_COMPLETE, null, APIEvent.ERROR_TIMED_OUT));
}
private function onError(_arg1:String):void{
Logger.logError("Error when sending command:", _arg1);
dispatchEvent(new APIEvent(APIEvent.COMMAND_COMPLETE, null, APIEvent.ERROR_UNKNOWN));
this.close();
}
private function onComplete(_arg1:String):void{
var response:Object;
var data = _arg1;
try {
if (((!(data)) || ((data == "")))){
throw (new Error());
};
Logger.logInternal("Received packet:", data);
response = JSON.decode(data);
if (!response){
throw (new Error());
};
if (bridge){
bridge.sendEvent(response.command_id, response);
};
dispatchEvent(new APIEvent(APIEvent.COMMAND_COMPLETE, response, (((response) && (response.success))) ? APIEvent.ERROR_NONE : APIEvent.ERROR_COMMAND_FAILED));
} catch(e) {
Logger.logError(("Invalid response returned from server: " + data));
dispatchEvent(new APIEvent(APIEvent.COMMAND_COMPLETE, null, APIEvent.ERROR_BAD_RESPONSE));
};
this.close();
}
private function startLoader(_arg1:String, _arg2:Object, _arg3:String):void{
var url = _arg1;
var data = _arg2;
var contentType = _arg3;
var urlRequest:URLRequest = new URLRequest(url);
urlRequest.data = data;
urlRequest.method = URLRequestMethod.POST;
urlRequest.contentType = contentType;
this._loader = new URLLoader();
this._loader.addEventListener(Event.COMPLETE, this.as3CompleteHandler);
this._loader.addEventListener(Event.OPEN, this.as3UpdateHandler);
this._loader.addEventListener(ProgressEvent.PROGRESS, this.as3UpdateHandler);
this._loader.addEventListener(IOErrorEvent.IO_ERROR, this.as3ErrorHandler);
this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.as3ErrorHandler);
try {
this._loader.load(urlRequest);
if (this._hasTimeout){
this._timeoutTimer.start();
};
} catch(error) {
onError("Security error");
};
}
private function as3CompleteHandler(_arg1:Event):void{
this.onComplete(this._loader.data);
}
private function as3UpdateHandler(_arg1:Event):void{
if (this._timeoutTimer.running){
this._timeoutTimer.reset();
this._timeoutTimer.start();
};
}
private function as3ErrorHandler(_arg1:Event):void{
this.onError(_arg1.toString());
}
private function buildMultipartData(_arg1:String, _arg2:Object, _arg3:Object):ByteArray{
var _local5:String;
var _local6:Object;
var _local4:ByteArray = new ByteArray();
_local4.endian = Endian.BIG_ENDIAN;
_arg1 = ("--" + _arg1);
for (_local5 in _arg2) {
_local4.writeUTFBytes((_arg1 + CRLF));
_local4.writeUTFBytes(((("Content-Disposition: form-data; name=\"" + _local5) + "\"") + CRLF));
_local4.writeUTFBytes(CRLF);
_local4.writeUTFBytes((_arg2[_local5].toString() + CRLF));
};
if (this._files){
for each (_local6 in _arg3) {
_local4.writeUTFBytes((_arg1 + CRLF));
_local4.writeUTFBytes(("Content-Disposition: form-data; name=\"Filename\"" + CRLF));
_local4.writeUTFBytes(CRLF);
_local4.writeUTFBytes((_local6.filename + CRLF));
_local4.writeUTFBytes((_arg1 + CRLF));
_local4.writeUTFBytes(((((("Content-Disposition: form-data; name=\"" + _local6.dataField) + "\"; filename=\"") + _local6.filename) + "\"") + CRLF));
_local4.writeUTFBytes((("Content-Type: " + _local6.contentType) + CRLF));
_local4.writeUTFBytes(CRLF);
_local4.writeBytes(_local6.data);
_local4.writeUTFBytes(CRLF);
};
_local4.writeUTFBytes((_arg1 + CRLF));
_local4.writeUTFBytes(("Content-Disposition: form-data; name=\"Upload\"" + CRLF));
_local4.writeUTFBytes(CRLF);
_local4.writeUTFBytes(("Submit Query" + CRLF));
};
_local4.writeUTFBytes((_arg1 + "--"));
_local4.position = 0;
return (_local4);
}
public static function stopPendingCommands():void{
var _local1:APICommand;
for each (_local1 in _pendingCommands) {
_local1.close();
};
_pendingCommands = [];
}
private static function onThrottleTimer(_arg1):void{
var _local2:Object;
if ((getTimer() - _throttleTimestamp) >= THROTTLE_INTERVAL){
_throttleCount = 0;
_throttleCount = 0;
while (((_commandQueue.length) && ((_throttleCount < THROTTLE_THRESHOLD)))) {
_local2 = _commandQueue.shift();
_local2.command.send(_local2.connection);
_throttleCount++;
};
};
}
private static function encryptHex(_arg1:String):String{
var _local2:uint = (_arg1.length % 6);
var _local3 = "";
var _local4:uint;
while (_local4 < _arg1.length) {
_local3 = (_local3 + _encryptor.encodeUint(uint(("0x" + _arg1.substr(_local4, 6))), 4));
_local4 = (_local4 + 6);
};
return ((_local2.toString() + _local3));
}
}
}//package com.newgrounds
Section 19
//APIConnection (com.newgrounds.APIConnection)
package com.newgrounds {
import flash.system.*;
public class APIConnection {
public var initialized:Boolean;
public var connectionState:String;// = "notConnected"
public var apiURL:String;// = "http://www.ngads.com/gateway_v2.php"
public var apiId:String;
public var debug:Boolean;
public var trackerId:uint;
public var publisherId:uint;
public var encryptionKey:String;
public var sessionId:String;
public var userEmail:String;
public var username:String;
public var userId:uint;
public var userpageFormat:uint;
private var _hostURL:String;
public var hostDomain:String;
public static const NOT_CONNECTED:String = "notConnected";
public static const CONNECTING:String = "connecting";
public static const CONNECTED:String = "connected";
public function APIConnection(){
this.reset();
}
public function get hostURL():String{
return (this._hostURL);
}
public function set hostURL(_arg1:String):void{
var _local2:Array;
this._hostURL = _arg1;
this.hostDomain = null;
if (this._hostURL){
_local2 = this._hostURL.split("/");
if (((!((_local2[0] == "file:"))) && (!((this._hostURL == "localhost"))))){
this.hostDomain = _local2[2];
};
};
if (!this.hostDomain){
this.hostDomain = "localhost";
};
}
public function get sandboxType():String{
return (Security.sandboxType);
}
public function get isNetworkHost():Boolean{
switch (this.sandboxType){
case "localWithFile":
case "localWithNetwork":
case "localTrusted":
case "application":
return (false);
case "remote":
default:
return (true);
};
}
public function get hasUserSession():Boolean{
return (((((!((this.sessionId == null))) && (!((this.sessionId == ""))))) && (!((this.publisherId == 0)))));
}
public function get connected():Boolean{
return ((this.connectionState == CONNECTED));
}
public function reset():void{
this.connectionState = NOT_CONNECTED;
this.encryptionKey = null;
this.sessionId = null;
this.userEmail = null;
this.username = null;
this.userId = 0;
this.userpageFormat = 0;
}
public function assertInitialized():Boolean{
if (!this.initialized){
Logger.logError("You must initialized the API using API.connect() before using this command.");
return (false);
};
return (true);
}
public function assertConnected():Boolean{
if (!(this.connectionState) == CONNECTED){
Logger.logError("You must establish a connection using API.connect() before using this command.");
return (false);
};
return (true);
}
public function sendSimpleCommand(_arg1:String, _arg2:Function, _arg3:Object=null, _arg4:Object=null):void{
var _local5:APICommand = new APICommand(_arg1);
_local5.parameters = _arg3;
_local5.secureParameters = _arg4;
if (_arg2 != null){
_local5.addEventListener(APIEvent.COMMAND_COMPLETE, _arg2);
};
_local5.send(this);
}
public function sendCommand(_arg1:APICommand):void{
_arg1.send(this);
}
public function loadInBrowser(_arg1:String, _arg2:Boolean=true, _arg3:Object=null):void{
var _local4:APICommand = new APICommand(_arg1);
_local4.parameters = _arg3;
_local4.loadInBrowser(this, _arg2);
}
}
}//package com.newgrounds
Section 20
//APIEvent (com.newgrounds.APIEvent)
package com.newgrounds {
import flash.events.*;
public class APIEvent extends Event {
private var _data;
private var _success:Boolean;
private var _error:String;
static const COMMAND_COMPLETE:String = "commandComplete";
static const MEDAL_UNLOCK_CONFIRMED:String = "medalUnlockConfirmed";
static const ICON_LOADED:String = "iconLoaded";
public static const API_CONNECTED:String = "movieConnected";
public static const LOG:String = "log";
public static const MEDAL_UNLOCKED:String = "medalUnlocked";
public static const SCORES_LOADED:String = "scoresLoaded";
public static const SCORE_POSTED:String = "scorePosted";
public static const QUERY_COMPLETE:String = "queryComplete";
public static const FILE_LOADED:String = "fileLoaded";
public static const FILE_SAVED:String = "fileSaved";
public static const FILE_REQUESTED:String = "fileRequested";
public static const VOTE_COMPLETE:String = "voteComplete";
public static const ERROR_NONE:String = "noError";
public static const ERROR_UNKNOWN:String = "unknownError";
public static const ERROR_COMMAND_FAILED:String = "commandFailed";
public static const ERROR_NOT_CONNECTED:String = "notConnected";
public static const ERROR_INVALID_ARGUMENT:String = "invalidArgument";
public static const ERROR_TIMED_OUT:String = "timedOut";
public static const ERROR_BAD_FILE:String = "badFile";
public static const ERROR_BAD_RESPONSE:String = "badResponse";
public static const ERROR_SENDING_COMMAND:String = "errorSendingCommand";
public static const ERROR_HOST_BLOCKED:String = "hostBlocked";
public static const ERROR_ALREADY_VOTED:String = "alreadyVoted";
public static const ERROR_NOT_LOGGED_IN:String = "notLoggedIn";
public static const ERROR_WRONG_ENCRYPTION_KEY:String = "wrongEncryptionKey";
public function APIEvent(_arg1:String, _arg2=null, _arg3:String=null){
super(_arg1);
if (((((!(_arg3)) || ((_arg3 == "")))) || ((_arg3 == ERROR_NONE)))){
this._error = ERROR_NONE;
this._success = true;
} else {
this._error = _arg3;
this._success = false;
};
if (_arg2){
this._data = _arg2;
} else {
this._data = {};
};
}
override public function clone():Event{
return (new APIEvent(type, this._data, this._error));
}
public function get success():Boolean{
return (this._success);
}
public function get data(){
return (this._data);
}
public function get error():String{
return (this._error);
}
}
}//package com.newgrounds
Section 21
//APIEventDispatcher (com.newgrounds.APIEventDispatcher)
package com.newgrounds {
import flash.display.*;
import com.newgrounds.*;
import flash.events.*;
class APIEventDispatcher extends EventDispatcher {
private static var _globalDispatcher:EventDispatcher;
private static var _eventQueue:Array = initEventQueue();
private static var _ticker:Sprite;
override public function dispatchEvent(_arg1:Event):Boolean{
_eventQueue.push({dispatcher:this, event:_arg1});
return (true);
}
private function actualDispatchEvent(_arg1:Event):void{
var _local2:Boolean = super.dispatchEvent(_arg1);
if (((_globalDispatcher) && (!((this == _globalDispatcher))))){
_globalDispatcher.dispatchEvent(_arg1);
};
}
public static function get globalDispatcher():EventDispatcher{
return (_globalDispatcher);
}
public static function set globalDispatcher(_arg1:EventDispatcher):void{
_globalDispatcher = _arg1;
}
private static function initEventQueue():Array{
_ticker = new Sprite();
_ticker.addEventListener(Event.ENTER_FRAME, runEventQueue);
return ([]);
}
private static function runEventQueue(_arg1):void{
var _local3:Array;
var _local4:uint;
var _local5:Object;
var _local2:uint = _eventQueue.length;
if (_local2){
_local3 = _eventQueue;
_eventQueue = [];
_local4 = 0;
while (_local4 < _local2) {
_local5 = _local3[_local4];
_local5.dispatcher.actualDispatchEvent(_local5.event);
_local4++;
};
};
}
}
}//package com.newgrounds
Section 22
//BitmapLoader (com.newgrounds.BitmapLoader)
package com.newgrounds {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.system.*;
public class BitmapLoader extends APIEventDispatcher {
private var _url:String;
private var _bitmapData:BitmapData;
private var _loaded:Boolean;// = true
private var _loader:Loader;
private static const LOADER_CONTEXT:LoaderContext = new LoaderContext(true);
static var _cacheSeed:uint = 0;
public function BitmapLoader(_arg1:BitmapData, _arg2:String){
this._bitmapData = _arg1;
this._url = _arg2;
}
public function get url():String{
return (this._url);
}
public function set url(_arg1:String):void{
this._loaded = false;
this._url = _arg1;
}
public function get bitmapData():BitmapData{
return (this._bitmapData);
}
public function set bitmapData(_arg1:BitmapData):void{
this._bitmapData = _arg1;
this._loaded = true;
}
public function get loaded():Boolean{
return (this._loaded);
}
private function createLoader():Loader{
var _local1:Loader = new Loader();
var _local2:URLRequest = new URLRequest(this._url);
_local2.method = URLRequestMethod.GET;
_local2.data = _cacheSeed.toString();
_local1.load(_local2, LOADER_CONTEXT);
return (_local1);
}
private function disposeLoader():void{
if (this._loader){
try {
this._loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, this.onLoadComplete);
this._loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, this.onLoadComplete);
this._loader.unload();
} catch(error) {
};
this._loader = null;
};
}
public function load():void{
if (((!(this._url)) || ((this._url == "")))){
this.onLoadComplete(null);
return;
};
this.disposeLoader();
this._loader = this.createLoader();
this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onLoadComplete);
this._loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.onLoadComplete);
}
public function attachBitmap(_arg1:DisplayObjectContainer):Sprite{
var _local2:Sprite = new Sprite();
if (((((!(this._loaded)) && (this._url))) && (!((this._url == ""))))){
if (!this._loader){
this.load();
};
_local2.addChild(this.createLoader());
} else {
_local2.addChild(new Bitmap(this._bitmapData));
};
if (_arg1){
_arg1.addChild(_local2);
};
return (_local2);
}
private function onLoadComplete(_arg1:Event):void{
var bitmapData:BitmapData;
var event = _arg1;
try {
if (((((((event) && ((event.type == Event.COMPLETE)))) && (this._loader))) && ((this._loader.content is Bitmap)))){
bitmapData = Bitmap(this._loader.content).bitmapData;
this._bitmapData = bitmapData;
this._loaded = true;
};
} catch(error:SecurityError) {
if (bitmapData){
bitmapData.dispose();
};
};
this.disposeLoader();
dispatchEvent(new APIEvent(APIEvent.ICON_LOADED, this, (this._loaded) ? null : APIEvent.ERROR_BAD_FILE));
}
}
}//package com.newgrounds
Section 23
//Bridge (com.newgrounds.Bridge)
package com.newgrounds {
import flash.events.*;
import flash.net.*;
public class Bridge {
private var _inConnection:LocalConnection;
private var _outConnection:LocalConnection;
private var _widgetId:String;
public function Bridge(_arg1:String){
this._widgetId = _arg1;
this._inConnection = new LocalConnection();
this._outConnection = new LocalConnection();
this._inConnection.client = this;
try {
this._inConnection.connect(("rec_" + this._widgetId));
} catch(error) {
};
this._outConnection.addEventListener(StatusEvent.STATUS, this.onStatus);
Logger.addEventListener(APIEvent.LOG, this.onLogMessage);
}
private function onLogMessage(_arg1:APIEvent):void{
try {
this._outConnection.send(this._widgetId, "sendEvent", "trace", String(_arg1.data));
} catch(error) {
};
}
public function sendEvent(_arg1:String, _arg2:Object):void{
if (this._outConnection){
_arg2 = {data:_arg2};
this._outConnection.send(this._widgetId, "sendEvent", _arg1, _arg2);
};
}
public function receiveEvent(_arg1:String, _arg2:Object):void{
}
private function onStatus(_arg1:Event):void{
}
}
}//package com.newgrounds
Section 24
//Logger (com.newgrounds.Logger)
package com.newgrounds {
import flash.events.*;
public class Logger {
static const PRIORITY_INTERNAL:uint = 0;
public static const PRIORITY_MESSAGE:uint = 1;
public static const PRIORITY_WARNING:uint = 2;
public static const PRIORITY_ERROR:uint = 3;
public static const PRIORITY_MAX:uint = 4;
private static const HEADER:String = "[Newgrounds API] :: ";
private static var _eventDispatcher:EventDispatcher = new EventDispatcher();
private static var _messageLevel:uint = 1;
private static var _throwLevel:uint = 4;
static function logInternal(... _args):void{
log(PRIORITY_INTERNAL, _args);
}
public static function logMessage(... _args):void{
log(PRIORITY_MESSAGE, _args);
}
public static function logWarning(... _args):void{
log(PRIORITY_WARNING, _args);
}
public static function logError(... _args):void{
log(PRIORITY_ERROR, _args);
}
private static function log(_arg1:uint=1, _arg2:Array=null):void{
var _local3:uint;
if (_arg1 >= _messageLevel){
_local3 = 0;
while (_local3 < _arg2.length) {
trace((HEADER + _arg2[_local3]));
_eventDispatcher.dispatchEvent(new APIEvent(APIEvent.LOG, _arg2[_local3]));
_local3++;
};
};
if (_arg1 >= _throwLevel){
throw (new Error(_arg2.join("\n")));
};
}
public static function addEventListener(_arg1:String, _arg2:Function):void{
_eventDispatcher.addEventListener(_arg1, _arg2, false, 0, false);
}
}
}//package com.newgrounds
Section 25
//Medal (com.newgrounds.Medal)
package com.newgrounds {
import flash.display.*;
import com.newgrounds.assets.*;
public class Medal extends APIEventDispatcher {
private var _connection:APIConnection;
private var _name:String;
private var _id:uint;
private var _description:String;
private var _secret:Boolean;
private var _value:uint;
private var _unlocked:Boolean;
private var _difficulty:String;
private var _iconLoader:BitmapLoader;
public static const ICON_WIDTH:uint = 50;
public static const ICON_HEIGHT:uint = 50;
public static const DIFFICULTY_EASY:String = "Easy";
public static const DIFFICULTY_MODERATE:String = "Moderate";
public static const DIFFICULTY_CHALLENGING:String = "Challenging";
public static const DIFFICULTY_DIFFICULT:String = "Difficult";
public static const DIFFICULTY_BRUTAL:String = "Brutal";
private static const DIFFICULTIES:Array = ["Unknown", DIFFICULTY_EASY, DIFFICULTY_MODERATE, DIFFICULTY_CHALLENGING, DIFFICULTY_DIFFICULT, DIFFICULTY_BRUTAL];
public static const DEFAULT_ICON:BitmapData = new DefaultMedalIcon(ICON_WIDTH, ICON_HEIGHT);
public function Medal(_arg1:APIConnection, _arg2:uint, _arg3:String, _arg4:String, _arg5:Boolean, _arg6:Boolean, _arg7:uint, _arg8:uint, _arg9:String){
this._connection = _arg1;
this._id = _arg2;
this._name = _arg3;
this._description = _arg4;
this._secret = _arg5;
this._unlocked = _arg6;
this._value = _arg7;
this._difficulty = DIFFICULTIES[_arg8];
this._iconLoader = new BitmapLoader(DEFAULT_ICON, _arg9);
this._iconLoader.load();
}
public function get difficulty():String{
return (this._difficulty);
}
public function get icon():BitmapData{
return (this._iconLoader.bitmapData);
}
public function get id():uint{
return (this._id);
}
public function get name():String{
return (this._name);
}
public function get description():String{
return (this._description);
}
public function get secret():Boolean{
return (this._secret);
}
public function get unlocked():Boolean{
return (this._unlocked);
}
public function get value():uint{
return (this._value);
}
override public function toString():String{
return (((((((("Medal: " + this._name) + "\t\t(") + (this._unlocked) ? "unlocked, " : "locked, ") + this._value) + "pts, ") + this._difficulty) + ")"));
}
public function attachIcon(_arg1:DisplayObjectContainer):Sprite{
return (this._iconLoader.attachBitmap(_arg1));
}
public function unlock():void{
if (this._unlocked){
Logger.logWarning((("Medal \"" + this._name) + "\" is already unlocked."));
return;
};
Logger.logMessage((("Unlocking medal \"" + this.name) + "\"..."));
this._unlocked = true;
if (this._connection.hasUserSession){
this._connection.sendSimpleCommand("unlockMedal", this.onUnlockConfirmed, null, {medal_id:this.id});
};
dispatchEvent(new APIEvent(APIEvent.MEDAL_UNLOCKED, this));
}
function setUnlocked(_arg1:Boolean):void{
this._unlocked = _arg1;
}
private function onUnlockConfirmed(_arg1:APIEvent):void{
if (_arg1.success){
Logger.logMessage((("Medal \"" + this.name) + "\" unlocked."));
} else {
Logger.logError((("Failed to unlock \"" + this.name) + "\"!"));
};
dispatchEvent(new APIEvent(APIEvent.MEDAL_UNLOCK_CONFIRMED, this, _arg1.error));
}
}
}//package com.newgrounds
Section 26
//SaveFile (com.newgrounds.SaveFile)
package com.newgrounds {
import flash.utils.*;
import flash.display.*;
import flash.events.*;
import flash.net.*;
import com.newgrounds.encoders.*;
import com.newgrounds.assets.*;
import flash.geom.*;
public class SaveFile extends APIEventDispatcher {
private var _group:SaveGroup;
private var _name:String;
private var _id:uint;
private var _description:String;
private var _authorId:uint;
private var _authorName:String;
private var _createdDate:String;
private var _modifiedDate:String;
private var _views:uint;
private var _readOnly:Boolean;
private var _public:Boolean;
private var _approved:Boolean;
private var _draft:Boolean;
private var _iconLoader:BitmapLoader;
private var _keys:Object;
private var _ratings:Object;
private var _dataURL:String;
private var _data;
private var _dataLoaded:Boolean;
private var _encodedData;
private var _encoderQueue:Array;
private var _encoding:Boolean;
private var _encodingParent:Object;
private var _encodingProperty:String;
private var _fileSize:uint;
private var _dataLoader:URLLoader;
public static const ICON_WIDTH:uint = 90;
public static const ICON_HEIGHT:uint = 90;
private static const STATUS_PRIVATE:uint = 0;
private static const STATUS_SHARED:uint = 1;
private static const STATUS_UNAPPROVED:uint = 2;
private static const STATUS_APPROVED:uint = 3;
public static const DEFAULT_ICON:BitmapData = new DefaultSaveIcon(ICON_WIDTH, ICON_HEIGHT);
private static var _currentFile:SaveFile;
static var _imageFilePath:String = "";
static var _saveFilePath:String = "";
public function SaveFile(_arg1:SaveGroup){
this._keys = new Object();
this._ratings = new Object();
super();
this._iconLoader = new BitmapLoader(DEFAULT_ICON, null);
this._group = _arg1;
}
public function get group():SaveGroup{
return (this._group);
}
public function get name():String{
return (this._name);
}
public function set name(_arg1:String):void{
this._name = _arg1;
}
public function get description():String{
return (this._description);
}
public function set description(_arg1:String):void{
this._description = _arg1;
}
public function get id():uint{
return (this._id);
}
public function get data():Object{
return (this._data);
}
public function set data(_arg1:Object):void{
this._data = _arg1;
}
public function get bytesLoaded():uint{
if (this._data){
return (this.bytesTotal);
};
if (!this._dataLoader){
return (0);
};
return (this._dataLoader.bytesLoaded);
}
public function get bytesTotal():uint{
return (this._fileSize);
}
public function get readOnly():Boolean{
return (this._readOnly);
}
public function get draft():Boolean{
return (this._draft);
}
public function set draft(_arg1:Boolean):void{
this._draft = _arg1;
}
public function get authorId():uint{
return (this._authorId);
}
public function get authorName():String{
return (this._authorName);
}
public function get keys():Object{
return (this._keys);
}
public function get ratings():Object{
return (this._ratings);
}
public function get views():uint{
return (this._views);
}
public function get createdDate():String{
return (this._createdDate);
}
public function get updatedDate():String{
return (this._modifiedDate);
}
override public function toString():String{
return (("Save File: " + this._name));
}
public function get icon():BitmapData{
return (this._iconLoader.bitmapData);
}
public function set icon(_arg1:BitmapData):void{
this.createIcon(_arg1);
}
public function get iconLoaded():Boolean{
return (this._iconLoader.loaded);
}
public function createIcon(_arg1:IBitmapDrawable):void{
var _local3:Number;
var _local4:Number;
var _local8:Number;
var _local9:Rectangle;
var _local2:BitmapData = new BitmapData(ICON_WIDTH, ICON_HEIGHT, false, 0);
var _local5:Number = 0;
var _local6:Number = 0;
_local3 = Object(_arg1).width;
_local4 = Object(_arg1).height;
if ((_arg1 is DisplayObject)){
_local9 = DisplayObject(_arg1).getBounds(null);
_local5 = _local9.left;
_local6 = _local9.top;
};
var _local7:Matrix = new Matrix();
_local8 = Math.min((ICON_WIDTH / _local3), (ICON_HEIGHT / _local4));
_local7.translate(-(_local5), -(_local6));
_local7.scale(_local8, _local8);
_local7.translate(((ICON_WIDTH - (_local3 * _local8)) / 2), ((ICON_HEIGHT - (_local4 * _local8)) / 2));
_local2.draw(_arg1, _local7);
this._iconLoader.bitmapData = _local2;
}
public function attachIcon(_arg1:DisplayObjectContainer):Sprite{
if (this._iconLoader){
return (this._iconLoader.attachBitmap(_arg1));
};
Logger.logError("No icon available for this sumbission.");
return (null);
}
public function save():void{
if (!this._group.connection.hasUserSession){
Logger.logError("The user must be logged-in to save a file.");
dispatchEvent(new APIEvent(APIEvent.FILE_SAVED, null, APIEvent.ERROR_NOT_LOGGED_IN));
return;
};
BitmapLoader._cacheSeed++;
_currentFile = this;
this.encodeData(true);
}
private function doSave():void{
var _local3:String;
var _local4:Array;
var _local5:String;
var _local6:SaveKey;
var _local7:SaveRating;
var _local8:ByteArray;
var _local1:APICommand = new APICommand("saveFile");
_local1.secureParameters.group = this._group.id;
_local1.secureParameters.user_name = this._group.connection.username;
_local1.secureParameters.filename = this._name;
_local1.secureParameters.description = this._description;
if (this._draft){
_local1.secureParameters.draft = true;
};
if (((this._id) && (!(this._readOnly)))){
_local1.secureParameters.overwrite = 1;
_local1.secureParameters.save_id = this._id;
};
var _local2:Array = [];
for (_local3 in this._keys) {
_local6 = this._group.getKey(_local3);
if (_local6){
_local2.push({id:_local6.id, value:_local6.validateValue(this._keys[_local3])});
} else {
Logger.logError((((("No key named \"" + _local3) + "\" in save group \"") + this._group.name) + "\"."));
};
};
_local1.secureParameters.keys = _local2;
_local4 = [];
for (_local5 in this._ratings) {
_local7 = this._group.getRating(_local5);
if (_local7){
_local4.push({id:_local7.id, value:_local7.validateValue(this._ratings[_local5])});
} else {
Logger.logError((((("No rating named \"" + _local5) + "\" in save group \"") + this._group.name) + "\"."));
};
};
_local1.secureParameters.ratings = _local4;
_local8 = new ByteArray();
_local8.writeObject(this._encodedData);
_local8.compress();
_local1.addFile("file", _local8, "file");
if (this.iconLoaded){
_local1.addFile("thumbnail", PNGEncoder.encode(this.icon), "thumbnail");
};
_local1.addEventListener(APIEvent.COMMAND_COMPLETE, this.onSaveComplete);
this._group.connection.sendCommand(_local1);
}
private function encodeData(_arg1:Boolean):void{
this._encoderQueue = [];
this._encoding = _arg1;
if (_arg1){
this._encodedData = this._data;
this.preEncodeObject(this, "_encodedData");
} else {
this.preEncodeObject(this, "_data");
};
this.encodeObject();
}
private function preEncodeObject(_arg1:Object, _arg2:String):void{
var _local4:Boolean;
var _local6:Boolean;
var _local7:String;
var _local3:Object = _arg1[_arg2];
try {
if (this._encoding){
_local4 = (_local3 is BitmapData);
} else {
_local4 = (_local3.type == "__bitmap");
};
} catch(error) {
};
var _local5:Object = _local3;
_local6 = (_local3 is ByteArray);
if (_local4){
this._encoderQueue.push({parent:_arg1, property:_arg2});
} else {
if ((((typeof(_local3) == "object")) && (!(_local6)))){
if (this._encoding){
if ((_local3 is Array)){
_local5 = [];
} else {
_local5 = {};
};
for (_local7 in _local3) {
_local5[_local7] = _local3[_local7];
};
_arg1[_arg2] = _local5;
};
for (_local7 in _local5) {
this.preEncodeObject(_local5, _local7);
};
};
};
}
private function encodeObject():void{
var _local5:Object;
if (!this._encoderQueue.length){
if (this._encoding){
this.doSave();
} else {
this._dataLoaded = true;
this.checkLoadComplete();
};
return;
};
var _local1:Object = this._encoderQueue.pop();
var _local2:Object = _local1.parent;
var _local3:String = _local1.property;
var _local4:Object = _local2[_local3];
if (this._encoding){
_local5 = {type:"__bitmap", width:_local4.width, height:_local4.height, transparent:_local4.transparent};
_local2[_local3] = _local5;
_local5.data = new ByteArray();
_local5.data.writeBytes(_local4.getPixels(_local4.rect));
_local5.data.position = 0;
} else {
_local5 = new BitmapData(_local4.width, _local4.height, _local4.transparent);
new BitmapData(_local4.width, _local4.height, _local4.transparent).setPixels(_local5.rect, _local4.data);
_local2[_local3] = _local5;
};
this.encodeObject();
}
private function onIconLoaded(_arg1:APIEvent):void{
if (((!(_arg1.success)) && (this._iconLoader.url))){
Logger.logWarning("Unable to load the icon for this save file.");
};
this._iconLoader.removeEventListener(APIEvent.ICON_LOADED, this.onIconLoaded);
this.checkLoadComplete();
}
private function checkLoadComplete():void{
if (((this._dataLoaded) && (this.iconLoaded))){
Logger.logMessage("Data loaded.");
dispatchEvent(new APIEvent(APIEvent.FILE_LOADED, this));
};
}
private function onDataLoaded(_arg1):void{
var byteArray:ByteArray;
var data = _arg1;
try {
if (data){
byteArray = data;
byteArray.uncompress();
this._data = byteArray.readObject();
this.encodeData(false);
};
} catch(error:Error) {
Logger.logError("Error while loading data:", error);
dispatchEvent(new APIEvent(APIEvent.FILE_LOADED, this, APIEvent.ERROR_BAD_FILE));
};
}
private function onDataError(_arg1:String):void{
Logger.logError("Unable to load data:", _arg1);
dispatchEvent(new APIEvent(APIEvent.FILE_LOADED, this, APIEvent.ERROR_BAD_FILE));
}
private function onSaveComplete(_arg1:APIEvent):void{
if (_arg1.success){
Logger.logMessage((("File \"" + this._name) + "\" saved!"));
if (_arg1.data){
this._id = _arg1.data.save_id;
this._dataURL = unescape(_arg1.data.file_url);
};
dispatchEvent(new APIEvent(APIEvent.FILE_SAVED, this));
} else {
Logger.logError((("Error saving file \"" + this._name) + "\":"), _arg1.error);
dispatchEvent(new APIEvent(APIEvent.FILE_SAVED, this, _arg1.error));
};
}
public function sendVote(_arg1:String, _arg2:Number):void{
var _local3:SaveRating = this._group.getRating(_arg1);
if (!_local3){
Logger.logError((("No save rating named \"" + _arg1) + "\" exists for this save group."));
dispatchEvent(new APIEvent(APIEvent.VOTE_COMPLETE, {}, APIEvent.ERROR_INVALID_ARGUMENT));
return;
};
_arg2 = _local3.validateValue(_arg2);
if (isNaN(_arg2)){
Logger.logError((((((((("Invalid vote (" + _arg2) + "). ") + _arg1) + " allows a range of ") + _local3.minimum) + "-") + _local3.maximum) + "."));
dispatchEvent(new APIEvent(APIEvent.VOTE_COMPLETE, {}, APIEvent.ERROR_INVALID_ARGUMENT));
return;
};
Logger.logMessage((((((("Voting " + _arg2) + " for ") + _arg1) + " on ") + this._name) + "..."));
this._group.connection.sendSimpleCommand("rateSaveFile", this.onVoteComplete, null, {group:this._group.id, save_id:this._id, rating_id:_local3.id, vote:_arg2});
}
private function onVoteComplete(_arg1:APIEvent):void{
var _local3:SaveRating;
var _local2:String = _arg1.error;
if (_arg1.data.already_voted){
Logger.logError("Vote failed. You've already voted on this rating today.");
_local2 = APIEvent.ERROR_ALREADY_VOTED;
};
if (_local2 == APIEvent.ERROR_NONE){
_local3 = this._group.getRatingById(_arg1.data.rating_id);
if (_local3){
this._ratings[_local3.name] = _local3.validateValue(_arg1.data.score);
};
};
dispatchEvent(new APIEvent(APIEvent.VOTE_COMPLETE, this, _local2));
}
public function clone():SaveFile{
var _local2:String;
var _local1:SaveFile = new SaveFile(this._group);
_local1._data = this._data;
_local1._description = this._description;
_local1._draft = this._draft;
_local1._fileSize = this._fileSize;
_local1._iconLoader.bitmapData = this._iconLoader.bitmapData;
for (_local2 in this._keys) {
_local1._keys[_local2] = this._keys[_local2];
};
for (_local2 in this._ratings) {
_local1._ratings[_local2] = this._ratings[_local2];
};
_local1._name = this._name;
return (_local1);
}
public function load():void{
_currentFile = this;
this._dataLoaded = false;
this._data = null;
if (!this.iconLoaded){
this._iconLoader.addEventListener(APIEvent.ICON_LOADED, this.onIconLoaded);
this._iconLoader.load();
};
this._dataLoader = new URLLoader();
this._dataLoader.dataFormat = URLLoaderDataFormat.BINARY;
this._dataLoader.addEventListener(Event.COMPLETE, this.as3DataLoaded);
this._dataLoader.addEventListener(IOErrorEvent.IO_ERROR, this.as3DataError);
this._dataLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.as3DataError);
this._dataLoader.load(new URLRequest(this._dataURL));
}
private function as3DataLoaded(_arg1:Event):void{
this.onDataLoaded(this._dataLoader.data);
}
private function as3DataError(_arg1:Event):void{
this.onDataError(_arg1.toString());
}
private function decodeObject(_arg1:Object):Object{
var _local2:BitmapData;
var _local3:String;
if (getQualifiedClassName(_arg1) == "Object"){
if (_arg1.type == "__bitmap"){
_local2 = new BitmapData(_arg1.width, _arg1.height, _arg1.transparent);
_local2.setPixels(_local2.rect, _arg1.data);
_arg1 = _local2;
} else {
for (_local3 in _arg1) {
_arg1[_local3] = this.decodeObject(_arg1[_local3]);
};
};
};
return (_arg1);
}
public static function get currentFile():SaveFile{
return (_currentFile);
}
static function fromObject(_arg1:SaveGroup, _arg2:Object):SaveFile{
var _local4:Object;
var _local5:Object;
var _local6:SaveKey;
var _local7:SaveRating;
var _local3:SaveFile = new SaveFile(_arg1);
_local3._name = _arg2.filename;
_local3._description = _arg2.description;
_local3._id = _arg2.save_id;
_local3._authorId = _arg2.user_id;
_local3._authorName = _arg2.user_name;
_local3._createdDate = _arg2.created;
_local3._modifiedDate = _arg2.last_update;
_local3._views = _arg2.views;
if (((_arg2.thumb) && (!((_arg2.thumb == ""))))){
_local3._iconLoader.url = (_imageFilePath + _arg2.thumb);
};
_local3._dataURL = (_saveFilePath + _arg2.file);
_local3._fileSize = _arg2.file_size;
_local3._approved = !((_arg2.status == STATUS_UNAPPROVED));
_local3._readOnly = false;
_local3._public = ((!((_arg2.status == STATUS_PRIVATE))) && (!((_arg2.status == STATUS_UNAPPROVED))));
for each (_local4 in _arg2.keys) {
_local6 = _arg1.getKeyById(_local4.id);
if (_local6){
_local3._keys[_local6.name] = _local6.validateValue(_local4.value);
};
};
for each (_local5 in _arg2.ratings) {
_local7 = _arg1.getRatingById(_local5.id);
if (_local7){
_local3._ratings[_local7.name] = _local7.validateValue(_local5.score);
};
};
return (_local3);
}
}
}//package com.newgrounds
Section 27
//SaveGroup (com.newgrounds.SaveGroup)
package com.newgrounds {
public class SaveGroup {
private var _connection:APIConnection;
private var _name:String;
private var _id:uint;
private var _type:uint;
private var _keysArray:Array;
private var _ratingsArray:Array;
private var _keys:Object;
private var _ratings:Object;
public static const TYPE_SYSTEM:uint = 0;
public static const TYPE_PRIVATE:uint = 1;
public static const TYPE_PUBLIC:uint = 2;
public static const TYPE_MODERATED:uint = 3;
public function SaveGroup(_arg1:APIConnection, _arg2:String, _arg3:uint, _arg4:uint, _arg5:Array, _arg6:Array){
var _local7:uint;
var _local8:SaveKey;
var _local9:SaveRating;
super();
this._connection = _arg1;
this._id = _arg3;
this._name = _arg2;
this._type = _arg4;
this._keysArray = _arg5;
this._ratingsArray = _arg6;
this._keys = new Object();
this._ratings = new Object();
for each (_local8 in _arg5) {
this._keys[_local8.name] = _local8;
};
for each (_local9 in _arg6) {
this._ratings[_local9.name] = _local9;
};
}
public function get connection():APIConnection{
return (this._connection);
}
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 get keys():Array{
return (this._keysArray);
}
public function get ratings():Array{
return (this._ratingsArray);
}
public function getKey(_arg1:String):SaveKey{
return (this._keys[_arg1]);
}
public function getRating(_arg1:String):SaveRating{
return (this._ratings[_arg1]);
}
public function getKeyById(_arg1:uint):SaveKey{
var _local2:SaveKey;
for each (_local2 in this._keys) {
if (_local2.id == _arg1){
return (_local2);
};
};
return (null);
}
public function getRatingById(_arg1:uint):SaveRating{
var _local2:SaveRating;
for each (_local2 in this._ratings) {
if (_local2.id == _arg1){
return (_local2);
};
};
return (null);
}
public function toString():String{
return (((((("SaveGroup: " + this.name) + " Keys: ") + this._keysArray) + " Ratings: ") + this._ratingsArray));
}
}
}//package com.newgrounds
Section 28
//SaveKey (com.newgrounds.SaveKey)
package com.newgrounds {
public class SaveKey {
private var _name:String;
private var _id:uint;
private var _type:uint;
public static const TYPE_FLOAT:uint = 1;
public static const TYPE_INTEGER:uint = 2;
public static const TYPE_STRING:uint = 3;
public static const TYPE_BOOLEAN:uint = 4;
public function SaveKey(_arg1:String, _arg2:uint, _arg3:uint){
this._name = _arg1;
this._id = _arg2;
this._type = _arg3;
}
public function get name():String{
return (this._name);
}
public function get id():uint{
return (this._id);
}
public function get type():uint{
return (this._type);
}
public function validateValue(_arg1){
var _local2:int;
switch (this._type){
case TYPE_INTEGER:
_arg1 = Number(_arg1);
if (!isNaN(_arg1)){
_local2 = int(_arg1);
if (_local2 != _arg1){
Logger.logWarning((((((("Float value " + _arg1) + " given for integer key \"") + this._name) + "\". Clamping to ") + _local2) + "."));
};
return (_local2);
};
break;
case TYPE_FLOAT:
_arg1 = Number(_arg1);
if (!isNaN(_arg1)){
return (isNaN(Number(_arg1)));
};
break;
case TYPE_BOOLEAN:
return (Boolean(_arg1));
case TYPE_STRING:
return ((_arg1) ? _arg1.toString() : "");
};
return (null);
}
public function toString():String{
return (this._name);
}
}
}//package com.newgrounds
Section 29
//SaveQuery (com.newgrounds.SaveQuery)
package com.newgrounds {
public class SaveQuery extends APIEventDispatcher {
private var _connection:APIConnection;
private var _group:SaveGroup;
private var _page:uint;// = 1
private var _resultsPerPage:uint;// = 10
private var _isRandomized:Boolean;// = false
private var _files:Array;
private var _totalResults:uint;
private var _lookupKeys:Array;
private var _lookupRatings:Array;
private var _fileConditions:Array;
private var _keyConditions:Array;
private var _ratingConditions:Array;
private var _sortFields:Array;
public static const FILE_ID:String = "fileId";
public static const AUTHOR_ID:String = "authorId";
public static const AUTHOR_NAME:String = "authorName";
public static const FILE_NAME:String = "fileName";
public static const CREATED_ON:String = "createdOn";
public static const UPDATED_ON:String = "updatedOn";
public static const FILE_VIEWS:String = "fileViews";
public static const FILE_STATUS:String = "fileStatus";
private static const FILE_FIELDS:Array = [FILE_ID, AUTHOR_ID, AUTHOR_NAME, FILE_NAME, CREATED_ON, UPDATED_ON, FILE_VIEWS, FILE_STATUS];
public static const OPERATOR_EQUAL:String = "=";
public static const OPERATOR_LESS_THAN:String = "<";
public static const OPERATOR_GREATER_THAN:String = ">";
public static const OPERATOR_NOT_EQUAL:String = "!=";
public static const OPERATOR_LESS_OR_EQUAL:String = "<=";
public static const OPERATOR_GREATER_OR_EQUAL:String = ">=";
public static const OPERATOR_CONTAINS:String = "*";
public static const OPERATOR_NOT_CONTAINS:String = "!*";
public static const OPERATOR_NOT_BEGINS_WITH:String = "!*=";
public static const OPERATOR_NOT_ENDS_WITH:String = "!=*";
public static const OPERATOR_BEGINS_WITH:String = "*=";
public static const OPERATOR_ENDS_WITH:String = "=*";
private static const TABLE_FILES:uint = 1;
private static const TABLE_KEYS:uint = 2;
private static const TABLE_RATINGS:uint = 3;
public function SaveQuery(_arg1:SaveGroup){
this._files = [];
this._lookupKeys = [];
this._lookupRatings = [];
this._fileConditions = [];
this._keyConditions = [];
this._ratingConditions = [];
this._sortFields = [];
super();
this._group = _arg1;
this._connection = _arg1.connection;
this.includeAllFields();
}
public function get group():SaveGroup{
return (this._group);
}
public function get resultsPerPage():uint{
return (this._resultsPerPage);
}
public function set resultsPerPage(_arg1:uint):void{
this._resultsPerPage = Math.min(Math.max(_arg1, 1), 100);
}
public function get page():uint{
return (this._page);
}
public function set page(_arg1:uint):void{
this._page = Math.max(_arg1, 1);
}
public function prevPage():void{
this.page--;
}
public function nextPage():void{
this.page++;
}
public function get isRandomized():Boolean{
return (this._isRandomized);
}
public function set isRandomized(_arg1:Boolean):void{
this._isRandomized = _arg1;
}
public function get files():Array{
return (this._files);
}
public function reset():void{
this._page = 1;
this._resultsPerPage = 10;
this._isRandomized = false;
this._lookupKeys = [];
this._lookupRatings = [];
this._fileConditions = [];
this._keyConditions = [];
this._ratingConditions = [];
this._files = [];
this.includeAllFields();
}
public function clone():SaveQuery{
var _local1:SaveQuery = new SaveQuery(this._group);
_local1._page = this._page;
_local1._resultsPerPage = this._resultsPerPage;
_local1._isRandomized = this._isRandomized;
_local1._lookupKeys = this._lookupKeys.concat();
_local1._lookupRatings = this._lookupRatings.concat();
_local1._fileConditions = this._fileConditions.concat();
_local1._keyConditions = this._keyConditions.concat();
_local1._ratingConditions = this._ratingConditions.concat();
return (_local1);
}
private function includeAllFields():void{
var _local1:SaveKey;
var _local2:SaveRating;
for each (_local1 in this._group.keys) {
this._lookupKeys.push(_local1.id);
};
for each (_local2 in this._group.ratings) {
this._lookupRatings.push(_local2.id);
};
}
public function addCondition(_arg1:String, _arg2:String, _arg3):void{
var _local4:int;
var _local5:SaveKey;
var _local6:Array;
var _local7:SaveRating;
_local4 = FILE_FIELDS.indexOf(_arg1);
if (_local4 >= 0){
this._fileConditions.push({field:_local4, operator:_arg2, value:_arg3});
} else {
_local5 = this._group.getKey(_arg1);
if (_local5){
_arg3 = _local5.validateValue(_arg3);
this._keyConditions.push({key_id:_local5.id, operator:_arg2, value:_arg3});
return;
};
_local6 = _arg1.split(".");
_local7 = this._group.getRating(_local6[0]);
if (_local7){
_arg3 = _local7.validateValue(_arg3);
this._ratingConditions.push({rating_id:_local7.id, operator:_arg2, value:_arg3, column:(_local6[1]) ? _local6[1] : "score"});
return;
};
Logger.logError((((("The save group \"" + this._group.name) + "\" does not have a field named \"") + _arg1) + "\"."));
};
}
public function sortOn(_arg1:String, _arg2:Boolean=false):void{
var _local3:int;
var _local4:SaveKey;
var _local5:Array;
var _local6:SaveRating;
_local3 = FILE_FIELDS.indexOf(_arg1);
if (_local3 >= 0){
this._sortFields.push({table:TABLE_FILES, field:_local3, desc:_arg2});
} else {
_local4 = this._group.getKey(_arg1);
if (_local4){
this._sortFields.push({table:TABLE_KEYS, field:_local4.id, desc:_arg2});
return;
};
_local5 = _arg1.split(".");
_local6 = this._group.getRating(_local5[0]);
if (_local6){
this._sortFields.push({table:TABLE_RATINGS, field:_local6.id, desc:_arg2, extra:(_local5[1]) ? _local5[1] : "score"});
return;
};
Logger.logError((((("The save group \"" + this._group.name) + "\" does not have a field named \"") + _arg1) + "\"."));
};
}
public function execute():void{
var _local1:Object = {};
_local1.page = this._page;
_local1.num_results = this._resultsPerPage;
if (this._isRandomized){
_local1.randomize = 1;
};
if (((this._lookupKeys) && (this._lookupKeys.length))){
_local1.lookup_keys = this._lookupKeys;
};
if (((this._lookupRatings) && (this._lookupRatings.length))){
_local1.lookup_ratings = this._lookupRatings;
};
if (((this._fileConditions) && (this._fileConditions.length))){
_local1.file_conditions = this._fileConditions;
};
if (((this._keyConditions) && (this._keyConditions.length))){
_local1.key_conditions = this._keyConditions;
};
if (((this._ratingConditions) && (this._ratingConditions.length))){
_local1.rating_conditions = this._ratingConditions;
};
if (((this._sortFields) && (this._sortFields.length))){
_local1.sort_conditions = this._sortFields;
};
this._connection.sendSimpleCommand("lookupSaveFiles", this.onQueryComplete, {publisher_id:this._connection.publisherId, group_id:this._group.id, query:_local1});
}
private function onQueryComplete(_arg1:APIEvent):void{
var _local2:Object;
var _local3:uint;
var _local4:SaveFile;
if (_arg1.success){
_local2 = _arg1.data;
this._files = [];
if (_local2.files){
_local3 = 0;
while (_local3 < _local2.files.length) {
_local4 = SaveFile.fromObject(this._group, _local2.files[_local3]);
if (_local4){
this._files.push(_local4);
};
_local3++;
};
};
dispatchEvent(new APIEvent(APIEvent.QUERY_COMPLETE, this));
} else {
Logger.logError(("Query failed: " + _arg1.error));
dispatchEvent(new APIEvent(APIEvent.QUERY_COMPLETE, this, _arg1.error));
};
}
}
}//package com.newgrounds
Section 30
//SaveRating (com.newgrounds.SaveRating)
package com.newgrounds {
public class SaveRating {
private var _name:String;
private var _id:uint;
private var _isFloat:Boolean;
private var _minimum:Number;
private var _maximum:Number;
public function SaveRating(_arg1:String, _arg2:uint, _arg3:Boolean, _arg4:Number, _arg5:Number){
this._name = _arg1;
this._id = _arg2;
this._isFloat = _arg3;
this._minimum = _arg4;
this._maximum = _arg5;
}
public function get name():String{
return (this._name);
}
public function get id():uint{
return (this._id);
}
public function get isFloat():Boolean{
return (this._isFloat);
}
public function get minimum():Number{
return (this._minimum);
}
public function get maximum():Number{
return (this._maximum);
}
public function validateValue(_arg1):Number{
var _local3:int;
var _local2:Number = Number(_arg1);
if (isNaN(_local2)){
Logger.logError((("Invalid value for rating \"" + this._name) + "\"."));
return (NaN);
};
if (_local2 < this._minimum){
Logger.logWarning((((((_local2 + " is out of acceptable range for rating \"") + this._name) + "\". Clamping to ") + this._minimum) + "."));
return (this._minimum);
};
if (_local2 > this._maximum){
Logger.logWarning((((((_local2 + " is out of acceptable range for rating \"") + this._name) + "\". Clamping to ") + this._maximum) + "."));
return (this._maximum);
};
if (!this.isFloat){
_local3 = int(_local2);
if (_local3 != _local2){
Logger.logWarning((((((("Float value " + _local2) + " given for integer rating \"") + this._name) + "\". Clamping to ") + _local3) + "."));
};
return (_local3);
};
return (_local2);
}
public function toString():String{
return (this._name);
}
}
}//package com.newgrounds
Section 31
//Score (com.newgrounds.Score)
package com.newgrounds {
public class Score {
private var _numericValue:Number;
private var _rank:uint;
private var _username:String;
private var _score:String;
private var _tag:String;
public function Score(_arg1:uint, _arg2:String, _arg3:String, _arg4:Number, _arg5:String){
this._rank = _arg1;
this._username = _arg2;
this._score = _arg3;
this._numericValue = _arg4;
this._tag = _arg5;
}
public function get numericValue():Number{
return (this._numericValue);
}
public function get rank():uint{
return (this._rank);
}
public function get score():String{
return (this._score);
}
public function get tag():String{
return (this._tag);
}
public function get username():String{
return (this._username);
}
public function toString():String{
return (((((this._rank + ".\t") + this._username) + "\t") + this._score));
}
}
}//package com.newgrounds
Section 32
//ScoreBoard (com.newgrounds.ScoreBoard)
package com.newgrounds {
public class ScoreBoard extends APIEventDispatcher {
private var _connection:APIConnection;
private var _name:String;
private var _id:uint;
private var _period:String;// = "All-Time"
private var _firstResult:uint;// = 1
private var _numResults:uint;// = 10
private var _tag:String;
private var _scores:Array;
public static const TODAY:String = "Today";
public static const THIS_WEEK:String = "This Week";
public static const THIS_MONTH:String = "This Month";
public static const THIS_YEAR:String = "This Year";
public static const ALL_TIME:String = "All-Time";
public function ScoreBoard(_arg1:APIConnection, _arg2:String, _arg3:uint){
this._connection = _arg1;
this._name = _arg2;
this._id = _arg3;
}
public function get name():String{
return (this._name);
}
public function get scores():Array{
return (this._scores);
}
public function get period():String{
return (this._period);
}
public function set period(_arg1:String):void{
this._period = _arg1;
}
public function get firstResult():uint{
return (this._firstResult);
}
public function set firstResult(_arg1:uint):void{
this._firstResult = Math.max(1, _arg1);
}
public function get numResults():uint{
return (this._numResults);
}
public function set numResults(_arg1:uint):void{
this._numResults = _arg1;
}
public function get tag():String{
return (this._tag);
}
public function set tag(_arg1:String):void{
this._tag = _arg1;
}
public function get page():uint{
return ((Math.ceil(((this._firstResult - 1) / this._numResults)) + 1));
}
public function prevPage():void{
if (this.firstResult > this._numResults){
this.firstResult = (this.firstResult - this._numResults);
};
}
public function nextPage():void{
this.firstResult = (this.firstResult + this._numResults);
}
public function loadScores():void{
this._connection.sendSimpleCommand("loadScores", this.onScoresLoaded, {publisher_id:this._connection.publisherId, board:this._id, page:(((this._firstResult - 1) / this._numResults) + 1), num_results:this._numResults, period:this._period, tag:this._tag});
}
public function postScore(_arg1:Number, _arg2:String=null):void{
if (isNaN(_arg1)){
Logger.logError(("Cannot post invalid score: " + _arg1));
dispatchEvent(new APIEvent(APIEvent.SCORE_POSTED, null, APIEvent.ERROR_INVALID_ARGUMENT));
return;
};
Logger.logMessage((((((("Posting a score of " + _arg1) + " by ") + this._connection.username) + " to scoreboard \"") + this._name) + "\"..."));
this._connection.sendSimpleCommand("postScore", this.onScorePosted, null, {user_name:this._connection.username, board:this._id, value:_arg1, tag:_arg2});
}
private function onScoresLoaded(_arg1:APIEvent):void{
var _local3:uint;
var _local4:uint;
var _local5:Object;
var _local2:Object = _arg1.data;
this._scores = [];
if (_local2.first_result){
_local3 = _local2.first_result;
} else {
_local3 = this._firstResult;
};
if (_local2.scores){
_local4 = 0;
while (_local4 < _local2.scores.length) {
_local5 = _local2.scores[_local4];
if (_local5){
this._scores[_local4] = new Score(_local3, _local5.username, _local5.value, _local5.numeric_value, _local5.tag);
};
_local4++;
_local3++;
};
};
dispatchEvent(new APIEvent(APIEvent.SCORES_LOADED, this));
}
private function onScorePosted(_arg1:APIEvent):void{
var _local2:Object;
var _local3:Object;
if (_arg1.success){
Logger.logMessage("Score posted!");
_local2 = _arg1.data;
_local3 = {};
_local3.score = _local2.value;
_local3.scoreBoard = this;
} else {
Logger.logError(("Error posting score: " + _arg1.error));
};
dispatchEvent(new APIEvent(APIEvent.SCORE_POSTED, _local3, _arg1.error));
}
override public function toString():String{
return (("Scoreboard: " + this._name));
}
}
}//package com.newgrounds