Section 1
//MochiAd (mochi.as3.MochiAd)
package mochi.as3 {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
public class MochiAd {
public function MochiAd(){
super();
}
public static function getVersion():String{
return (MochiServices.getVersion());
}
public static function showClickAwayAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:2000, regpt:"o", method:"showClickAwayAd", res:"300x250", no_bg:true, ad_started:function ():void{
}, ad_finished:function ():void{
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
clip = options.clip;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
options.ad_finished();
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
mc.unloadAd = function ():void{
MochiAd.unload(clip);
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
var sendHostProgress:Boolean;
mc.regContLC = function (lc_name:String):void{
mc._containerLCName = lc_name;
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (!this.parent){
delete this.onEnterFrame;
return;
};
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
finished = true;
chk.started = getTimer();
} else {
if (elapsed > chk.ad_timeout){
options.ad_failed();
finished = true;
};
};
};
if (this.root == null){
finished = true;
};
if (finished){
delete this.onEnterFrame;
};
};
doOnEnterFrame(chk);
}
public static function _isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
public static function _allowDomains(server:String):String{
var hostname:String = server.split("/")[2].split(":")[0];
if (Security.sandboxType == "application"){
return (hostname);
};
Security.allowDomain("*");
Security.allowDomain(hostname);
Security.allowInsecureDomain("*");
Security.allowInsecureDomain(hostname);
return (hostname);
}
public static function unload(clip:Object):Boolean{
if (((clip.clip) && (clip.clip._mochiad))){
clip = clip.clip;
};
if (clip.origFrameRate != undefined){
clip.stage.frameRate = clip.origFrameRate;
};
if (!clip._mochiad){
return (false);
};
if (clip._mochiad._containerLCName != undefined){
clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"unload"});
};
if (clip._mochiad.onUnload){
clip._mochiad.onUnload();
};
delete clip._mochiad_loaded;
delete clip._mochiad;
return (true);
}
public static function showInterLevelAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:2000, fadeout_time:250, regpt:"o", method:"showTimedAd", ad_started:function ():void{
if ((this.clip is MovieClip)){
this.clip.stop();
} else {
throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_finished:function ():void{
if ((this.clip is MovieClip)){
this.clip.play();
} else {
throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
clip = options.clip;
var ad_msec:Number = 11000;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time:Number = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
options.ad_finished();
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.ad_msec = ad_msec;
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function ():void{
if (!this.parent){
delete this.onEnterFrame;
delete this.fadeFunction;
return;
};
var p:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time)));
if (p > 0){
this.parent.alpha = (p * 0.01);
} else {
MochiAd.unload(clip);
delete this["onEnterFrame"];
};
};
mc.unloadAd = function ():void{
MochiAd.unload(clip);
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.adjustProgress = function (msec:Number):void{
var _chk:Object = mc._mochiad_wait;
_chk.server_control = true;
_chk.showing = true;
_chk.started = getTimer();
_chk.ad_msec = (msec - 250);
};
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (!this.parent){
delete this.onEnterFrame;
delete this.fadeFunction;
return;
};
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
chk.started = getTimer();
MochiAd.adShowing(clip);
} else {
if (elapsed > chk.ad_timeout){
options.ad_failed();
finished = true;
};
};
};
if (elapsed > chk.ad_msec){
finished = true;
};
if (finished){
if (this.server_control){
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = this.fadeFunction;
};
};
};
doOnEnterFrame(chk);
}
public static function _parseOptions(options:Object, defaults:Object):Object{
var k:String;
var pairs:Array;
var i:Number;
var kv:Array;
var optcopy:Object = {};
for (k in defaults) {
optcopy[k] = defaults[k];
};
if (options){
for (k in options) {
optcopy[k] = options[k];
};
};
if (optcopy.clip == undefined){
throw (new Error("MochiAd is missing the 'clip' parameter. This should be a MovieClip, Sprite or an instance of a class that extends MovieClip or Sprite."));
};
options = optcopy.clip.loaderInfo.parameters.mochiad_options;
if (options){
pairs = options.split("&");
i = 0;
while (i < pairs.length) {
kv = pairs[i].split("=");
optcopy[unescape(kv[0])] = unescape(kv[1]);
i++;
};
};
if (optcopy.id == "test"){
trace("[MochiAd] WARNING: Using the MochiAds test identifier, make sure to use the code from your dashboard, not this example!");
};
return (optcopy);
}
public static function _cleanup(mc:Object):void{
var k:String;
var lc:LocalConnection;
var f:Function;
var mc = mc;
if (("lc" in mc)){
lc = mc.lc;
f = function ():void{
lc.client = null;
lc.close();
//unresolved jump
var _slot1 = e;
};
setTimeout(f, 0);
};
var idx:Number = DisplayObjectContainer(mc).numChildren;
while (idx > 0) {
idx = (idx - 1);
DisplayObjectContainer(mc).removeChildAt(idx);
};
for (k in mc) {
delete mc[k];
};
}
public static function load(options:Object):MovieClip{
var clip:Object;
var k:String;
var server:String;
var hostname:String;
var lc:LocalConnection;
var name:String;
var loader:Loader;
var g:Function;
var req:URLRequest;
var v:Object;
var options = options;
var DEFAULTS:Object = {server:"http://x.mochiads.com/srv/1/", method:"load", depth:10333, id:"_UNKNOWN_"};
options = MochiAd._parseOptions(options, DEFAULTS);
options.swfv = 9;
options.mav = MochiAd.getVersion();
clip = options.clip;
if (!MochiAd._isNetworkAvailable()){
return (null);
};
if (clip._mochiad_loaded){
return (null);
};
//unresolved jump
var _slot1 = e;
throw (new Error("MochiAd requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic."));
var depth:Number = options.depth;
delete options.depth;
var mc:MovieClip = createEmptyMovieClip(clip, "_mochiad", depth);
var wh:Array = MochiAd._getRes(options, clip);
options.res = ((wh[0] + "x") + wh[1]);
options.server = (options.server + options.id);
delete options.id;
clip._mochiad_loaded = true;
if (clip.loaderInfo.loaderURL.indexOf("http") == 0){
options.as3_swf = clip.loaderInfo.loaderURL;
} else {
trace("[MochiAd] NOTE: Security Sandbox Violation errors below are normal");
};
var lv:URLVariables = new URLVariables();
for (k in options) {
v = options[k];
if (!(v is Function)){
lv[k] = v;
};
};
server = lv.server;
delete lv.server;
hostname = _allowDomains(server);
lc = new LocalConnection();
lc.client = mc;
name = ["", Math.floor(new Date().getTime()), Math.floor((Math.random() * 999999))].join("_");
lc.allowDomain("*", "localhost");
lc.allowInsecureDomain("*", "localhost");
lc.connect(name);
mc.lc = lc;
mc.lcName = name;
lv.lc = name;
lv.st = getTimer();
loader = new Loader();
g = function (ev:Object):void{
ev.target.removeEventListener(ev.type, arguments.callee);
MochiAd.unload(clip);
};
loader.contentLoaderInfo.addEventListener(Event.UNLOAD, g);
req = new URLRequest(((server + ".swf?cacheBust=") + new Date().getTime()));
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function (io:IOErrorEvent):void{
trace("[MochiAds] Blocked URL");
});
loader.load(req);
mc.addChild(loader);
mc._mochiad_ctr = loader;
return (mc);
}
public static function runMethod(base:Object, methodName:String, argsArray:Array):Object{
var nameArray:Array = methodName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return (undefined);
};
base = base[nameArray[i]];
i++;
};
if (typeof(base[nameArray[i]]) == "function"){
return (base[nameArray[i]].apply(base, argsArray));
};
return (undefined);
}
public static function createEmptyMovieClip(parent:Object, name:String, depth:Number):MovieClip{
var mc:MovieClip = new MovieClip();
if (((false) && (depth))){
parent.addChildAt(mc, depth);
} else {
parent.addChild(mc);
};
parent[name] = mc;
mc["_name"] = name;
return (mc);
}
public static function _getRes(options:Object, clip:Object):Array{
var xy:Array;
var b:Object = clip.getBounds(clip.root);
var w:Number = 0;
var h:Number = 0;
if (typeof(options.res) != "undefined"){
xy = options.res.split("x");
w = parseFloat(xy[0]);
h = parseFloat(xy[1]);
} else {
w = (b.xMax - b.xMin);
h = (b.yMax - b.yMin);
};
if ((((w == 0)) || ((h == 0)))){
w = clip.stage.stageWidth;
h = clip.stage.stageHeight;
};
return ([w, h]);
}
public static function adShowing(mc:Object):void{
mc.origFrameRate = mc.stage.frameRate;
mc.stage.frameRate = 30;
}
public static function getValue(base:Object, objectName:String):Object{
var nameArray:Array = objectName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return (undefined);
};
base = base[nameArray[i]];
i++;
};
return (base[nameArray[i]]);
}
public static function rpc(clip:Object, callbackID:Number, arg:Object):void{
var _local4:Object;
var _local5:Object;
switch (arg.id){
case "setValue":
MochiAd.setValue(clip, arg.objectName, arg.value);
break;
case "getValue":
_local4 = MochiAd.getValue(clip, arg.objectName);
clip._mochiad.lc.send(clip._mochiad._containerLCName, "rpcResult", callbackID, _local4);
break;
case "runMethod":
_local5 = MochiAd.runMethod(clip, arg.method, arg.args);
clip._mochiad.lc.send(clip._mochiad._containerLCName, "rpcResult", callbackID, _local5);
break;
default:
trace(("[mochiads rpc] unknown rpc id: " + arg.id));
};
}
public static function setValue(base:Object, objectName:String, value:Object):void{
var nameArray:Array = objectName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return;
};
base = base[nameArray[i]];
i++;
};
base[nameArray[i]] = value;
}
public static function showPreGameAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var complete:Boolean;
var unloaded:Boolean;
var sendHostProgress:Boolean;
var fn:Function;
var r:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:3000, fadeout_time:250, regpt:"o", method:"showPreloaderAd", color:0xFF8A00, background:16777161, outline:13994812, no_progress_bar:false, ad_started:function ():void{
if ((this.clip is MovieClip)){
this.clip.stop();
} else {
throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_finished:function ():void{
if ((this.clip is MovieClip)){
this.clip.play();
} else {
throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}, ad_progress:function (percent:Number):void{
}, progress_override:function (_clip:Object):Number{
return (NaN);
}, bar_offset:0};
options = MochiAd._parseOptions(options, DEFAULTS);
if ("c862232051e0a94e1c3609b3916ddb17".substr(0) == "dfeada81ac97cde83665f81c12da7def"){
options.ad_started();
fn = function ():void{
options.ad_finished();
};
setTimeout(fn, 100);
return;
};
clip = options.clip;
var ad_msec:Number = 11000;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time:Number = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
var fn:Function = function ():void{
options.ad_finished();
};
setTimeout(fn, 100);
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.x = (w * -0.5);
chk.y = (h * -0.5);
var bar:MovieClip = createEmptyMovieClip(chk, "_mochiad_bar", 4);
if (options.no_progress_bar){
bar.visible = false;
delete options.no_progress_bar;
} else {
bar.x = (10 + options.bar_offset);
bar.y = (h - 20);
};
var bar_w:Number = ((w - bar.x) - 10);
var bar_color:Number = options.color;
delete options.color;
var bar_background:Number = options.background;
delete options.background;
var bar_outline:Number = options.outline;
delete options.outline;
var backing_mc:MovieClip = createEmptyMovieClip(bar, "_outline", 1);
var backing:Object = backing_mc.graphics;
backing.beginFill(bar_background);
backing.moveTo(0, 0);
backing.lineTo(bar_w, 0);
backing.lineTo(bar_w, 10);
backing.lineTo(0, 10);
backing.lineTo(0, 0);
backing.endFill();
var inside_mc:MovieClip = createEmptyMovieClip(bar, "_inside", 2);
var inside:Object = inside_mc.graphics;
inside.beginFill(bar_color);
inside.moveTo(0, 0);
inside.lineTo(bar_w, 0);
inside.lineTo(bar_w, 10);
inside.lineTo(0, 10);
inside.lineTo(0, 0);
inside.endFill();
inside_mc.scaleX = 0;
var outline_mc:MovieClip = createEmptyMovieClip(bar, "_outline", 3);
var outline:Object = outline_mc.graphics;
outline.lineStyle(0, bar_outline, 100);
outline.moveTo(0, 0);
outline.lineTo(bar_w, 0);
outline.lineTo(bar_w, 10);
outline.lineTo(0, 10);
outline.lineTo(0, 0);
chk.ad_msec = ad_msec;
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
chk.last_pcnt = 0;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function ():void{
var p:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time)));
if (p > 0){
this.parent.alpha = (p * 0.01);
} else {
MochiAd.unload(clip);
delete this["onEnterFrame"];
};
};
complete = false;
unloaded = false;
var progress:Number = Math.min(1, options.progress_override(clip));
var f:Function = function (ev:Event):void{
ev.target.removeEventListener(ev.type, arguments.callee);
complete = true;
if (unloaded){
MochiAd.unload(clip);
};
};
if (!isNaN(progress)){
complete = (progress == 1);
} else {
if (clip.loaderInfo.bytesLoaded == clip.loaderInfo.bytesTotal){
complete = true;
} else {
if ((clip.root is MovieClip)){
r = (clip.root as MovieClip);
if (r.framesLoaded >= r.totalFrames){
complete = true;
} else {
clip.loaderInfo.addEventListener(Event.COMPLETE, f);
};
} else {
clip.loaderInfo.addEventListener(Event.COMPLETE, f);
};
};
};
mc.unloadAd = function ():void{
unloaded = true;
if (complete){
MochiAd.unload(clip);
};
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.adjustProgress = function (msec:Number):void{
var _chk:Object = mc._mochiad_wait;
_chk.server_control = true;
_chk.showing = true;
_chk.started = getTimer();
_chk.ad_msec = msec;
};
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
mc.rpcTestFn = function (s:String):Object{
trace(("[MOCHIAD rpcTestFn] " + s));
return (s);
};
mc.regContLC = function (lc_name:String):void{
mc._containerLCName = lc_name;
};
sendHostProgress = false;
mc.sendHostLoadProgress = function (lc_name:String):void{
sendHostProgress = true;
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (((!(this.parent)) || (!(this.parent.parent)))){
delete this["onEnterFrame"];
return;
};
var _clip:Object = this.parent.parent.root;
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
var clip_total:Number = _clip.loaderInfo.bytesTotal;
var clip_loaded:Number = _clip.loaderInfo.bytesLoaded;
var clip_progress:Number = Math.min(1, options.progress_override(_clip));
if (clip_progress == 1){
complete = true;
};
if (complete){
clip_loaded = Math.max(1, clip_loaded);
clip_total = clip_loaded;
};
var clip_pcnt:Number = ((100 * clip_loaded) / clip_total);
if (!isNaN(clip_progress)){
clip_pcnt = (100 * clip_progress);
};
var ad_pcnt:Number = ((100 * elapsed) / chk.ad_msec);
var _inside:Object = this._mochiad_bar._inside;
var pcnt:Number = Math.min(100, Math.min(((clip_pcnt) || (0)), ad_pcnt));
pcnt = Math.max(this.last_pcnt, pcnt);
this.last_pcnt = pcnt;
_inside.scaleX = (pcnt * 0.01);
options.ad_progress(pcnt);
if (sendHostProgress){
clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"hostLoadPcnt", pcnt:clip_pcnt});
if (clip_pcnt >= 100){
sendHostProgress = false;
};
};
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
chk.started = getTimer();
MochiAd.adShowing(clip);
} else {
if ((((elapsed > chk.ad_timeout)) && ((clip_pcnt == 100)))){
options.ad_failed();
finished = true;
};
};
};
if (elapsed > chk.ad_msec){
finished = true;
};
if (((complete) && (finished))){
if (unloaded){
MochiAd.unload(_clip);
} else {
if (this.server_control){
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = chk.fadeFunction;
};
};
};
};
doOnEnterFrame(chk);
}
public static function showPreloaderAd(options:Object):void{
trace("[MochiAd] DEPRECATED: showPreloaderAd was renamed to showPreGameAd in 2.0");
MochiAd.showPreGameAd(options);
}
public static function showTimedAd(options:Object):void{
trace("[MochiAd] DEPRECATED: showTimedAd was renamed to showInterLevelAd in 2.0");
MochiAd.showInterLevelAd(options);
}
public static function doOnEnterFrame(mc:MovieClip):void{
var mc = mc;
var f:Function = function (ev:Object):void{
if (((("onEnterFrame" in mc)) && (mc.onEnterFrame))){
mc.onEnterFrame();
} else {
ev.target.removeEventListener(ev.type, arguments.callee);
};
};
mc.addEventListener(Event.ENTER_FRAME, f);
}
}
}//package mochi.as3
Section 2
//MochiCoins (mochi.as3.MochiCoins)
package mochi.as3 {
public class MochiCoins {
public static const STORE_HIDE:String = "StoreHide";
public static const LOGGED_IN:String = "LoggedIn";
public static const STORE_ITEMS:String = "StoreItems";
public static const NO_USER:String = "NoUser";
public static const PROPERTIES_SIZE:String = "PropertiesSize";
public static const ITEM_NEW:String = "ItemNew";
public static const USER_INFO:String = "UserInfo";
public static const IO_ERROR:String = "IOError";
public static const ITEM_OWNED:String = "ItemOwned";
public static const PROPERTIES_SAVED:String = "PropertySaved";
public static const WIDGET_LOADED:String = "WidgetLoaded";
public static const ERROR:String = "Error";
public static const LOGGED_OUT:String = "LoggedOut";
public static const PROFILE_SHOW:String = "ProfileShow";
public static const LOGIN_HIDE:String = "LoginHide";
public static const LOGIN_SHOW:String = "LoginShow";
public static const STORE_SHOW:String = "StoreShow";
public static const PROFILE_HIDE:String = "ProfileHide";
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
public function MochiCoins(){
super();
}
public static function showItem(options:Object=null):void{
if (((!(options)) || (!((typeof(options.item) == "string"))))){
trace("ERROR: showItem call must pass an Object with an item key");
return;
};
MochiServices.bringToTop();
MochiServices.send("coins_showItem", {options:options}, null, null);
}
public static function saveUserProperties(properties:Object):void{
MochiServices.send("coins_saveUserProperties", properties);
}
public static function triggerEvent(eventType:String, args:Object):void{
_dispatcher.triggerEvent(eventType, args);
}
public static function showLoginWidget(options:Object=null):void{
MochiServices.setContainer();
MochiServices.bringToTop();
MochiServices.send("coins_showLoginWidget", {options:options});
}
public static function getStoreItems():void{
MochiServices.send("coins_getStoreItems");
}
public static function getVersion():String{
return (MochiServices.getVersion());
}
public static function showStore(options:Object=null):void{
MochiServices.bringToTop();
MochiServices.send("coins_showStore", {options:options}, null, null);
}
public static function addEventListener(eventType:String, delegate:Function):void{
_dispatcher.addEventListener(eventType, delegate);
}
public static function getUserInfo():void{
MochiServices.send("coins_getUserInfo");
}
public static function hideLoginWidget():void{
MochiServices.send("coins_hideLoginWidget");
}
public static function removeEventListener(eventType:String, delegate:Function):void{
_dispatcher.removeEventListener(eventType, delegate);
}
public static function showVideo(options:Object=null):void{
if (((!(options)) || (!((typeof(options.item) == "string"))))){
trace("ERROR: showVideo call must pass an Object with an item key");
return;
};
MochiServices.bringToTop();
MochiServices.send("coins_showVideo", {options:options}, null, null);
}
}
}//package mochi.as3
Section 3
//MochiEventDispatcher (mochi.as3.MochiEventDispatcher)
package mochi.as3 {
public class MochiEventDispatcher {
private var eventTable:Object;
public function MochiEventDispatcher():void{
super();
eventTable = {};
}
public function triggerEvent(event:String, args:Object):void{
var i:Object;
if (eventTable[event] == undefined){
return;
};
for (i in eventTable[event]) {
var _local6 = eventTable[event];
_local6[i](args);
};
}
public function removeEventListener(event:String, delegate:Function):void{
var s:Object;
if (eventTable[event] == undefined){
eventTable[event] = [];
return;
};
for (s in eventTable[event]) {
if (eventTable[event][s] != delegate){
} else {
eventTable[event].splice(Number(s), 1);
};
};
}
public function addEventListener(event:String, delegate:Function):void{
removeEventListener(event, delegate);
eventTable[event].push(delegate);
}
}
}//package mochi.as3
Section 4
//MochiEvents (mochi.as3.MochiEvents)
package mochi.as3 {
import flash.display.*;
public class MochiEvents {
public static const ALIGN_BOTTOM_LEFT:String = "ALIGN_BL";
public static const FORMAT_LONG:String = "LongForm";
public static const ALIGN_BOTTOM:String = "ALIGN_B";
public static const ACHIEVEMENT_RECEIVED:String = "AchievementReceived";
public static const FORMAT_SHORT:String = "ShortForm";
public static const ALIGN_TOP_RIGHT:String = "ALIGN_TR";
public static const ALIGN_BOTTOM_RIGHT:String = "ALIGN_BR";
public static const ALIGN_TOP:String = "ALIGN_T";
public static const ALIGN_LEFT:String = "ALIGN_L";
public static const ALIGN_RIGHT:String = "ALIGN_R";
public static const ALIGN_TOP_LEFT:String = "ALIGN_TL";
public static const ALIGN_CENTER:String = "ALIGN_C";
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
private static var gameStart:Number;
private static var levelStart:Number;
public function MochiEvents(){
super();
}
public static function addEventListener(eventType:String, delegate:Function):void{
_dispatcher.addEventListener(eventType, delegate);
}
public static function removeEventListener(eventType:String, delegate:Function):void{
_dispatcher.removeEventListener(eventType, delegate);
}
public static function startSession(achievementID:String):void{
MochiServices.send("events_beginSession", {achievementID:achievementID}, null, null);
}
public static function triggerEvent(eventType:String, args:Object):void{
_dispatcher.triggerEvent(eventType, args);
}
public static function setNotifications(clip:MovieClip, style:Object):void{
var s:Object;
var args:Object = {};
for (s in style) {
args[s] = style[s];
};
args.clip = clip;
MochiServices.send("events_setNotifications", args, null, null);
}
public static function endGame():void{
var delta:Number = (new Date().time - gameStart);
trigger("end_game", {time:delta});
}
public static function startGame():void{
gameStart = new Date().time;
trigger("start_game");
}
public static function trigger(kind:String, obj:Object=null):void{
if (obj == null){
obj = {};
} else {
if (obj["kind"] != undefined){
trace("WARNING: optional arguements package contains key 'id', it will be overwritten");
obj["kind"] = kind;
};
};
MochiServices.send("events_triggerEvent", {eventObject:obj}, null, null);
}
public static function getVersion():String{
return (MochiServices.getVersion());
}
public static function startLevel():void{
levelStart = new Date().time;
trigger("start_level");
}
public static function endLevel():void{
var delta:Number = (new Date().time - levelStart);
trigger("end_level", {time:delta});
}
}
}//package mochi.as3
Section 5
//MochiServices (mochi.as3.MochiServices)
package mochi.as3 {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
import flash.geom.*;
public class MochiServices {
private static var _container:Object;
private static var _connected:Boolean = false;
private static var _swfVersion:String;
private static var _preserved:Object;
public static var netupAttempted:Boolean = false;
private static var _sendChannel:LocalConnection;
public static var servicesSync:MochiSync = new MochiSync();
private static var _clip:MovieClip;
private static var _id:String;
private static var _services:String = "services.swf";
private static var _servURL:String = "http://www.mochiads.com/static/lib/services/";
public static var widget:Boolean = false;
private static var _timer:Timer;
private static var _sendChannelName:String;
private static var _loader:Loader;
private static var _connecting:Boolean = false;
private static var _mochiLocalConnection:MovieClip;
private static var _listenChannelName:String = "__ms_";
public static var onError:Object;
public static var netup:Boolean = true;
private static var _mochiLC:String = "MochiLC.swf";
public function MochiServices(){
super();
}
public static function isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
public static function get connected():Boolean{
return (_connected);
}
private static function onReceive(pkg:Object):void{
var methodName:String;
var pkg = pkg;
var cb:String = pkg.callbackID;
var cblst:Object = _clip._callbacks[cb];
if (!cblst){
return;
};
var method:* = cblst.callbackMethod;
methodName = "";
var obj:Object = cblst.callbackObject;
if (((obj) && ((typeof(method) == "string")))){
methodName = method;
if (obj[method] != null){
method = obj[method];
} else {
trace((("Error: Method " + method) + " does not exist."));
};
};
if (method != undefined){
method.apply(obj, pkg.args);
//unresolved jump
var _slot1 = error;
trace(((("Error invoking callback method '" + methodName) + "': ") + _slot1.toString()));
} else {
if (obj != null){
obj(pkg.args);
//unresolved jump
var _slot1 = error;
trace(("Error invoking method on object: " + _slot1.toString()));
};
};
delete _clip._callbacks[cb];
}
public static function get childClip():Object{
return (_clip);
}
public static function send(methodName:String, args:Object=null, callbackObject:Object=null, callbackMethod:Object=null):void{
if (_connected){
_mochiLocalConnection.send(_sendChannelName, "onReceive", {methodName:methodName, args:args, callbackID:_clip._nextcallbackID});
} else {
if ((((_clip == null)) || (!(_connecting)))){
trace(("Error: MochiServices not connected. Please call MochiServices.connect(). Function: " + methodName));
handleError(args, callbackObject, callbackMethod);
flush(true);
return;
};
_clip._queue.push({methodName:methodName, args:args, callbackID:_clip._nextcallbackID});
};
if (_clip != null){
if (((!((_clip._callbacks == null))) && (!((_clip._nextcallbackID == null))))){
_clip._callbacks[_clip._nextcallbackID] = {callbackObject:callbackObject, callbackMethod:callbackMethod};
_clip._nextcallbackID++;
};
};
}
private static function init(id:String, clip:Object):void{
_id = id;
if (clip != null){
_container = clip;
loadCommunicator(id, _container);
};
}
private static function clickMovie(url:String, cb:Function):MovieClip{
var b:int;
var loader:Loader;
var avm1_bytecode:Array = [150, 21, 0, 7, 1, 0, 0, 0, 0, 98, 116, 110, 0, 7, 2, 0, 0, 0, 0, 116, 104, 105, 115, 0, 28, 150, 22, 0, 0, 99, 114, 101, 97, 116, 101, 69, 109, 112, 116, 121, 77, 111, 118, 105, 101, 67, 108, 105, 112, 0, 82, 135, 1, 0, 0, 23, 150, 13, 0, 4, 0, 0, 111, 110, 82, 101, 108, 101, 97, 115, 101, 0, 142, 8, 0, 0, 0, 0, 2, 42, 0, 114, 0, 150, 17, 0, 0, 32, 0, 7, 1, 0, 0, 0, 8, 0, 0, 115, 112, 108, 105, 116, 0, 82, 135, 1, 0, 1, 23, 150, 7, 0, 4, 1, 7, 0, 0, 0, 0, 78, 150, 8, 0, 0, 95, 98, 108, 97, 110, 107, 0, 154, 1, 0, 0, 150, 7, 0, 0, 99, 108, 105, 99, 107, 0, 150, 7, 0, 4, 1, 7, 1, 0, 0, 0, 78, 150, 27, 0, 7, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 76, 111, 99, 97, 108, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 0, 64, 150, 6, 0, 0, 115, 101, 110, 100, 0, 82, 79, 150, 15, 0, 4, 0, 0, 95, 97, 108, 112, 104, 97, 0, 7, 0, 0, 0, 0, 79, 150, 23, 0, 7, 0xFF, 0, 0xFF, 0, 7, 1, 0, 0, 0, 4, 0, 0, 98, 101, 103, 105, 110, 70, 105, 108, 108, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 109, 111, 118, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 100, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 100, 0, 0, 0, 7, 100, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 100, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 16, 0, 7, 0, 0, 0, 0, 4, 0, 0, 101, 110, 100, 70, 105, 108, 108, 0, 82, 23];
var header:Array = [104, 0, 31, 64, 0, 7, 208, 0, 0, 12, 1, 0, 67, 2, 0xFF, 0xFF, 0xFF, 63, 3];
var footer:Array = [0, 64, 0, 0, 0];
var mc:MovieClip = new MovieClip();
var lc:LocalConnection = new LocalConnection();
var lc_name:String = ((("_click_" + Math.floor((Math.random() * 999999))) + "_") + Math.floor(new Date().time));
lc = new LocalConnection();
mc.lc = lc;
mc.click = cb;
lc.client = mc;
lc.connect(lc_name);
var ba:ByteArray = new ByteArray();
var cpool:ByteArray = new ByteArray();
cpool.endian = Endian.LITTLE_ENDIAN;
cpool.writeShort(1);
cpool.writeUTFBytes(((url + " ") + lc_name));
cpool.writeByte(0);
var actionLength:uint = ((avm1_bytecode.length + cpool.length) + 4);
var fileLength:uint = (actionLength + 35);
ba.endian = Endian.LITTLE_ENDIAN;
ba.writeUTFBytes("FWS");
ba.writeByte(8);
ba.writeUnsignedInt(fileLength);
for each (b in header) {
ba.writeByte(b);
};
ba.writeUnsignedInt(actionLength);
ba.writeByte(136);
ba.writeShort(cpool.length);
ba.writeBytes(cpool);
for each (b in avm1_bytecode) {
ba.writeByte(b);
};
for each (b in footer) {
ba.writeByte(b);
};
loader = new Loader();
loader.loadBytes(ba);
mc.addChild(loader);
return (mc);
}
public static function stayOnTop():void{
_container.addEventListener(Event.ENTER_FRAME, MochiServices.bringToTop, false, 0, true);
if (_clip != null){
_clip.visible = true;
};
}
public static function addLinkEvent(url:String, burl:String, btn:DisplayObjectContainer, onClick:Function=null):void{
var avm1Click:DisplayObject;
var x:String;
var req:URLRequest;
var loader:Loader;
var setURL:Function;
var err:Function;
var complete:Function;
var url = url;
var burl = burl;
var btn = btn;
var onClick = onClick;
var vars:Object = new Object();
vars["mav"] = getVersion();
vars["swfv"] = "9";
vars["swfurl"] = btn.loaderInfo.loaderURL;
vars["fv"] = Capabilities.version;
vars["os"] = Capabilities.os;
vars["lang"] = Capabilities.language;
vars["scres"] = ((Capabilities.screenResolutionX + "x") + Capabilities.screenResolutionY);
var s = "?";
var i:Number = 0;
for (x in vars) {
if (i != 0){
s = (s + "&");
};
i = (i + 1);
s = (((s + x) + "=") + escape(vars[x]));
};
req = new URLRequest("http://x.mochiads.com/linkping.swf");
loader = new Loader();
setURL = function (url:String):void{
if (avm1Click){
btn.removeChild(avm1Click);
};
avm1Click = clickMovie(url, onClick);
var rect:Rectangle = btn.getBounds(btn);
btn.addChild(avm1Click);
avm1Click.x = rect.x;
avm1Click.y = rect.y;
avm1Click.scaleX = (0.01 * rect.width);
avm1Click.scaleY = (0.01 * rect.height);
};
err = function (ev:Object):void{
netup = false;
ev.target.removeEventListener(ev.type, arguments.callee);
setURL(burl);
};
complete = function (ev:Object):void{
ev.target.removeEventListener(ev.type, arguments.callee);
};
if (netup){
setURL((url + s));
} else {
setURL(burl);
};
if (!((netupAttempted) || (_connected))){
netupAttempted = true;
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, err);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete);
loader.load(req);
};
}
public static function warnID(bid:String, leaderboard:Boolean):void{
bid = bid.toLowerCase();
if (bid.length != 16){
trace((("WARNING: " + (leaderboard) ? "board" : "game") + " ID is not the appropriate length"));
return;
} else {
if (bid == "1e113c7239048b3f"){
if (leaderboard){
trace("WARNING: Using testing board ID");
} else {
trace("WARNING: Using testing board ID as game ID");
};
return;
} else {
if (bid == "84993a1de4031cd8"){
if (leaderboard){
trace("WARNING: Using testing game ID as board ID");
} else {
trace("WARNING: Using testing game ID");
};
return;
};
};
};
var i:Number = 0;
while (i < bid.length) {
switch (bid.charAt(i)){
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
case "a":
case "b":
case "c":
case "d":
case "e":
case "f":
break;
default:
trace(("WARNING: Board ID contains illegal characters: " + bid));
return;
};
i++;
};
}
public static function disconnect():void{
if (((_connected) || (_connecting))){
if (_clip != null){
if (_clip.parent != null){
if ((_clip.parent is Sprite)){
Sprite(_clip.parent).removeChild(_clip);
_clip = null;
};
};
};
_connecting = (_connected = false);
flush(true);
_mochiLocalConnection.close();
//unresolved jump
var _slot1 = error;
};
if (_timer != null){
_timer.stop();
//unresolved jump
var _slot1 = error;
};
}
public static function allowDomains(server:String):String{
var hostname:String;
if (Security.sandboxType != "application"){
Security.allowDomain("*");
Security.allowInsecureDomain("*");
};
if (server.indexOf("http://") != -1){
hostname = server.split("/")[2].split(":")[0];
if (Security.sandboxType != "application"){
Security.allowDomain(hostname);
Security.allowInsecureDomain(hostname);
};
};
return (hostname);
}
public static function getVersion():String{
return ("3.3 as3");
}
public static function doClose():void{
_container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop);
}
private static function flush(error:Boolean):void{
var request:Object;
var callback:Object;
if (((_clip) && (_clip._queue))){
while (_clip._queue.length > 0) {
request = _clip._queue.shift();
callback = null;
if (request != null){
if (request.callbackID != null){
callback = _clip._callbacks[request.callbackID];
};
delete _clip._callbacks[request.callbackID];
if (((error) && (!((callback == null))))){
handleError(request.args, callback.callbackObject, callback.callbackMethod);
};
};
};
};
}
public static function get id():String{
return (_id);
}
private static function onEvent(pkg:Object):void{
var target:String = pkg.target;
var event:String = pkg.event;
switch (target){
case "events":
MochiEvents.triggerEvent(pkg.event, pkg.args);
break;
case "coins":
MochiCoins.triggerEvent(pkg.event, pkg.args);
break;
case "sync":
servicesSync.triggerEvent(pkg.event, pkg.args);
break;
};
}
private static function urlOptions(clip:Object):Object{
var options:String;
var pairs:Array;
var i:Number;
var kv:Array;
var opts:Object = {};
if (clip.stage){
options = clip.stage.loaderInfo.parameters.mochiad_options;
} else {
options = clip.loaderInfo.parameters.mochiad_options;
};
if (options){
pairs = options.split("&");
i = 0;
while (i < pairs.length) {
kv = pairs[i].split("=");
opts[unescape(kv[0])] = unescape(kv[1]);
i++;
};
};
return (opts);
}
public static function setContainer(container:Object=null, doAdd:Boolean=true):void{
if (container != null){
if ((container is Sprite)){
_container = container;
};
};
if (doAdd){
if ((_container is Sprite)){
Sprite(_container).addChild(_clip);
};
};
}
private static function handleError(args:Object, callbackObject:Object, callbackMethod:Object):void{
var args = args;
var callbackObject = callbackObject;
var callbackMethod = callbackMethod;
if (args != null){
if (args.onError != null){
args.onError.apply(null, ["NotConnected"]);
};
if (((!((args.options == null))) && (!((args.options.onError == null))))){
args.options.onError.apply(null, ["NotConnected"]);
};
};
if (callbackMethod != null){
args = {};
args.error = true;
args.errorCode = "NotConnected";
if (((!((callbackObject == null))) && ((callbackMethod is String)))){
var _local5 = callbackObject;
_local5[callbackMethod](args);
//unresolved jump
var _slot1 = error;
} else {
if (callbackMethod != null){
callbackMethod.apply(args);
//unresolved jump
var _slot1 = error;
};
};
};
}
private static function loadError(ev:Object):void{
_clip._mochiad_ctr_failed = true;
trace("MochiServices could not load.");
MochiServices.disconnect();
MochiServices.onError("IOError");
}
private static function initComChannels():void{
if (!_connected){
trace("[SERVICES_API] connected!");
_connecting = false;
_connected = true;
_mochiLocalConnection.send(_sendChannelName, "onReceive", {methodName:"handshakeDone"});
_mochiLocalConnection.send(_sendChannelName, "onReceive", {methodName:"registerGame", preserved:_preserved, id:_id, clip:_container, version:getVersion(), parentURL:_container.loaderInfo.loaderURL});
_clip.onReceive = onReceive;
_clip.onEvent = onEvent;
_clip.onError = function ():void{
MochiServices.onError("IOError");
};
while (_clip._queue.length > 0) {
_mochiLocalConnection.send(_sendChannelName, "onReceive", _clip._queue.shift());
};
};
}
private static function loadLCBridge(clip:Object):void{
var loader:Loader;
var clip = clip;
loader = new Loader();
var mochiLCURL:String = (_servURL + _mochiLC);
var req:URLRequest = new URLRequest(mochiLCURL);
var complete:Function = function (ev:Object):void{
_mochiLocalConnection = MovieClip(loader.content);
listen();
};
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
loader.load(req);
clip.addChild(loader);
}
private static function listen():void{
_mochiLocalConnection.connect(_listenChannelName);
_clip.handshake = function (args:Object):void{
MochiServices.comChannelName = args.newChannel;
};
trace("Waiting for MochiAds services to connect...");
}
public static function get clip():Object{
return (_container);
}
public static function set comChannelName(val:String):void{
if (val != null){
if (val.length > 3){
_sendChannelName = (val + "_fromgame");
initComChannels();
};
};
}
private static function loadCommunicator(id:String, clip:Object):MovieClip{
var clipname:String = ("_mochiservices_com_" + id);
if (_clip != null){
return (_clip);
};
if (!MochiServices.isNetworkAvailable()){
return (null);
};
if (urlOptions(clip).servURL){
_servURL = urlOptions(clip).servURL;
};
var servicesURL:String = (_servURL + _services);
if (urlOptions(clip).servicesURL){
servicesURL = urlOptions(clip).servicesURL;
};
_listenChannelName = (_listenChannelName + ((Math.floor(new Date().time) + "_") + Math.floor((Math.random() * 99999))));
MochiServices.allowDomains(servicesURL);
_clip = createEmptyMovieClip(clip, clipname, 10336, false);
loadLCBridge(_clip);
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
var req:URLRequest = new URLRequest(servicesURL);
var vars:URLVariables = new URLVariables();
vars.listenLC = _listenChannelName;
vars.mochiad_options = clip.loaderInfo.parameters.mochiad_options;
vars.api_version = getVersion();
if (widget){
vars.widget = true;
};
req.data = vars;
_loader.load(req);
_clip.addChild(_loader);
_clip._mochiservices_com = _loader;
_sendChannel = new LocalConnection();
_clip._queue = [];
_clip._nextcallbackID = 0;
_clip._callbacks = {};
_timer = new Timer(10000, 1);
_timer.addEventListener(TimerEvent.TIMER, connectWait);
_timer.start();
return (_clip);
}
public static function connect(id:String, clip:Object, onError:Object=null):void{
var id = id;
var clip = clip;
var onError = onError;
warnID(id, false);
if ((clip is DisplayObject)){
if (((!(_connected)) && ((_clip == null)))){
trace("MochiServices Connecting...");
_connecting = true;
init(id, clip);
};
} else {
trace("Error, MochiServices requires a Sprite, Movieclip or instance of the stage.");
};
if (onError != null){
MochiServices.onError = onError;
} else {
if (MochiServices.onError == null){
MochiServices.onError = function (errorCode:String):void{
trace(errorCode);
};
};
};
}
public static function createEmptyMovieClip(parent:Object, name:String, depth:Number, doAdd:Boolean=true):MovieClip{
var parent = parent;
var name = name;
var depth = depth;
var doAdd = doAdd;
var mc:MovieClip = new MovieClip();
if (doAdd){
if (((false) && (depth))){
parent.addChildAt(mc, depth);
} else {
parent.addChild(mc);
};
};
parent[name] = mc;
//unresolved jump
var _slot1 = e;
throw (new Error("MochiServices requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic."));
mc["_name"] = name;
return (mc);
}
public static function bringToTop(e:Event=null):void{
var e = e;
if (((!((MochiServices.clip == null))) && (!((MochiServices.childClip == null))))){
if (MochiServices.clip.numChildren > 1){
MochiServices.clip.setChildIndex(MochiServices.childClip, (MochiServices.clip.numChildren - 1));
};
//unresolved jump
var _slot1 = errorObject;
trace("Warning: Depth sort error.");
_container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop);
};
}
public static function connectWait(e:TimerEvent):void{
if (!_connected){
_clip._mochiad_ctr_failed = true;
trace("MochiServices could not load. (timeout)");
MochiServices.disconnect();
MochiServices.onError("IOError");
};
}
}
}//package mochi.as3
Section 6
//MochiSync (mochi.as3.MochiSync)
package mochi.as3 {
import flash.utils.*;
public dynamic class MochiSync extends Proxy {
private var _syncContainer:Object;
public static var SYNC_PROPERTY:String = "UpdateProperty";
public static var SYNC_REQUEST:String = "SyncRequest";
public function MochiSync():void{
super();
_syncContainer = {};
}
override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function setProperty(name, value):void{
if (_syncContainer[name] == value){
return;
};
var n:String = name.toString();
_syncContainer[n] = value;
MochiServices.send("sync_propUpdate", {name:n, value:value});
}
override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function getProperty(name){
return (_syncContainer[name]);
}
public function triggerEvent(eventType:String, args:Object):void{
switch (eventType){
case SYNC_REQUEST:
MochiServices.send("sync_syncronize", _syncContainer);
break;
case SYNC_PROPERTY:
_syncContainer[args.name] = args.value;
break;
};
}
}
}//package mochi.as3
Section 7
//ByteArrayAsset (mx.core.ByteArrayAsset)
package mx.core {
import flash.utils.*;
public class ByteArrayAsset extends ByteArray implements IFlexAsset {
mx_internal static const VERSION:String = "3.3.0.4852";
public function ByteArrayAsset(){
super();
}
}
}//package mx.core
Section 8
//EdgeMetrics (mx.core.EdgeMetrics)
package mx.core {
public class EdgeMetrics {
public var top:Number;
public var left:Number;
public var bottom:Number;
public var right:Number;
mx_internal static const VERSION:String = "3.3.0.4852";
public static const EMPTY:EdgeMetrics = new EdgeMetrics(0, 0, 0, 0);
;
public function EdgeMetrics(left:Number=0, top:Number=0, right:Number=0, bottom:Number=0){
super();
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public function clone():EdgeMetrics{
return (new EdgeMetrics(left, top, right, bottom));
}
}
}//package mx.core
Section 9
//FlexMovieClip (mx.core.FlexMovieClip)
package mx.core {
import flash.display.*;
import mx.utils.*;
public class FlexMovieClip extends MovieClip {
mx_internal static const VERSION:String = "3.3.0.4852";
public function FlexMovieClip(){
super();
name = NameUtil.createUniqueName(this);
//unresolved jump
var _slot1 = e;
}
override public function toString():String{
return (NameUtil.displayObjectToString(this));
}
}
}//package mx.core
Section 10
//IBorder (mx.core.IBorder)
package mx.core {
public interface IBorder {
function get borderMetrics():EdgeMetrics;
}
}//package mx.core
Section 11
//IFlexAsset (mx.core.IFlexAsset)
package mx.core {
public interface IFlexAsset {
}
}//package mx.core
Section 12
//IFlexDisplayObject (mx.core.IFlexDisplayObject)
package mx.core {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import flash.accessibility.*;
public interface IFlexDisplayObject extends IBitmapDrawable, IEventDispatcher {
function get visible():Boolean;
function get rotation():Number;
function localToGlobal(void:Point):Point;
function get name():String;
function set width(flash.display:Number):void;
function get measuredHeight():Number;
function get blendMode():String;
function get scale9Grid():Rectangle;
function set name(flash.display:String):void;
function set scaleX(flash.display:Number):void;
function set scaleY(flash.display:Number):void;
function get measuredWidth():Number;
function get accessibilityProperties():AccessibilityProperties;
function set scrollRect(flash.display:Rectangle):void;
function get cacheAsBitmap():Boolean;
function globalToLocal(void:Point):Point;
function get height():Number;
function set blendMode(flash.display:String):void;
function get parent():DisplayObjectContainer;
function getBounds(String:DisplayObject):Rectangle;
function get opaqueBackground():Object;
function set scale9Grid(flash.display:Rectangle):void;
function setActualSize(_arg1:Number, _arg2:Number):void;
function set alpha(flash.display:Number):void;
function set accessibilityProperties(flash.display:AccessibilityProperties):void;
function get width():Number;
function hitTestPoint(_arg1:Number, _arg2:Number, _arg3:Boolean=false):Boolean;
function set cacheAsBitmap(flash.display:Boolean):void;
function get scaleX():Number;
function get scaleY():Number;
function get scrollRect():Rectangle;
function get mouseX():Number;
function get mouseY():Number;
function set height(flash.display:Number):void;
function set mask(flash.display:DisplayObject):void;
function getRect(String:DisplayObject):Rectangle;
function get alpha():Number;
function set transform(flash.display:Transform):void;
function move(_arg1:Number, _arg2:Number):void;
function get loaderInfo():LoaderInfo;
function get root():DisplayObject;
function hitTestObject(mx.core:IFlexDisplayObject/mx.core:IFlexDisplayObject:stage/get:DisplayObject):Boolean;
function set opaqueBackground(flash.display:Object):void;
function set visible(flash.display:Boolean):void;
function get mask():DisplayObject;
function set x(flash.display:Number):void;
function set y(flash.display:Number):void;
function get transform():Transform;
function set filters(flash.display:Array):void;
function get x():Number;
function get y():Number;
function get filters():Array;
function set rotation(flash.display:Number):void;
function get stage():Stage;
}
}//package mx.core
Section 13
//IRepeaterClient (mx.core.IRepeaterClient)
package mx.core {
public interface IRepeaterClient {
function get instanceIndices():Array;
function set instanceIndices(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get isDocument():Boolean;
function set repeaters(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function initializeRepeaterArrays(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:IRepeaterClient):void;
function get repeaters():Array;
function set repeaterIndices(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get repeaterIndices():Array;
}
}//package mx.core
Section 14
//MovieClipAsset (mx.core.MovieClipAsset)
package mx.core {
public class MovieClipAsset extends FlexMovieClip implements IFlexAsset, IFlexDisplayObject, IBorder {
private var _measuredHeight:Number;
private var _measuredWidth:Number;
mx_internal static const VERSION:String = "3.3.0.4852";
public function MovieClipAsset(){
super();
_measuredWidth = width;
_measuredHeight = height;
}
public function get measuredWidth():Number{
return (_measuredWidth);
}
public function get measuredHeight():Number{
return (_measuredHeight);
}
public function setActualSize(newWidth:Number, newHeight:Number):void{
width = newWidth;
height = newHeight;
}
public function move(x:Number, y:Number):void{
this.x = x;
this.y = y;
}
public function get borderMetrics():EdgeMetrics{
if (scale9Grid == null){
return (EdgeMetrics.EMPTY);
};
return (new EdgeMetrics(scale9Grid.left, scale9Grid.top, Math.ceil((measuredWidth - scale9Grid.right)), Math.ceil((measuredHeight - scale9Grid.bottom))));
}
}
}//package mx.core
Section 15
//MovieClipLoaderAsset (mx.core.MovieClipLoaderAsset)
package mx.core {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.system.*;
public class MovieClipLoaderAsset extends MovieClipAsset implements IFlexAsset, IFlexDisplayObject {
protected var initialHeight:Number;// = 0
private var loader:Loader;// = null
private var initialized:Boolean;// = false
protected var initialWidth:Number;// = 0
private var requestedHeight:Number;
private var requestedWidth:Number;
mx_internal static const VERSION:String = "3.3.0.4852";
public function MovieClipLoaderAsset(){
super();
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
if (("allowLoadBytesCodeExecution" in loaderContext)){
loaderContext["allowLoadBytesCodeExecution"] = true;
};
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.loadBytes(movieClipData, loaderContext);
addChild(loader);
}
override public function get width():Number{
if (!initialized){
return (initialWidth);
};
return (super.width);
}
override public function set width(value:Number):void{
if (!initialized){
requestedWidth = value;
} else {
loader.width = value;
};
}
override public function get measuredHeight():Number{
return (initialHeight);
}
private function completeHandler(event:Event):void{
initialized = true;
initialWidth = loader.width;
initialHeight = loader.height;
if (!isNaN(requestedWidth)){
loader.width = requestedWidth;
};
if (!isNaN(requestedHeight)){
loader.height = requestedHeight;
};
dispatchEvent(event);
}
override public function set height(value:Number):void{
if (!initialized){
requestedHeight = value;
} else {
loader.height = value;
};
}
override public function get measuredWidth():Number{
return (initialWidth);
}
override public function get height():Number{
if (!initialized){
return (initialHeight);
};
return (super.height);
}
public function get movieClipData():ByteArray{
return (null);
}
}
}//package mx.core
Section 16
//mx_internal (mx.core.mx_internal)
package mx.core {
public namespace mx_internal = "http://www.adobe.com/2006/flex/mx/internal";
}//package mx.core
Section 17
//NameUtil (mx.utils.NameUtil)
package mx.utils {
import flash.display.*;
import mx.core.*;
import flash.utils.*;
public class NameUtil {
mx_internal static const VERSION:String = "3.3.0.4852";
private static var counter:int = 0;
public function NameUtil(){
super();
}
public static function displayObjectToString(displayObject:DisplayObject):String{
var result:String;
var o:DisplayObject;
var s:String;
var indices:Array;
var displayObject = displayObject;
o = displayObject;
while (o != null) {
if (((((o.parent) && (o.stage))) && ((o.parent == o.stage)))){
break;
};
s = o.name;
if ((o is IRepeaterClient)){
indices = IRepeaterClient(o).instanceIndices;
if (indices){
s = (s + (("[" + indices.join("][")) + "]"));
};
};
result = ((result == null)) ? s : ((s + ".") + result);
o = o.parent;
};
//unresolved jump
var _slot1 = e;
return (result);
}
public static function createUniqueName(object:Object):String{
if (!object){
return (null);
};
var name:String = getQualifiedClassName(object);
var index:int = name.indexOf("::");
if (index != -1){
name = name.substr((index + 2));
};
var charCode:int = name.charCodeAt((name.length - 1));
if ((((charCode >= 48)) && ((charCode <= 57)))){
name = (name + "_");
};
return ((name + counter++));
}
}
}//package mx.utils
Section 18
//LoadBar (LoadBar)
package {
import flash.display.*;
public dynamic class LoadBar extends MovieClip {
}
}//package
Section 19
//MochiPreloader (MochiPreloader)
package {
import flash.display.*;
import mochi.as3.*;
import flash.utils.*;
import flash.ui.*;
public dynamic class MochiPreloader extends MovieClip {
private var GAME_OPTIONS:Object;
private var _clip:MovieClip;
public function MochiPreloader(){
super();
var cm:ContextMenu = new ContextMenu();
cm.hideBuiltInItems();
this.contextMenu = cm;
_clip = new MovieClip();
addChild(_clip);
this.preloader = null;
}
private function MochiAdComplete():void{
var obj:Object;
var mainClass:Class = Class(getDefinitionByName("MochiPreloaderMain"));
if (mainClass){
obj = new (mainClass);
this.addChild((obj as DisplayObject));
};
}
public function set preloader(preloader:Sprite):void{
MochiAd.showPreGameAd({clip:_clip, id:"79c698789e3a200c", res:"550x550", ad_finished:MochiAdComplete});
}
}
}//package
Section 20
//MochiPreloaderMain (MochiPreloaderMain)
package {
import flash.events.*;
import flash.display.*;
import mx.core.*;
import flash.utils.*;
import flash.net.*;
import flash.text.*;
public class MochiPreloaderMain extends MovieClip {
private var wh:MovieClip;
public var Game:Class;
private var moido:MovieClip;
private var kongClass:Class;
private var child:MovieClipLoaderAsset;
private var faded:Number;// = 1
private var kongregate:MovieClip;
public var words5:Class;
public var words6:Class;
public var words7:Class;
public var words4:Class;
private var fader:Sprite;
private var game:MovieClip;
private var ldr:Loader;
public var wordsAll:Class;
public function MochiPreloaderMain(){
Game = MochiPreloaderMain_Game;
words4 = MochiPreloaderMain_words4;
words5 = MochiPreloaderMain_words5;
words6 = MochiPreloaderMain_words6;
words7 = MochiPreloaderMain_words7;
wordsAll = MochiPreloaderMain_wordsAll;
kongClass = MochiPreloaderMain_kongClass;
super();
init();
fader = new Sprite();
fader.graphics.beginFill(0, 1);
fader.graphics.drawRect(0, 0, 550, 550);
fader.graphics.endFill();
}
private function fadeOut(event:Event):void{
faded = (faded - 1.1);
fader.graphics.clear();
if (faded <= 0){
this.removeEventListener(Event.ENTER_FRAME, fadeOut);
return;
};
}
private function kongClick(event:Event):void{
navigateToURL(new URLRequest("http://www.kongregate.com/?gamereferral=wordspector"), "_blank");
}
private function init():void{
kongregate = new kongClass();
kongregate.x = 10;
kongregate.y = ((550 - kongregate.height) / 2);
kongregate.addEventListener(MouseEvent.CLICK, kongClick);
this.addChild(kongregate);
setTimeout(fadeToMoido, 5000);
}
private function fadeInMoido(event:Event):void{
fader.alpha = (fader.alpha - 0.1);
if (fader.alpha <= 0){
fader.alpha = 0;
this.removeEventListener(Event.ENTER_FRAME, fadeInMoido);
showMoidoLogo();
};
}
private function ef(event:Event):void{
var tf:TextField;
var format:TextFormat;
this.removeEventListener(Event.ENTER_FRAME, ef);
var domain:String = this.stage.root.loaderInfo.url;
var allowedDomains:Array = ["", "http://www.flashgamelicense.com", "https://www.flashgamelicense.com", "http://www.moidogames.com", "http://moidogames.com", "http://moido.dynalias.com", "file://"];
trace(("DOMAIM: " + domain));
var domainFound:Boolean;
var i:int;
while (i < allowedDomains.length) {
if (domain.indexOf(allowedDomains[i]) != -1){
domainFound = true;
break;
};
i++;
};
if (!domainFound){
tf = new TextField();
tf.text = "The game is not allowed to be published on this site.\nPlease contact info@moidogames.com for licensing options";
format = new TextFormat("Arial", 18, 0xFFFFFF);
tf.setTextFormat(format);
tf.width = this.stage.stageWidth;
tf.height = this.stage.stageHeight;
tf.multiline = true;
this.addChild(tf);
return;
};
var baAll:ByteArray = (new wordsAll() as ByteArray);
var ba4:ByteArray = (new words4() as ByteArray);
var ba5:ByteArray = (new words5() as ByteArray);
var ba6:ByteArray = (new words6() as ByteArray);
var ba7:ByteArray = (new words7() as ByteArray);
var wh:Class = (ldr.contentLoaderInfo.applicationDomain.getDefinition("WordHunt") as Class);
game = new (wh);
game.test = "FOOBAR";
game.parseWords(baAll, ba4, ba5, ba6, ba7);
this.removeEventListener(Event.ENTER_FRAME, ef);
this.addChild(game);
}
private function showMoidoLogo():void{
setTimeout(moveToGame, 500);
}
private function fadeOutKong(event:Event):void{
fader.alpha = (fader.alpha + 0.1);
if (fader.alpha >= 1){
fader.alpha = 1;
this.removeEventListener(Event.ENTER_FRAME, fadeOutKong);
this.addEventListener(Event.ENTER_FRAME, fadeInMoido);
moido = new LoadBar();
this.addChild(moido);
this.removeChild(kongregate);
this.addChild(fader);
};
}
private function fadeToMoido():void{
fader.alpha = 0;
this.addChild(fader);
this.addEventListener(Event.ENTER_FRAME, fadeOutKong);
}
private function moveToGame():void{
child = new Game();
var ba:ByteArray = child.movieClipData;
ba.position = 0;
ldr = new Loader();
ldr.loadBytes(ba);
this.addEventListener(Event.ENTER_FRAME, ef);
nextFrame();
fader = new Sprite();
this.addEventListener(Event.ENTER_FRAME, fadeOut);
}
}
}//package
Section 21
//MochiPreloaderMain_Game (MochiPreloaderMain_Game)
package {
import mx.core.*;
import flash.utils.*;
public class MochiPreloaderMain_Game extends MovieClipLoaderAsset {
public var dataClass:Class;
private static var bytes:ByteArray = null;
public function MochiPreloaderMain_Game(){
dataClass = MochiPreloaderMain_Game_dataClass;
super();
initialWidth = (11000 / 20);
initialHeight = (11000 / 20);
}
override public function get movieClipData():ByteArray{
if (bytes == null){
bytes = ByteArray(new dataClass());
};
return (bytes);
}
}
}//package
Section 22
//MochiPreloaderMain_Game_dataClass (MochiPreloaderMain_Game_dataClass)
package {
import mx.core.*;
public class MochiPreloaderMain_Game_dataClass extends ByteArrayAsset {
}
}//package
Section 23
//MochiPreloaderMain_kongClass (MochiPreloaderMain_kongClass)
package {
import mx.core.*;
import flash.utils.*;
public class MochiPreloaderMain_kongClass extends MovieClipLoaderAsset {
public var dataClass:Class;
private static var bytes:ByteArray = null;
public function MochiPreloaderMain_kongClass(){
dataClass = MochiPreloaderMain_kongClass_dataClass;
super();
initialWidth = (11000 / 20);
initialHeight = (8000 / 20);
}
override public function get movieClipData():ByteArray{
if (bytes == null){
bytes = ByteArray(new dataClass());
};
return (bytes);
}
}
}//package
Section 24
//MochiPreloaderMain_kongClass_dataClass (MochiPreloaderMain_kongClass_dataClass)
package {
import mx.core.*;
public class MochiPreloaderMain_kongClass_dataClass extends ByteArrayAsset {
}
}//package
Section 25
//MochiPreloaderMain_words4 (MochiPreloaderMain_words4)
package {
import mx.core.*;
public class MochiPreloaderMain_words4 extends ByteArrayAsset {
}
}//package
Section 26
//MochiPreloaderMain_words5 (MochiPreloaderMain_words5)
package {
import mx.core.*;
public class MochiPreloaderMain_words5 extends ByteArrayAsset {
}
}//package
Section 27
//MochiPreloaderMain_words6 (MochiPreloaderMain_words6)
package {
import mx.core.*;
public class MochiPreloaderMain_words6 extends ByteArrayAsset {
}
}//package
Section 28
//MochiPreloaderMain_words7 (MochiPreloaderMain_words7)
package {
import mx.core.*;
public class MochiPreloaderMain_words7 extends ByteArrayAsset {
}
}//package
Section 29
//MochiPreloaderMain_wordsAll (MochiPreloaderMain_wordsAll)
package {
import mx.core.*;
public class MochiPreloaderMain_wordsAll extends ByteArrayAsset {
}
}//package