initial commit, kind of working.
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package mochi.as3
|
||||
{
|
||||
public class MochiCoins
|
||||
{
|
||||
|
||||
public static var _inventory:MochiInventory;
|
||||
|
||||
public static const STORE_SHOW:String = "StoreShow";
|
||||
|
||||
public static const STORE_HIDE:String = "StoreHide";
|
||||
|
||||
public static const ITEM_OWNED:String = "ItemOwned";
|
||||
|
||||
public static const ITEM_NEW:String = "ItemNew";
|
||||
|
||||
public static const STORE_ITEMS:String = "StoreItems";
|
||||
|
||||
public static const ERROR:String = "Error";
|
||||
|
||||
public static const IO_ERROR:String = "IOError";
|
||||
|
||||
public static const NO_USER:String = "NoUser";
|
||||
|
||||
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
|
||||
|
||||
addEventListener(MochiSocial.LOGGED_IN,function(param1:Object):void
|
||||
{
|
||||
_inventory = new MochiInventory();
|
||||
});
|
||||
addEventListener(MochiSocial.LOGGED_OUT,function(param1:Object):void
|
||||
{
|
||||
_inventory = null;
|
||||
});
|
||||
|
||||
public function MochiCoins()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function get inventory() : MochiInventory
|
||||
{
|
||||
return _inventory;
|
||||
}
|
||||
|
||||
public static function getVersion() : String
|
||||
{
|
||||
return MochiServices.getVersion();
|
||||
}
|
||||
|
||||
public static function showStore(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("coins_showStore",{"options":param1},null,null);
|
||||
}
|
||||
|
||||
public static function showItem(param1:Object = null) : void
|
||||
{
|
||||
if(!param1 || typeof param1.item != "string")
|
||||
{
|
||||
return;
|
||||
}
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("coins_showItem",{"options":param1},null,null);
|
||||
}
|
||||
|
||||
public static function showVideo(param1:Object = null) : void
|
||||
{
|
||||
if(!param1 || typeof param1.item != "string")
|
||||
{
|
||||
return;
|
||||
}
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("coins_showVideo",{"options":param1},null,null);
|
||||
}
|
||||
|
||||
public static function getStoreItems() : void
|
||||
{
|
||||
MochiServices.send("coins_getStoreItems");
|
||||
}
|
||||
|
||||
public static function requestFunding(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("social_requestFunding",param1);
|
||||
}
|
||||
|
||||
public static function addEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.addEventListener(param1,param2);
|
||||
}
|
||||
|
||||
public static function triggerEvent(param1:String, param2:Object) : void
|
||||
{
|
||||
_dispatcher.triggerEvent(param1,param2);
|
||||
}
|
||||
|
||||
public static function removeEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.removeEventListener(param1,param2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package mochi.as3
|
||||
{
|
||||
public final class MochiDigits
|
||||
{
|
||||
|
||||
private var Fragment:Number;
|
||||
|
||||
private var Sibling:MochiDigits;
|
||||
|
||||
private var Encoder:Number;
|
||||
|
||||
public function MochiDigits(param1:Number = 0, param2:uint = 0)
|
||||
{
|
||||
super();
|
||||
this.Encoder = 0;
|
||||
this.setValue(param1,param2);
|
||||
}
|
||||
|
||||
public function get value() : Number
|
||||
{
|
||||
return Number(this.toString());
|
||||
}
|
||||
|
||||
public function set value(param1:Number) : void
|
||||
{
|
||||
this.setValue(param1);
|
||||
}
|
||||
|
||||
public function addValue(param1:Number) : void
|
||||
{
|
||||
this.value += param1;
|
||||
}
|
||||
|
||||
public function setValue(param1:Number = 0, param2:uint = 0) : void
|
||||
{
|
||||
var _loc3_:String = param1.toString();
|
||||
this.Fragment = _loc3_.charCodeAt(param2++) ^ this.Encoder;
|
||||
if(param2 < _loc3_.length)
|
||||
{
|
||||
this.Sibling = new MochiDigits(param1,param2);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Sibling = null;
|
||||
}
|
||||
this.reencode();
|
||||
}
|
||||
|
||||
public function reencode() : void
|
||||
{
|
||||
var _loc1_:uint = uint(int(2147483647 * Math.random()));
|
||||
this.Fragment ^= _loc1_ ^ this.Encoder;
|
||||
this.Encoder = _loc1_;
|
||||
}
|
||||
|
||||
public function toString() : String
|
||||
{
|
||||
var _loc1_:String = String.fromCharCode(this.Fragment ^ this.Encoder);
|
||||
if(this.Sibling != null)
|
||||
{
|
||||
_loc1_ += this.Sibling.toString();
|
||||
}
|
||||
return _loc1_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package mochi.as3
|
||||
{
|
||||
public class MochiEventDispatcher
|
||||
{
|
||||
|
||||
private var eventTable:Object;
|
||||
|
||||
public function MochiEventDispatcher()
|
||||
{
|
||||
super();
|
||||
this.eventTable = {};
|
||||
}
|
||||
|
||||
public function addEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
this.removeEventListener(param1,param2);
|
||||
this.eventTable[param1].push(param2);
|
||||
}
|
||||
|
||||
public function removeEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
var _loc3_:Object = null;
|
||||
if(this.eventTable[param1] == undefined)
|
||||
{
|
||||
this.eventTable[param1] = [];
|
||||
return;
|
||||
}
|
||||
for(_loc3_ in this.eventTable[param1])
|
||||
{
|
||||
if(this.eventTable[param1][_loc3_] == param2)
|
||||
{
|
||||
this.eventTable[param1].splice(Number(_loc3_),1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function triggerEvent(param1:String, param2:Object) : void
|
||||
{
|
||||
var _loc3_:Object = null;
|
||||
if(this.eventTable[param1] == undefined)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(_loc3_ in this.eventTable[param1])
|
||||
{
|
||||
this.eventTable[param1][_loc3_](param2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package mochi.as3
|
||||
{
|
||||
public class MochiEvents
|
||||
{
|
||||
|
||||
private static var gameStart:Number;
|
||||
|
||||
private static var levelStart:Number;
|
||||
|
||||
public static const ACHIEVEMENTS_OWNED:String = "AchievementOwned";
|
||||
|
||||
public static const ACHIEVEMENT_NEW:String = "AchievementReceived";
|
||||
|
||||
public static const GAME_ACHIEVEMENTS:String = "GameAchievements";
|
||||
|
||||
public static const ERROR:String = "Error";
|
||||
|
||||
public static const IO_ERROR:String = "IOError";
|
||||
|
||||
public static const IO_PENDING:String = "IOPending";
|
||||
|
||||
public static const ALIGN_TOP_LEFT:String = "ALIGN_TL";
|
||||
|
||||
public static const ALIGN_TOP:String = "ALIGN_T";
|
||||
|
||||
public static const ALIGN_TOP_RIGHT:String = "ALIGN_TR";
|
||||
|
||||
public static const ALIGN_LEFT:String = "ALIGN_L";
|
||||
|
||||
public static const ALIGN_CENTER:String = "ALIGN_C";
|
||||
|
||||
public static const ALIGN_RIGHT:String = "ALIGN_R";
|
||||
|
||||
public static const ALIGN_BOTTOM_LEFT:String = "ALIGN_BL";
|
||||
|
||||
public static const ALIGN_BOTTOM:String = "ALIGN_B";
|
||||
|
||||
public static const ALIGN_BOTTOM_RIGHT:String = "ALIGN_BR";
|
||||
|
||||
public static const FORMAT_SHORT:String = "ShortForm";
|
||||
|
||||
public static const FORMAT_LONG:String = "LongForm";
|
||||
|
||||
public static const FORMAT_NONE:String = "NoForm";
|
||||
|
||||
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
|
||||
|
||||
public function MochiEvents()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getVersion() : String
|
||||
{
|
||||
return MochiServices.getVersion();
|
||||
}
|
||||
|
||||
public static function getAchievements(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.send("events_getAchievements",param1);
|
||||
}
|
||||
|
||||
public static function unlockAchievement(param1:Object) : void
|
||||
{
|
||||
MochiServices.send("events_unlockAchievement",param1);
|
||||
}
|
||||
|
||||
public static function startSession(param1:String) : void
|
||||
{
|
||||
MochiServices.send("events_beginSession",{"achievementID":param1},null,null);
|
||||
}
|
||||
|
||||
public static function showAwards(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.stayOnTop();
|
||||
MochiServices.send("events_showAwards",param1);
|
||||
}
|
||||
|
||||
public static function setNotifications(param1:Object) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("events_setNotifications",param1,null,null);
|
||||
}
|
||||
|
||||
public static function addEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.addEventListener(param1,param2);
|
||||
}
|
||||
|
||||
public static function triggerEvent(param1:String, param2:Object) : void
|
||||
{
|
||||
_dispatcher.triggerEvent(param1,param2);
|
||||
}
|
||||
|
||||
public static function removeEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.removeEventListener(param1,param2);
|
||||
}
|
||||
|
||||
public static function startPlay(param1:String = "gameplay") : void
|
||||
{
|
||||
MochiServices.send("events_setRoundID",{"tag":String(param1)},null,null);
|
||||
}
|
||||
|
||||
public static function endPlay() : void
|
||||
{
|
||||
MochiServices.send("events_clearRoundID",null,null,null);
|
||||
}
|
||||
|
||||
public static function trackEvent(param1:String, param2:* = null) : void
|
||||
{
|
||||
MochiServices.send("events_trackEvent",{
|
||||
"tag":param1,
|
||||
"value":param2
|
||||
},null,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
package mochi.as3
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.utils.Proxy;
|
||||
import flash.utils.Timer;
|
||||
import flash.utils.flash_proxy;
|
||||
|
||||
use namespace flash_proxy;
|
||||
|
||||
public dynamic class MochiInventory extends Proxy
|
||||
{
|
||||
|
||||
private static const CONSUMER_KEY:String = "MochiConsumables";
|
||||
|
||||
private static const KEY_SALT:String = " syncMaint\x01";
|
||||
|
||||
public static const READY:String = "InvReady";
|
||||
|
||||
public static const WRITTEN:String = "InvWritten";
|
||||
|
||||
public static const ERROR:String = "Error";
|
||||
|
||||
public static const IO_ERROR:String = "IoError";
|
||||
|
||||
public static const VALUE_ERROR:String = "InvValueError";
|
||||
|
||||
public static const NOT_READY:String = "InvNotReady";
|
||||
|
||||
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
|
||||
|
||||
private var _timer:Timer;
|
||||
|
||||
private var _consumableProperties:Object;
|
||||
|
||||
private var _syncPending:Boolean;
|
||||
|
||||
private var _outstandingID:Number;
|
||||
|
||||
private var _syncID:Number;
|
||||
|
||||
private var _names:Array;
|
||||
|
||||
private var _storeSync:Object;
|
||||
|
||||
public function MochiInventory()
|
||||
{
|
||||
super();
|
||||
MochiCoins.addEventListener(MochiCoins.ITEM_OWNED,this.itemOwned);
|
||||
MochiCoins.addEventListener(MochiCoins.ITEM_NEW,this.newItems);
|
||||
MochiSocial.addEventListener(MochiSocial.LOGGED_IN,this.loggedIn);
|
||||
MochiSocial.addEventListener(MochiSocial.LOGGED_OUT,this.loggedOut);
|
||||
this._storeSync = new Object();
|
||||
this._syncPending = false;
|
||||
this._outstandingID = 0;
|
||||
this._syncID = 0;
|
||||
this._timer = new Timer(1000);
|
||||
this._timer.addEventListener(TimerEvent.TIMER,this.sync);
|
||||
this._timer.start();
|
||||
if(MochiSocial.loggedIn)
|
||||
{
|
||||
this.loggedIn();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.loggedOut();
|
||||
}
|
||||
}
|
||||
|
||||
public static function addEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.addEventListener(param1,param2);
|
||||
}
|
||||
|
||||
public static function triggerEvent(param1:String, param2:Object) : void
|
||||
{
|
||||
_dispatcher.triggerEvent(param1,param2);
|
||||
}
|
||||
|
||||
public static function removeEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.removeEventListener(param1,param2);
|
||||
}
|
||||
|
||||
public function release() : void
|
||||
{
|
||||
MochiCoins.removeEventListener(MochiCoins.ITEM_NEW,this.newItems);
|
||||
MochiSocial.removeEventListener(MochiSocial.LOGGED_IN,this.loggedIn);
|
||||
MochiSocial.removeEventListener(MochiSocial.LOGGED_OUT,this.loggedOut);
|
||||
}
|
||||
|
||||
private function loggedOut(param1:Object = null) : void
|
||||
{
|
||||
this._consumableProperties = null;
|
||||
}
|
||||
|
||||
private function loggedIn(param1:Object = null) : void
|
||||
{
|
||||
MochiUserData.get(CONSUMER_KEY,this.getConsumableBag);
|
||||
}
|
||||
|
||||
private function newItems(param1:Object) : void
|
||||
{
|
||||
if(!this[param1.id + KEY_SALT])
|
||||
{
|
||||
this[param1.id + KEY_SALT] = 0;
|
||||
}
|
||||
if(!this[param1.id])
|
||||
{
|
||||
this[param1.id] = 0;
|
||||
}
|
||||
this[param1.id + KEY_SALT] += param1.count;
|
||||
this[param1.id] += param1.count;
|
||||
if(Boolean(param1.privateProperties) && Boolean(param1.privateProperties.consumable))
|
||||
{
|
||||
if(!this[param1.privateProperties.tag])
|
||||
{
|
||||
this[param1.privateProperties.tag] = 0;
|
||||
}
|
||||
this[param1.privateProperties.tag] += param1.privateProperties.inc * param1.count;
|
||||
}
|
||||
}
|
||||
|
||||
private function itemOwned(param1:Object) : void
|
||||
{
|
||||
this._storeSync[param1.id] = {
|
||||
"properties":param1.properties,
|
||||
"count":param1.count
|
||||
};
|
||||
}
|
||||
|
||||
private function getConsumableBag(param1:MochiUserData) : void
|
||||
{
|
||||
var _loc2_:String = null;
|
||||
var _loc3_:Number = NaN;
|
||||
if(param1.error)
|
||||
{
|
||||
triggerEvent(ERROR,{
|
||||
"type":IO_ERROR,
|
||||
"error":param1.error
|
||||
});
|
||||
return;
|
||||
}
|
||||
this._consumableProperties = {};
|
||||
this._names = new Array();
|
||||
if(param1.data)
|
||||
{
|
||||
for(_loc2_ in param1.data)
|
||||
{
|
||||
this._names.push(_loc2_);
|
||||
this._consumableProperties[_loc2_] = new MochiDigits(param1.data[_loc2_]);
|
||||
}
|
||||
}
|
||||
for(_loc2_ in this._storeSync)
|
||||
{
|
||||
_loc3_ = Number(this._storeSync[_loc2_].count);
|
||||
if(this._consumableProperties[_loc2_ + KEY_SALT])
|
||||
{
|
||||
_loc3_ -= this._consumableProperties[_loc2_ + KEY_SALT].value;
|
||||
}
|
||||
if(_loc3_ != 0)
|
||||
{
|
||||
this.newItems({
|
||||
"id":_loc2_,
|
||||
"count":_loc3_,
|
||||
"properties":this._storeSync[_loc2_].properties
|
||||
});
|
||||
}
|
||||
}
|
||||
triggerEvent(READY,{});
|
||||
}
|
||||
|
||||
private function putConsumableBag(param1:MochiUserData) : void
|
||||
{
|
||||
this._syncPending = false;
|
||||
if(param1.error)
|
||||
{
|
||||
triggerEvent(ERROR,{
|
||||
"type":IO_ERROR,
|
||||
"error":param1.error
|
||||
});
|
||||
this._outstandingID = -1;
|
||||
}
|
||||
triggerEvent(WRITTEN,{});
|
||||
}
|
||||
|
||||
private function sync(param1:Event = null) : void
|
||||
{
|
||||
var _loc3_:String = null;
|
||||
if(this._syncPending || this._syncID == this._outstandingID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this._outstandingID = this._syncID;
|
||||
var _loc2_:Object = {};
|
||||
for(_loc3_ in this._consumableProperties)
|
||||
{
|
||||
_loc2_[_loc3_] = MochiDigits(this._consumableProperties[_loc3_]).value;
|
||||
}
|
||||
MochiUserData.put(CONSUMER_KEY,_loc2_,this.putConsumableBag);
|
||||
this._syncPending = true;
|
||||
}
|
||||
|
||||
override flash_proxy function getProperty(param1:*) : *
|
||||
{
|
||||
if(this._consumableProperties == null)
|
||||
{
|
||||
triggerEvent(ERROR,{"type":NOT_READY});
|
||||
return -1;
|
||||
}
|
||||
if(this._consumableProperties[param1])
|
||||
{
|
||||
return MochiDigits(this._consumableProperties[param1]).value;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
override flash_proxy function deleteProperty(param1:*) : Boolean
|
||||
{
|
||||
if(!this._consumableProperties[param1])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this._names.splice(this._names.indexOf(param1),1);
|
||||
delete this._consumableProperties[param1];
|
||||
return true;
|
||||
}
|
||||
|
||||
override flash_proxy function hasProperty(param1:*) : Boolean
|
||||
{
|
||||
if(this._consumableProperties == null)
|
||||
{
|
||||
triggerEvent(ERROR,{"type":NOT_READY});
|
||||
return false;
|
||||
}
|
||||
if(this._consumableProperties[param1] == undefined)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
override flash_proxy function setProperty(param1:*, param2:*) : void
|
||||
{
|
||||
var _loc3_:MochiDigits = null;
|
||||
if(this._consumableProperties == null)
|
||||
{
|
||||
triggerEvent(ERROR,{"type":NOT_READY});
|
||||
return;
|
||||
}
|
||||
if(!(param2 is Number))
|
||||
{
|
||||
triggerEvent(ERROR,{
|
||||
"type":VALUE_ERROR,
|
||||
"error":"Invalid type",
|
||||
"arg":param2
|
||||
});
|
||||
return;
|
||||
}
|
||||
if(this._consumableProperties[param1])
|
||||
{
|
||||
_loc3_ = MochiDigits(this._consumableProperties[param1]);
|
||||
if(_loc3_.value == param2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_loc3_.value = param2;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._names.push(param1);
|
||||
this._consumableProperties[param1] = new MochiDigits(param2);
|
||||
}
|
||||
++this._syncID;
|
||||
}
|
||||
|
||||
override flash_proxy function nextNameIndex(param1:int) : int
|
||||
{
|
||||
return param1 >= this._names.length ? 0 : int(param1 + 1);
|
||||
}
|
||||
|
||||
override flash_proxy function nextName(param1:int) : String
|
||||
{
|
||||
return this._names[param1 - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,808 @@
|
||||
package mochi.as3
|
||||
{
|
||||
import flash.display.DisplayObject;
|
||||
import flash.display.DisplayObjectContainer;
|
||||
import flash.display.Loader;
|
||||
import flash.display.LoaderInfo;
|
||||
import flash.display.MovieClip;
|
||||
import flash.display.Sprite;
|
||||
import flash.events.Event;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.TimerEvent;
|
||||
import flash.geom.Rectangle;
|
||||
import flash.net.LocalConnection;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLVariables;
|
||||
import flash.system.Capabilities;
|
||||
import flash.system.Security;
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
import flash.utils.Timer;
|
||||
|
||||
public class MochiServices
|
||||
{
|
||||
|
||||
private static var _id:String;
|
||||
|
||||
private static var _container:Object;
|
||||
|
||||
private static var _clip:MovieClip;
|
||||
|
||||
private static var _loader:Loader;
|
||||
|
||||
private static var _timer:Timer;
|
||||
|
||||
private static var _preserved:Object;
|
||||
|
||||
private static var _swfVersion:String;
|
||||
|
||||
private static var _sendChannel:LocalConnection;
|
||||
|
||||
private static var _sendChannelName:String;
|
||||
|
||||
public static var onError:Object;
|
||||
|
||||
private static var _mochiLocalConnection:MovieClip;
|
||||
|
||||
private static var _queue:Array;
|
||||
|
||||
private static var _nextCallbackID:Number;
|
||||
|
||||
private static var _callbacks:Object;
|
||||
|
||||
public static const CONNECTED:String = "onConnected";
|
||||
|
||||
private static var _servURL:String = "http://www.mochiads.com/static/lib/services/";
|
||||
|
||||
private static var _services:String = "services.swf";
|
||||
|
||||
private static var _mochiLC:String = "MochiLC.swf";
|
||||
|
||||
private static var _listenChannelName:String = "__ms_";
|
||||
|
||||
private static var _connecting:Boolean = false;
|
||||
|
||||
private static var _connected:Boolean = false;
|
||||
|
||||
public static var netup:Boolean = true;
|
||||
|
||||
public static var netupAttempted:Boolean = false;
|
||||
|
||||
public static var widget:Boolean = false;
|
||||
|
||||
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
|
||||
|
||||
public function MochiServices()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function get id() : String
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public static function get clip() : Object
|
||||
{
|
||||
return _container;
|
||||
}
|
||||
|
||||
public static function get childClip() : Object
|
||||
{
|
||||
return _clip;
|
||||
}
|
||||
|
||||
public static function getVersion() : String
|
||||
{
|
||||
return "3.9.4 as3";
|
||||
}
|
||||
|
||||
public static function allowDomains(param1:String) : String
|
||||
{
|
||||
var _loc2_:String = null;
|
||||
if(Security.sandboxType != "application")
|
||||
{
|
||||
Security.allowDomain("*");
|
||||
Security.allowInsecureDomain("*");
|
||||
}
|
||||
if(param1.indexOf("http://") != -1)
|
||||
{
|
||||
_loc2_ = param1.split("/")[2].split(":")[0];
|
||||
if(Security.sandboxType != "application")
|
||||
{
|
||||
Security.allowDomain(_loc2_);
|
||||
Security.allowInsecureDomain(_loc2_);
|
||||
}
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
public static function isNetworkAvailable() : Boolean
|
||||
{
|
||||
return Security.sandboxType != "localWithFile";
|
||||
}
|
||||
|
||||
public static function set comChannelName(param1:String) : void
|
||||
{
|
||||
if(param1 != null)
|
||||
{
|
||||
if(param1.length > 3)
|
||||
{
|
||||
_sendChannelName = param1 + "_fromgame";
|
||||
initComChannels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function get connected() : Boolean
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
public static function warnID(param1:String, param2:Boolean) : void
|
||||
{
|
||||
param1 = param1.toLowerCase();
|
||||
if(param1.length != 16)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(param1 == "1e113c7239048b3f")
|
||||
{
|
||||
if(param2)
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(param1 == "84993a1de4031cd8")
|
||||
{
|
||||
if(param2)
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
var _loc3_:Number = 0;
|
||||
while(_loc3_ < param1.length)
|
||||
{
|
||||
switch(param1.charAt(_loc3_))
|
||||
{
|
||||
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:
|
||||
return;
|
||||
}
|
||||
_loc3_++;
|
||||
}
|
||||
}
|
||||
|
||||
public static function connect(param1:String, param2:Object, param3:Object = null) : void
|
||||
{
|
||||
var id:String = param1;
|
||||
var clip:Object = param2;
|
||||
var onError:Object = param3;
|
||||
warnID(id,false);
|
||||
if(onError != null)
|
||||
{
|
||||
MochiServices.onError = onError;
|
||||
}
|
||||
else if(MochiServices.onError == null)
|
||||
{
|
||||
MochiServices.onError = function(param1:String):void
|
||||
{
|
||||
};
|
||||
}
|
||||
if(clip is DisplayObject)
|
||||
{
|
||||
if(clip.stage == null)
|
||||
{
|
||||
}
|
||||
if(!_connected && _clip == null)
|
||||
{
|
||||
_connecting = true;
|
||||
init(id,clip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
try
|
||||
{
|
||||
_mochiLocalConnection.close();
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
if(_timer != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_timer.stop();
|
||||
_timer.removeEventListener(TimerEvent.TIMER,connectWait);
|
||||
_timer = null;
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function stayOnTop() : void
|
||||
{
|
||||
_container.addEventListener(Event.ENTER_FRAME,MochiServices.bringToTop,false,0,true);
|
||||
if(_clip != null)
|
||||
{
|
||||
_clip.visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function doClose() : void
|
||||
{
|
||||
_container.removeEventListener(Event.ENTER_FRAME,MochiServices.bringToTop);
|
||||
}
|
||||
|
||||
public static function bringToTop(param1:Event = null) : void
|
||||
{
|
||||
var e:Event = param1;
|
||||
if(MochiServices.clip != null && MochiServices.childClip != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(MochiServices.clip.numChildren > 1)
|
||||
{
|
||||
MochiServices.clip.setChildIndex(MochiServices.childClip,MochiServices.clip.numChildren - 1);
|
||||
}
|
||||
}
|
||||
catch(errorObject:Error)
|
||||
{
|
||||
_container.removeEventListener(Event.ENTER_FRAME,MochiServices.bringToTop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function init(param1:String, param2:Object) : void
|
||||
{
|
||||
_id = param1;
|
||||
if(param2 != null)
|
||||
{
|
||||
_container = param2;
|
||||
loadCommunicator(param1,_container);
|
||||
}
|
||||
}
|
||||
|
||||
public static function setContainer(param1:Object = null, param2:Boolean = true) : void
|
||||
{
|
||||
if(_clip.parent)
|
||||
{
|
||||
_clip.parent.removeChild(_clip);
|
||||
}
|
||||
if(param1 != null)
|
||||
{
|
||||
if(param1 is DisplayObjectContainer)
|
||||
{
|
||||
_container = param1;
|
||||
}
|
||||
}
|
||||
if(param2)
|
||||
{
|
||||
if(_container is DisplayObjectContainer)
|
||||
{
|
||||
DisplayObjectContainer(_container).addChild(_clip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function loadCommunicator(param1:String, param2:Object) : MovieClip
|
||||
{
|
||||
if(_clip != null)
|
||||
{
|
||||
return _clip;
|
||||
}
|
||||
if(!MochiServices.isNetworkAvailable())
|
||||
{
|
||||
MochiServices.onError("NotConnected");
|
||||
return null;
|
||||
}
|
||||
if(urlOptions(param2).servURL)
|
||||
{
|
||||
_servURL = urlOptions(param2).servURL;
|
||||
}
|
||||
var _loc3_:String = _servURL + _services;
|
||||
if(urlOptions(param2).servicesURL)
|
||||
{
|
||||
_loc3_ = urlOptions(param2).servicesURL;
|
||||
}
|
||||
_listenChannelName += Math.floor(new Date().time) + "_" + Math.floor(Math.random() * 99999);
|
||||
MochiServices.allowDomains(_loc3_);
|
||||
_clip = new MovieClip();
|
||||
loadLCBridge(_clip);
|
||||
_loader = new Loader();
|
||||
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,detach);
|
||||
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,detach);
|
||||
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadError);
|
||||
var _loc4_:URLRequest = new URLRequest(_loc3_);
|
||||
var _loc5_:URLVariables = new URLVariables();
|
||||
_loc5_.listenLC = _listenChannelName;
|
||||
_loc5_.mochiad_options = param2.loaderInfo.parameters.mochiad_options;
|
||||
_loc5_.api_version = getVersion();
|
||||
if(widget)
|
||||
{
|
||||
_loc5_.widget = true;
|
||||
}
|
||||
_loc4_.data = _loc5_;
|
||||
_loader.load(_loc4_);
|
||||
_clip.addChild(_loader);
|
||||
_sendChannel = new LocalConnection();
|
||||
_queue = [];
|
||||
_nextCallbackID = 0;
|
||||
_callbacks = {};
|
||||
_timer = new Timer(10000,1);
|
||||
_timer.addEventListener(TimerEvent.TIMER,connectWait);
|
||||
_timer.start();
|
||||
return _clip;
|
||||
}
|
||||
|
||||
private static function detach(param1:Event) : void
|
||||
{
|
||||
var _loc2_:LoaderInfo = LoaderInfo(param1.target);
|
||||
_loc2_.removeEventListener(Event.COMPLETE,detach);
|
||||
_loc2_.removeEventListener(IOErrorEvent.IO_ERROR,detach);
|
||||
_loc2_.removeEventListener(Event.COMPLETE,loadLCBridgeComplete);
|
||||
_loc2_.removeEventListener(IOErrorEvent.IO_ERROR,loadError);
|
||||
}
|
||||
|
||||
private static function loadLCBridge(param1:Object) : void
|
||||
{
|
||||
var _loc2_:Loader = new Loader();
|
||||
var _loc3_:String = _servURL + _mochiLC;
|
||||
var _loc4_:URLRequest = new URLRequest(_loc3_);
|
||||
_loc2_.contentLoaderInfo.addEventListener(Event.COMPLETE,detach);
|
||||
_loc2_.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,detach);
|
||||
_loc2_.contentLoaderInfo.addEventListener(Event.COMPLETE,loadLCBridgeComplete);
|
||||
_loc2_.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadError);
|
||||
_loc2_.load(_loc4_);
|
||||
param1.addChild(_loc2_);
|
||||
}
|
||||
|
||||
private static function loadLCBridgeComplete(param1:Event) : void
|
||||
{
|
||||
var _loc2_:Loader = LoaderInfo(param1.target).loader;
|
||||
_mochiLocalConnection = MovieClip(_loc2_.content);
|
||||
listen();
|
||||
}
|
||||
|
||||
private static function loadError(param1:Object) : void
|
||||
{
|
||||
_clip._mochiad_ctr_failed = true;
|
||||
MochiServices.disconnect();
|
||||
MochiServices.onError("IOError");
|
||||
}
|
||||
|
||||
public static function connectWait(param1:TimerEvent) : void
|
||||
{
|
||||
if(!_connected)
|
||||
{
|
||||
_clip._mochiad_ctr_failed = true;
|
||||
MochiServices.disconnect();
|
||||
MochiServices.onError("IOError");
|
||||
}
|
||||
else
|
||||
{
|
||||
_timer.stop();
|
||||
_timer.removeEventListener(TimerEvent.TIMER,connectWait);
|
||||
_timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function listen() : void
|
||||
{
|
||||
_mochiLocalConnection.connect(_listenChannelName);
|
||||
_clip.handshake = function(param1:Object):void
|
||||
{
|
||||
MochiServices.comChannelName = param1.newChannel;
|
||||
};
|
||||
}
|
||||
|
||||
private static function initComChannels() : void
|
||||
{
|
||||
if(!_connected)
|
||||
{
|
||||
_connecting = false;
|
||||
_connected = true;
|
||||
_mochiLocalConnection.send(_sendChannelName,"onReceive",{"methodName":"handshakeDone"});
|
||||
_mochiLocalConnection.send(_sendChannelName,"onReceive",{
|
||||
"methodName":"registerGame",
|
||||
"preserved":_preserved,
|
||||
"id":_id,
|
||||
"version":getVersion(),
|
||||
"parentURL":_container.loaderInfo.loaderURL
|
||||
});
|
||||
_clip.onReceive = onReceive;
|
||||
_clip.onEvent = onEvent;
|
||||
_clip.onError = function():void
|
||||
{
|
||||
MochiServices.onError("IOError");
|
||||
};
|
||||
while(_queue.length > 0)
|
||||
{
|
||||
_mochiLocalConnection.send(_sendChannelName,"onReceive",_queue.shift());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function onReceive(param1:Object) : void
|
||||
{
|
||||
var method:*;
|
||||
var methodName:String;
|
||||
var obj:Object;
|
||||
var pkg:Object = param1;
|
||||
var cb:String = pkg.callbackID;
|
||||
var cblst:Object = _callbacks[cb];
|
||||
if(!cblst)
|
||||
{
|
||||
return;
|
||||
}
|
||||
method = cblst.callbackMethod;
|
||||
methodName = "";
|
||||
obj = cblst.callbackObject;
|
||||
if(Boolean(obj) && typeof method == "string")
|
||||
{
|
||||
methodName = method;
|
||||
if(obj[method] != null)
|
||||
{
|
||||
method = obj[method];
|
||||
}
|
||||
}
|
||||
if(method != undefined)
|
||||
{
|
||||
try
|
||||
{
|
||||
method.apply(obj,pkg.args);
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if(obj != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
obj(pkg.args);
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
delete _callbacks[cb];
|
||||
}
|
||||
|
||||
private static function onEvent(param1:Object) : void
|
||||
{
|
||||
var _loc2_:String = param1.target;
|
||||
var _loc3_:String = param1.event;
|
||||
switch(_loc2_)
|
||||
{
|
||||
case "services":
|
||||
MochiServices.triggerEvent(param1.event,param1.args);
|
||||
break;
|
||||
case "events":
|
||||
MochiEvents.triggerEvent(param1.event,param1.args);
|
||||
break;
|
||||
case "coins":
|
||||
MochiCoins.triggerEvent(param1.event,param1.args);
|
||||
break;
|
||||
case "social":
|
||||
MochiSocial.triggerEvent(param1.event,param1.args);
|
||||
}
|
||||
}
|
||||
|
||||
private static function flush(param1:Boolean) : void
|
||||
{
|
||||
var _loc2_:Object = null;
|
||||
var _loc3_:Object = null;
|
||||
if(Boolean(_clip) && Boolean(_queue))
|
||||
{
|
||||
while(_queue.length > 0)
|
||||
{
|
||||
_loc2_ = _queue.shift();
|
||||
_loc3_ = null;
|
||||
if(_loc2_ != null)
|
||||
{
|
||||
if(_loc2_.callbackID != null)
|
||||
{
|
||||
_loc3_ = _callbacks[_loc2_.callbackID];
|
||||
}
|
||||
delete _callbacks[_loc2_.callbackID];
|
||||
if(param1 && _loc3_ != null)
|
||||
{
|
||||
handleError(_loc2_.args,_loc3_.callbackObject,_loc3_.callbackMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function handleError(param1:Object, param2:Object, param3:Object) : void
|
||||
{
|
||||
var args:Object = param1;
|
||||
var callbackObject:Object = param2;
|
||||
var callbackMethod:Object = param3;
|
||||
if(args != null)
|
||||
{
|
||||
if(args.onError != null)
|
||||
{
|
||||
args.onError("NotConnected");
|
||||
}
|
||||
if(args.options != null && args.options.onError != null)
|
||||
{
|
||||
args.options.onError("NotConnected");
|
||||
}
|
||||
}
|
||||
if(callbackMethod != null)
|
||||
{
|
||||
args = {};
|
||||
args.error = true;
|
||||
args.errorCode = "NotConnected";
|
||||
if(callbackObject != null && callbackMethod is String)
|
||||
{
|
||||
try
|
||||
{
|
||||
callbackObject[callbackMethod](args);
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if(callbackMethod != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
callbackMethod.apply(args);
|
||||
}
|
||||
catch(error:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function send(param1:String, param2:Object = null, param3:Object = null, param4:Object = null) : void
|
||||
{
|
||||
if(_connected)
|
||||
{
|
||||
_mochiLocalConnection.send(_sendChannelName,"onReceive",{
|
||||
"methodName":param1,
|
||||
"args":param2,
|
||||
"callbackID":_nextCallbackID
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_clip == null || !_connecting)
|
||||
{
|
||||
handleError(param2,param3,param4);
|
||||
flush(true);
|
||||
return;
|
||||
}
|
||||
_queue.push({
|
||||
"methodName":param1,
|
||||
"args":param2,
|
||||
"callbackID":_nextCallbackID
|
||||
});
|
||||
}
|
||||
if(_clip != null)
|
||||
{
|
||||
if(_callbacks != null)
|
||||
{
|
||||
_callbacks[_nextCallbackID] = {
|
||||
"callbackObject":param3,
|
||||
"callbackMethod":param4
|
||||
};
|
||||
++_nextCallbackID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function urlOptions(param1:Object) : Object
|
||||
{
|
||||
var _loc3_:String = null;
|
||||
var _loc4_:Array = null;
|
||||
var _loc5_:Number = NaN;
|
||||
var _loc6_:Array = null;
|
||||
var _loc2_:Object = {};
|
||||
if(param1.stage)
|
||||
{
|
||||
_loc3_ = param1.stage.loaderInfo.parameters.mochiad_options;
|
||||
}
|
||||
else
|
||||
{
|
||||
_loc3_ = param1.loaderInfo.parameters.mochiad_options;
|
||||
}
|
||||
if(_loc3_)
|
||||
{
|
||||
_loc4_ = _loc3_.split("&");
|
||||
_loc5_ = 0;
|
||||
while(_loc5_ < _loc4_.length)
|
||||
{
|
||||
_loc6_ = _loc4_[_loc5_].split("=");
|
||||
_loc2_[unescape(_loc6_[0])] = unescape(_loc6_[1]);
|
||||
_loc5_++;
|
||||
}
|
||||
}
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
public static function addLinkEvent(param1:String, param2:String, param3:DisplayObjectContainer, param4:Function = null) : void
|
||||
{
|
||||
var s:String;
|
||||
var i:Number;
|
||||
var avm1Click:DisplayObject = null;
|
||||
var x:String = null;
|
||||
var req:URLRequest = null;
|
||||
var loader:Loader = null;
|
||||
var setURL:Function = null;
|
||||
var err:Function = null;
|
||||
var complete:Function = null;
|
||||
var url:String = param1;
|
||||
var burl:String = param2;
|
||||
var btn:DisplayObjectContainer = param3;
|
||||
var onClick:Function = param4;
|
||||
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;
|
||||
s = "?";
|
||||
i = 0;
|
||||
for(x in vars)
|
||||
{
|
||||
if(i != 0)
|
||||
{
|
||||
s += "&";
|
||||
}
|
||||
i++;
|
||||
s = s + x + "=" + escape(vars[x]);
|
||||
}
|
||||
req = new URLRequest("http://link.mochiads.com/linkping.swf");
|
||||
loader = new Loader();
|
||||
setURL = function(param1:String):void
|
||||
{
|
||||
if(avm1Click)
|
||||
{
|
||||
btn.removeChild(avm1Click);
|
||||
}
|
||||
avm1Click = clickMovie(param1,onClick);
|
||||
var _loc2_:Rectangle = btn.getBounds(btn);
|
||||
btn.addChild(avm1Click);
|
||||
avm1Click.x = _loc2_.x;
|
||||
avm1Click.y = _loc2_.y;
|
||||
avm1Click.scaleX = 0.01 * _loc2_.width;
|
||||
avm1Click.scaleY = 0.01 * _loc2_.height;
|
||||
};
|
||||
err = function(param1:Object):void
|
||||
{
|
||||
netup = false;
|
||||
param1.target.removeEventListener(param1.type,arguments.callee);
|
||||
setURL(burl);
|
||||
};
|
||||
complete = function(param1:Object):void
|
||||
{
|
||||
param1.target.removeEventListener(param1.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 clickMovie(param1:String, param2:Function) : MovieClip
|
||||
{
|
||||
var _loc4_:int = 0;
|
||||
var _loc14_:Loader = null;
|
||||
var _loc3_: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,255,0,255,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 _loc5_:Array = [104,0,31,64,0,7,208,0,0,12,1,0,67,2,255,255,255,63,3];
|
||||
var _loc6_:Array = [0,64,0,0,0];
|
||||
var _loc7_:MovieClip = new MovieClip();
|
||||
var _loc8_:LocalConnection = new LocalConnection();
|
||||
var _loc9_:String = "_click_" + Math.floor(Math.random() * 999999) + "_" + Math.floor(new Date().time);
|
||||
_loc8_ = new LocalConnection();
|
||||
_loc7_.lc = _loc8_;
|
||||
_loc7_.click = param2;
|
||||
_loc8_.client = _loc7_;
|
||||
_loc8_.connect(_loc9_);
|
||||
var _loc10_:ByteArray = new ByteArray();
|
||||
var _loc11_:ByteArray = new ByteArray();
|
||||
_loc11_.endian = Endian.LITTLE_ENDIAN;
|
||||
_loc11_.writeShort(1);
|
||||
_loc11_.writeUTFBytes(param1 + " " + _loc9_);
|
||||
_loc11_.writeByte(0);
|
||||
var _loc12_:uint = _loc3_.length + _loc11_.length + 4;
|
||||
var _loc13_:uint = _loc12_ + 35;
|
||||
_loc10_.endian = Endian.LITTLE_ENDIAN;
|
||||
_loc10_.writeUTFBytes("FWS");
|
||||
_loc10_.writeByte(8);
|
||||
_loc10_.writeUnsignedInt(_loc13_);
|
||||
for each(_loc4_ in _loc5_)
|
||||
{
|
||||
_loc10_.writeByte(_loc4_);
|
||||
}
|
||||
_loc10_.writeUnsignedInt(_loc12_);
|
||||
_loc10_.writeByte(136);
|
||||
_loc10_.writeShort(_loc11_.length);
|
||||
_loc10_.writeBytes(_loc11_);
|
||||
for each(_loc4_ in _loc3_)
|
||||
{
|
||||
_loc10_.writeByte(_loc4_);
|
||||
}
|
||||
for each(_loc4_ in _loc6_)
|
||||
{
|
||||
_loc10_.writeByte(_loc4_);
|
||||
}
|
||||
_loc14_ = new Loader();
|
||||
_loc14_.loadBytes(_loc10_);
|
||||
_loc7_.addChild(_loc14_);
|
||||
return _loc7_;
|
||||
}
|
||||
|
||||
public static function addEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.addEventListener(param1,param2);
|
||||
}
|
||||
|
||||
public static function triggerEvent(param1:String, param2:Object) : void
|
||||
{
|
||||
_dispatcher.triggerEvent(param1,param2);
|
||||
}
|
||||
|
||||
public static function removeEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.removeEventListener(param1,param2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
package mochi.as3
|
||||
{
|
||||
public class MochiSocial
|
||||
{
|
||||
|
||||
public static const LOGGED_IN:String = "LoggedIn";
|
||||
|
||||
public static const LOGGED_OUT:String = "LoggedOut";
|
||||
|
||||
public static const LOGIN_SHOW:String = "LoginShow";
|
||||
|
||||
public static const LOGIN_HIDE:String = "LoginHide";
|
||||
|
||||
public static const LOGIN_SHOWN:String = "LoginShown";
|
||||
|
||||
public static const PROFILE_SHOW:String = "ProfileShow";
|
||||
|
||||
public static const PROFILE_HIDE:String = "ProfileHide";
|
||||
|
||||
public static const PROPERTIES_SAVED:String = "PropertySaved";
|
||||
|
||||
public static const WIDGET_LOADED:String = "WidgetLoaded";
|
||||
|
||||
public static const FRIEND_LIST:String = "FriendsList";
|
||||
|
||||
public static const PROFILE_DATA:String = "ProfileData";
|
||||
|
||||
public static const GAMEPLAY_DATA:String = "GameplayData";
|
||||
|
||||
public static const ACTION_CANCELED:String = "onCancel";
|
||||
|
||||
public static const ACTION_COMPLETE:String = "onComplete";
|
||||
|
||||
public static const USER_INFO:String = "UserInfo";
|
||||
|
||||
public static const ERROR:String = "Error";
|
||||
|
||||
public static const IO_ERROR:String = "IOError";
|
||||
|
||||
public static const NO_USER:String = "NoUser";
|
||||
|
||||
public static const PROPERTIES_SIZE:String = "PropertiesSize";
|
||||
|
||||
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
|
||||
|
||||
public static var _user_info:Object = null;
|
||||
|
||||
MochiSocial.addEventListener(MochiSocial.LOGGED_IN,function(param1:Object):void
|
||||
{
|
||||
_user_info = param1;
|
||||
});
|
||||
MochiSocial.addEventListener(MochiSocial.LOGGED_OUT,function(param1:Object):void
|
||||
{
|
||||
_user_info = null;
|
||||
});
|
||||
|
||||
public function MochiSocial()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public static function getVersion() : String
|
||||
{
|
||||
return MochiServices.getVersion();
|
||||
}
|
||||
|
||||
public static function getAPIURL() : String
|
||||
{
|
||||
if(!_user_info)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _user_info.api_url;
|
||||
}
|
||||
|
||||
public static function getAPIToken() : String
|
||||
{
|
||||
if(!_user_info)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _user_info.api_token;
|
||||
}
|
||||
|
||||
public static function showLoginWidget(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("social_showLoginWidget",{"options":param1});
|
||||
}
|
||||
|
||||
public static function hideLoginWidget() : void
|
||||
{
|
||||
MochiServices.send("social_hideLoginWidget");
|
||||
}
|
||||
|
||||
public static function requestLogin(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("social_requestLogin",param1);
|
||||
}
|
||||
|
||||
public static function showProfile(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.stayOnTop();
|
||||
MochiServices.send("social_showProfile",param1);
|
||||
}
|
||||
|
||||
public static function saveUserProperties(param1:Object) : void
|
||||
{
|
||||
MochiServices.send("social_saveUserProperties",param1);
|
||||
}
|
||||
|
||||
public static function getFriendsList(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.send("social_getFriendsList",param1);
|
||||
}
|
||||
|
||||
public static function postToStream(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("social_postToStream",param1);
|
||||
}
|
||||
|
||||
public static function inviteFriends(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("social_inviteFriends",param1);
|
||||
}
|
||||
|
||||
public static function requestFan(param1:Object = null) : void
|
||||
{
|
||||
MochiServices.setContainer();
|
||||
MochiServices.bringToTop();
|
||||
MochiServices.send("social_requestFan",param1);
|
||||
}
|
||||
|
||||
public static function addEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.addEventListener(param1,param2);
|
||||
}
|
||||
|
||||
public static function get loggedIn() : Boolean
|
||||
{
|
||||
return _user_info != null;
|
||||
}
|
||||
|
||||
public static function triggerEvent(param1:String, param2:Object) : void
|
||||
{
|
||||
_dispatcher.triggerEvent(param1,param2);
|
||||
}
|
||||
|
||||
public static function removeEventListener(param1:String, param2:Function) : void
|
||||
{
|
||||
_dispatcher.removeEventListener(param1,param2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
package mochi.as3
|
||||
{
|
||||
import flash.events.Event;
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.IOErrorEvent;
|
||||
import flash.events.SecurityErrorEvent;
|
||||
import flash.net.ObjectEncoding;
|
||||
import flash.net.URLLoader;
|
||||
import flash.net.URLLoaderDataFormat;
|
||||
import flash.net.URLRequest;
|
||||
import flash.net.URLRequestHeader;
|
||||
import flash.net.URLRequestMethod;
|
||||
import flash.net.URLVariables;
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
public class MochiUserData extends EventDispatcher
|
||||
{
|
||||
|
||||
public var _loader:URLLoader;
|
||||
|
||||
public var key:String = null;
|
||||
|
||||
public var data:* = null;
|
||||
|
||||
public var error:Event = null;
|
||||
|
||||
public var operation:String = null;
|
||||
|
||||
public var callback:Function = null;
|
||||
|
||||
public function MochiUserData(param1:String = "", param2:Function = null)
|
||||
{
|
||||
super();
|
||||
this.key = param1;
|
||||
this.callback = param2;
|
||||
}
|
||||
|
||||
public static function get(param1:String, param2:Function) : void
|
||||
{
|
||||
var _loc3_:MochiUserData = new MochiUserData(param1,param2);
|
||||
_loc3_.getEvent();
|
||||
}
|
||||
|
||||
public static function put(param1:String, param2:*, param3:Function) : void
|
||||
{
|
||||
var _loc4_:MochiUserData = new MochiUserData(param1,param3);
|
||||
_loc4_.putEvent(param2);
|
||||
}
|
||||
|
||||
public function serialize(param1:*) : ByteArray
|
||||
{
|
||||
var _loc2_:ByteArray = new ByteArray();
|
||||
_loc2_.objectEncoding = ObjectEncoding.AMF3;
|
||||
_loc2_.writeObject(param1);
|
||||
_loc2_.compress();
|
||||
return _loc2_;
|
||||
}
|
||||
|
||||
public function deserialize(param1:ByteArray) : *
|
||||
{
|
||||
param1.objectEncoding = ObjectEncoding.AMF3;
|
||||
param1.uncompress();
|
||||
return param1.readObject();
|
||||
}
|
||||
|
||||
public function request(param1:String, param2:ByteArray) : void
|
||||
{
|
||||
var api_url:String;
|
||||
var api_token:String;
|
||||
var args:URLVariables;
|
||||
var req:URLRequest;
|
||||
var _operation:String = param1;
|
||||
var _data:ByteArray = param2;
|
||||
this.operation = _operation;
|
||||
api_url = MochiSocial.getAPIURL();
|
||||
api_token = MochiSocial.getAPIToken();
|
||||
if(api_url == null || api_token == null)
|
||||
{
|
||||
this.errorHandler(new IOErrorEvent(IOErrorEvent.IO_ERROR,false,false,"not logged in"));
|
||||
return;
|
||||
}
|
||||
this._loader = new URLLoader();
|
||||
args = new URLVariables();
|
||||
args.op = _operation;
|
||||
args.key = this.key;
|
||||
req = new URLRequest(MochiSocial.getAPIURL() + "/" + "MochiUserData?" + args.toString());
|
||||
req.method = URLRequestMethod.POST;
|
||||
req.contentType = "application/x-mochi-userdata";
|
||||
req.requestHeaders = [new URLRequestHeader("x-mochi-services-version",MochiServices.getVersion()),new URLRequestHeader("x-mochi-api-token",api_token)];
|
||||
req.data = _data;
|
||||
this._loader.dataFormat = URLLoaderDataFormat.BINARY;
|
||||
this._loader.addEventListener(Event.COMPLETE,this.completeHandler);
|
||||
this._loader.addEventListener(IOErrorEvent.IO_ERROR,this.errorHandler);
|
||||
this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.securityErrorHandler);
|
||||
try
|
||||
{
|
||||
this._loader.load(req);
|
||||
}
|
||||
catch(e:SecurityError)
|
||||
{
|
||||
errorHandler(new IOErrorEvent(IOErrorEvent.IO_ERROR,false,false,"security error: " + e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public function completeHandler(param1:Event) : void
|
||||
{
|
||||
var event:Event = param1;
|
||||
try
|
||||
{
|
||||
if(this._loader.data.length)
|
||||
{
|
||||
this.data = this.deserialize(this._loader.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.data = null;
|
||||
}
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
errorHandler(new IOErrorEvent(IOErrorEvent.IO_ERROR,false,false,"deserialize error: " + e.toString()));
|
||||
return;
|
||||
}
|
||||
if(this.callback != null)
|
||||
{
|
||||
this.performCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatchEvent(event);
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
|
||||
public function errorHandler(param1:IOErrorEvent) : void
|
||||
{
|
||||
this.data = null;
|
||||
this.error = param1;
|
||||
if(this.callback != null)
|
||||
{
|
||||
this.performCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
dispatchEvent(param1);
|
||||
}
|
||||
this.close();
|
||||
}
|
||||
|
||||
public function securityErrorHandler(param1:SecurityErrorEvent) : void
|
||||
{
|
||||
this.errorHandler(new IOErrorEvent(IOErrorEvent.IO_ERROR,false,false,"security error: " + param1.toString()));
|
||||
}
|
||||
|
||||
public function performCallback() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
this.callback(this);
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public function close() : void
|
||||
{
|
||||
if(this._loader)
|
||||
{
|
||||
this._loader.removeEventListener(Event.COMPLETE,this.completeHandler);
|
||||
this._loader.removeEventListener(IOErrorEvent.IO_ERROR,this.errorHandler);
|
||||
this._loader.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,this.securityErrorHandler);
|
||||
this._loader.close();
|
||||
this._loader = null;
|
||||
}
|
||||
this.error = null;
|
||||
this.callback = null;
|
||||
}
|
||||
|
||||
public function getEvent() : void
|
||||
{
|
||||
this.request("get",this.serialize(null));
|
||||
}
|
||||
|
||||
public function putEvent(param1:*) : void
|
||||
{
|
||||
this.request("put",this.serialize(param1));
|
||||
}
|
||||
|
||||
override public function toString() : String
|
||||
{
|
||||
return "[MochiUserData operation=" + this.operation + " key=\"" + this.key + "\" data=" + this.data + " error=\"" + this.error + "\"]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user