Section 1
//distribution (distribution)
package {
import flash.events.*;
import flash.net.*;
import flash.display.*;
import flash.system.*;
import flash.utils.*;
public class distribution extends MovieClip {
private var ERROR_REPORT_URL:String;// = "http://swf.come2play.com/error/"
private var callerId:int;// = 6817
private var imageLoader:Loader;
private var allTraces:Array;
private var loader:URLLoader;
private var DISTRIBUTION_URL:String;// = "http://swf.come2play.com/"
private var errorMessage:ErrorMessage;
private var newUrlLoader:URLLoader;
private var callerURL:String;
private var recivedData:Object;
private var containerLoader:Loader;
private var didReportError:Boolean;// = false
private var tracePrefix:String;
private var retryNum:int;// = 1
private var VERSION:String;// = "1.0.0"
public function distribution(){
errorMessage = new ErrorMessage();
allTraces = [];
tracePrefix = (("Distribution SWF " + int((10000 * Math.random()))) + ": ");
super();
catchErrors("constructor", constructDistribution, []);
}
private function reportError():void{
if (didReportError){
return;
};
didReportError = true;
var errMessage:String = getTraces();
appendToErrorBox(errMessage);
var vars:URLVariables = new URLVariables();
vars["errMessage"] = "DistributionSwf error";
vars["url"] = callerURL;
vars["traces"] = errMessage;
vars["bug_id"] = int((Math.random() * 10000000));
loadASP(ERROR_REPORT_URL, vars, eventFailed);
}
private function appendToErrorBox(txt:String):void{
addErrorBox(txt);
}
private function retryFailedLoad(ev:Event, completeFunc:Function, request:URLRequest):void{
var failFunc:Function;
var dispatcher:IEventDispatcher;
var reteyTarget:String;
var oldUrlLoader:URLLoader;
var ev = ev;
var completeFunc = completeFunc;
var request = request;
traceEventError(ev);
if ((ev.target is URLLoader)){
imageLoader = null;
reteyTarget = "URL";
oldUrlLoader = (ev.target as URLLoader);
newUrlLoader = new URLLoader();
newUrlLoader.dataFormat = oldUrlLoader.dataFormat;
dispatcher = newUrlLoader;
} else {
if ((ev.target is LoaderInfo)){
newUrlLoader = null;
reteyTarget = "Image";
imageLoader = new Loader();
dispatcher = imageLoader.contentLoaderInfo;
};
};
myTrace("retry Number ", retryNum++, "Loading ", reteyTarget);
if (retryNum > 3){
retryNum = 1;
failFunc = eventFailed;
} else {
failFunc = function (ev:Event):void{
retryFailedLoad(ev, completeFunc, request);
};
};
addListeners(dispatcher, completeFunc, failFunc);
if (imageLoader != null){
imageLoader.load(request);
} else {
if (newUrlLoader != null){
newUrlLoader.load(request);
};
};
}
private function catchErrors(zoneName:String, func:Function, args:Array):void{
var zoneName = zoneName;
var func = func;
var args = args;
func.apply(null, args);
//unresolved jump
var _slot1 = e;
myTrace("Exception thrown in ", zoneName, " err=", error2String(_slot1));
reportError();
}
private function varsLoaded(ev:Event):void{
var urlRequest:URLRequest;
var urlVariables:URLVariables;
var obj:Object;
var params:Array;
var ev = ev;
retryNum = 1;
if (ev != null){
urlVariables = new URLVariables(ev.target.data);
obj = urlVariables.valueOf();
params = copyObject(obj, recivedData);
myTrace("Received params from ASP, params=", params);
};
var swf_url:String = recivedData["preloader_url"];
myTrace("Started loading framework from url=", swf_url);
containerLoader = new Loader();
var loaderInfo:LoaderInfo = containerLoader.contentLoaderInfo;
urlRequest = new URLRequest(swf_url);
addListeners(loaderInfo, containerLoaded, function (ev:Event):void{
retryFailedLoad(ev, containerLoaded, urlRequest);
});
containerLoader.load(urlRequest);
}
private function eventFailed(ev:Event):void{
traceEventError(ev);
reportError();
}
private function addListeners(dispatcher:IEventDispatcher, completeFunc:Function, errorFunction:Function):void{
myAddEventListener(dispatcher, Event.COMPLETE, completeFunc);
myAddEventListener(dispatcher, IOErrorEvent.IO_ERROR, errorFunction);
myAddEventListener(dispatcher, SecurityErrorEvent.SECURITY_ERROR, errorFunction);
}
private function myAddEventListener(dispatcher:IEventDispatcher, type:String, listener:Function):void{
dispatcher.addEventListener(type, wrapWithCatch(("EventListener=" + type), listener));
}
private function copyObject(src:Object, target:Object):Array{
var k:String;
var data:String;
var res:Array = [];
for (k in src) {
data = src[k];
trace(((k + " : ") + data));
res.push(["key=", k, " value=", data]);
target[k] = data;
};
return (res);
}
public function addErrorBox(text:String):void{
errorMessage.addText(text);
}
private function containerLoaded(ev:Event):void{
var loadedSwf:Object;
retryNum = 1;
myTrace("Finished loading framework, event=", ev);
var loaderInfo:LoaderInfo = (ev.target as LoaderInfo);
addChild(loaderInfo.content);
if (recivedData["do_not_passParameters"] == null){
recivedData["IGNORE_ALL_TRACES"] = getTraces();
loadedSwf = loaderInfo.content;
loadedSwf.passParameters(recivedData);
};
}
private function getTraces():String{
return (allTraces.join());
}
private function wrapWithCatch(zoneName:String, func:Function):Function{
var zoneName = zoneName;
var func = func;
return (function (... _args):void{
catchErrors(zoneName, func, _args);
});
}
private function loadASP(url:String, vars:URLVariables, completeFunc:Function):void{
var request:URLRequest;
var url = url;
var vars = vars;
var completeFunc = completeFunc;
myTrace("calling ASP with params, with url=", url, " and variables=", vars.toString());
request = new URLRequest(url);
request.data = vars;
request.method = URLRequestMethod.POST;
loader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
addListeners(loader, completeFunc, function (ev:Event):void{
retryFailedLoad(ev, completeFunc, request);
});
loader.load(request);
}
private function myTrace(... _args):void{
var traceLine = (((("Time " + getTimer()) + ":") + _args) + "\n");
allTraces.push(traceLine);
trace((tracePrefix + traceLine));
if (didReportError){
appendToErrorBox(traceLine);
};
}
private function traceEventError(ev:Event):void{
myTrace("eventFailed :", ev, (((((!((ev == null))) && (!((ev.target == null))))) && (ev.target.hasOwnProperty("data")))) ? ev.target.data : "no ev.target.data");
}
public function constructDistribution():void{
addChild(errorMessage);
Security.allowDomain("*");
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.stageFocusRect = false;
recivedData = root.loaderInfo.parameters;
if (recivedData == null){
recivedData = new Object();
};
callerURL = stage.loaderInfo.url;
var vars:URLVariables = new URLVariables();
var params:Array = copyObject(recivedData, vars);
myTrace("myUrl=", callerURL, "Recieved params from root=", params);
vars["callerId"] = callerId;
vars["callerURL"] = callerURL;
vars["swfWidth"] = ("" + stage.stageWidth);
vars["swfHeight"] = ("" + stage.stageHeight);
vars["distributionVersion"] = VERSION;
vars["flashVersion"] = Capabilities.version;
vars["flashServerString"] = Capabilities.serverString;
vars["flashTime"] = new Date().toString();
vars["doNotCache"] = int((Math.random() * int.MAX_VALUE));
vars["isDebugger"] = !((new Error().getStackTrace() == null));
if (recivedData["preloader_url"] != null){
varsLoaded(null);
} else {
loadASP(DISTRIBUTION_URL, vars, varsLoaded);
};
}
private function error2String(err:Error):String{
return (((err == null)) ? "null" : ((((((err.name + " message=") + err.message) + " errorID=") + err.errorID) + " stacktraces=") + err.getStackTrace()));
}
}
}//package
Section 2
//ErrorMessage (ErrorMessage)
package {
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.display.*;
public class ErrorMessage extends Sprite {
private var explanationField:TextField;
private var errorReportText:String;
private var textField:TextField;
public function ErrorMessage(){
super();
}
private function sendErrorReport(ev:MouseEvent):void{
var mailData:URLVariables = new URLVariables();
mailData["subject"] = "An Error in the distribution file";
mailData["body"] = errorReportText;
navigateToURL(new URLRequest(("mailto:support@come2play.com&" + mailData.toString())));
}
public function get text():String{
return (textField.text);
}
public function addText(text:String):void{
var btn:FakeButton;
if (textField == null){
textField = new TextField();
textField.width = (stage.stageWidth - 15);
textField.height = ((stage.stageHeight > 300)) ? 200 : 100;
textField.wordWrap = true;
textField.x = 10;
textField.y = 45;
textField.border = true;
textField.text = text;
explanationField = new TextField();
explanationField.width = (stage.stageWidth - 30);
explanationField.height = 40;
explanationField.wordWrap = true;
explanationField.x = (explanationField.y = 5);
explanationField.text = "An error occurred while loading the game. please press the button below to send an error report";
explanationField.setTextFormat(new TextFormat("Tahoma", 18));
graphics.beginFill(16054764);
graphics.lineStyle(2, 13314149);
graphics.drawRoundRect(5, 5, (stage.stageWidth - 5), (stage.stageHeight - 5), 3, 3);
graphics.endFill();
btn = FakeButton.getPositive("Send Report");
btn.x = (stage.stageWidth - 150);
btn.y = (stage.stageHeight - 40);
btn.addEventListener(MouseEvent.CLICK, sendErrorReport);
addChild(btn);
addChild(textField);
addChild(explanationField);
} else {
textField.appendText(text);
};
errorReportText = textField.text;
textField.setTextFormat(new TextFormat("Tahoma", 12, 0));
}
}
}//package
Section 3
//FakeButton (FakeButton)
package {
import flash.text.*;
import flash.display.*;
import flash.geom.*;
public class FakeButton extends MovieClip {
private var simpleButton:SimpleButton;
private var isDisabled:Boolean;
private var buttonPic:MovieClip;
private var captionTextFormat:TextFormat;
private var widthMod:int;// = 0
private var caption:TextField;
private var fakeHeight:int;// = 100
private var disabledPic:Sprite;
private var color2:uint;
private var fakeWidth:int;// = 100
private var color1:uint;
public function FakeButton(color1:uint, color2:uint, captionText:String, captionTextFormat:TextFormat=null, buttonPic:MovieClip=null, width:int=0, height:int=0){
super();
this.buttonPic = buttonPic;
this.color1 = color1;
this.color2 = color2;
caption = new TextField();
caption.autoSize = TextFieldAutoSize.CENTER;
caption.selectable = false;
caption.mouseEnabled = false;
if (captionTextFormat == null){
this.captionTextFormat = new TextFormat("Tahoma", 12, 0xFFFFFF, true, null, null, null, null, TextFieldAutoSize.CENTER);
} else {
this.captionTextFormat = captionTextFormat;
};
text = captionText;
if (buttonPic != null){
buttonHeight = ((height)==0) ? (caption.height + 5) : height;
buttonWidth = ((width)==0) ? ((caption.width + 12) + buttonPic.width) : width;
} else {
buttonHeight = ((height)==0) ? (caption.height + 3) : height;
buttonWidth = ((width)==0) ? (caption.width + 10) : width;
};
simpleButton = new SimpleButton(getUpState(), getDownState(), getOverState(), getDisabledState());
disabledPic = getDisabledState();
layerButton(simpleButton);
}
private function getUpState():Sprite{
var res:Sprite = new Sprite();
var colorScreen = 220;
var buttonMatrix:Matrix = new Matrix();
buttonMatrix.createGradientBox(fakeWidth, (fakeHeight - 5), (Math.PI / 2), 0, 0);
res.graphics.beginGradientFill(GradientType.LINEAR, [color1, color2], [1, 1], [0, colorScreen], buttonMatrix, SpreadMethod.PAD, InterpolationMethod.RGB);
res.graphics.drawRoundRect(0, 0, fakeWidth, fakeHeight, 7, 7);
res.graphics.endFill();
return (res);
}
private function updateWidthMod():void{
if (buttonPic != null){
widthMod = (buttonPic.width + (buttonPic.x * 2));
};
}
private function getDisabledState():Sprite{
var res:Sprite = new Sprite();
var colorScreen = 0xFF;
var buttonMatrix:Matrix = new Matrix();
buttonMatrix.createGradientBox(fakeWidth, (fakeHeight + 5), (Math.PI / 2), 0, 0);
res.graphics.beginGradientFill(GradientType.LINEAR, [0xCCCCCC, 0x666666], [1, 1], [0, colorScreen], buttonMatrix, SpreadMethod.PAD, InterpolationMethod.RGB);
res.graphics.drawRoundRect(0, 0, fakeWidth, fakeHeight, 7, 7);
res.graphics.endFill();
return (res);
}
public function get disabledButton():Boolean{
return (isDisabled);
}
private function getDownState():Sprite{
var res:Sprite = new Sprite();
var colorScreen = 160;
var buttonMatrix:Matrix = new Matrix();
buttonMatrix.createGradientBox(fakeWidth, (fakeHeight - 5), (Math.PI / 2), 0, 0);
res.graphics.beginGradientFill(GradientType.LINEAR, [color1, color2], [1, 1], [0, colorScreen], buttonMatrix, SpreadMethod.PAD, InterpolationMethod.RGB);
res.graphics.drawRoundRect(0, 0, fakeWidth, fakeHeight, 7, 7);
res.graphics.endFill();
return (res);
}
public function set text(newText:String):void{
caption.text = newText;
caption.setTextFormat(captionTextFormat);
caption.y = ((fakeHeight - (caption.textHeight + 5)) / 2);
}
private function getOverState():Sprite{
var res:Sprite = new Sprite();
var colorScreen = 0xFF;
var buttonMatrix:Matrix = new Matrix();
buttonMatrix.createGradientBox(fakeWidth, (fakeHeight + 5), (Math.PI / 2), 0, 0);
res.graphics.beginGradientFill(GradientType.LINEAR, [color1, color2], [1, 1], [0, colorScreen], buttonMatrix, SpreadMethod.PAD, InterpolationMethod.RGB);
res.graphics.drawRoundRect(0, 0, fakeWidth, fakeHeight, 7, 7);
res.graphics.endFill();
return (res);
}
public function set buttonWidth(newWidth:Number):void{
updateWidthMod();
fakeWidth = newWidth;
if (buttonPic != null){
caption.x = widthMod;
} else {
caption.x = ((newWidth - caption.width) / 2);
};
}
private function layerButton(but:DisplayObject):void{
addChild(but);
addChild(caption);
if (buttonPic != null){
addChild(buttonPic);
};
}
public function get text():String{
return (caption.text);
}
public function set buttonHeight(newHeight:Number):void{
updateWidthMod();
fakeHeight = newHeight;
if (buttonPic != null){
buttonPic.x = (buttonPic.y = (newHeight * 0.2));
buttonPic.height = (newHeight * 0.5);
buttonPic.scaleX = buttonPic.scaleY;
};
caption.y = ((newHeight - (caption.textHeight + 5)) / 2);
}
public function get buttonHeight():Number{
return (simpleButton.height);
}
public function get buttonWidth():Number{
return (simpleButton.width);
}
public function set disabledButton(disabled:Boolean):void{
isDisabled = disabled;
if (isDisabled){
layerButton(disabledPic);
simpleButton.enabled = false;
mouseChildren = false;
mouseEnabled = false;
} else {
layerButton(simpleButton);
simpleButton.enabled = true;
mouseChildren = true;
mouseEnabled = true;
};
}
public static function getNegative(text:String, textFormat:TextFormat=null, buttonPic:MovieClip=null, _width:int=0, _height:int=0):FakeButton{
return (new FakeButton(14033767, 11607381, text, textFormat, buttonPic, _width, _height));
}
public static function getPositive(text:String, textFormat:TextFormat=null, buttonPic:MovieClip=null, _width:int=0, _height:int=0):FakeButton{
return (new FakeButton(10339905, 4879905, text, textFormat, buttonPic, _width, _height));
}
}
}//package