Section 1
//BigDB (playerio.BigDB)
package playerio {
public interface BigDB {
function load(_arg1:String, _arg2:String, _arg3:Function=null, _arg4:Function=null):void;
function loadKeys(_arg1:String, _arg2:Array, _arg3:Function=null, _arg4:Function=null):void;
function loadSingle(_arg1:String, _arg2:String, _arg3:Array, _arg4:Function=null, _arg5:Function=null):void;
function createObject(_arg1:String, _arg2:String, _arg3:Object, _arg4:Function=null, _arg5:Function=null):void;
function loadMyPlayerObject(_arg1:Function=null, _arg2:Function=null):void;
function loadRange(_arg1:String, _arg2:String, _arg3:Array, _arg4:Object, _arg5:Object, _arg6:int, _arg7:Function=null, _arg8:Function=null):void;
function deleteKeys(_arg1:String, _arg2:Array, _arg3:Function=null, _arg4:Function=null):void;
function deleteRange(_arg1:String, _arg2:String, _arg3:Array, _arg4:Object, _arg5:Object, _arg6:Function=null, _arg7:Function=null):void;
function loadOrCreate(_arg1:String, _arg2:String, _arg3:Function=null, _arg4:Function=null):void;
function loadKeysOrCreate(_arg1:String, _arg2:Array, _arg3:Function=null, _arg4:Function=null):void;
}
}//package playerio
Section 2
//Client (playerio.Client)
package playerio {
import flash.display.*;
public interface Client {
function get connectUserId():String;
function get partnerPay():PartnerPay;
function get payVault():PayVault;
function get gameFS():GameFS;
function get bigDB():BigDB;
function get errorLog():ErrorLog;
function get multiplayer():Multiplayer;
function get stage():Stage;
}
}//package playerio
Section 3
//Connection (playerio.Connection)
package playerio {
public interface Connection {
function addMessageHandler(_arg1:String, _arg2:Function):void;
function removeMessageHandler(_arg1:String, _arg2:Function):void;
function addDisconnectHandler(_arg1:Function):void;
function removeDisconnectHandler(_arg1:Function):void;
function get connected():Boolean;
function createMessage(_arg1:String, ... _args):Message;
function send(_arg1:String, ... _args):void;
function sendMessage(_arg1:Message):void;
function disconnect():void;
}
}//package playerio
Section 4
//ErrorLog (playerio.ErrorLog)
package playerio {
public interface ErrorLog {
function writeError(_arg1:String, _arg2:String, _arg3:String, _arg4:Object, _arg5:Function=null, _arg6:Function=null):void;
}
}//package playerio
Section 5
//GameFS (playerio.GameFS)
package playerio {
public interface GameFS {
function getURL(_arg1:String):String;
}
}//package playerio
Section 6
//Message (playerio.Message)
package playerio {
import flash.utils.*;
public interface Message {
function add(... _args):void;
function getNumber(_arg1:int):Number;
function getInt(_arg1:int):int;
function getUInt(_arg1:int):uint;
function getString(_arg1:int):String;
function getBoolean(_arg1:int):Boolean;
function getByteArray(_arg1:int):ByteArray;
function get length():int;
function get type():String;
function set type(_arg1:String):void;
function toString():String;
}
}//package playerio
Section 7
//Multiplayer (playerio.Multiplayer)
package playerio {
public interface Multiplayer {
function createRoom(_arg1:String, _arg2:String, _arg3:Boolean, _arg4:Object, _arg5:Function=null, _arg6:Function=null):void;
function createJoinRoom(_arg1:String, _arg2:String, _arg3:Boolean, _arg4:Object, _arg5:Object, _arg6:Function=null, _arg7:Function=null):void;
function joinRoom(_arg1:String, _arg2:Object, _arg3:Function=null, _arg4:Function=null):void;
function listRooms(_arg1:String, _arg2:Object, _arg3:int, _arg4:int, _arg5:Function=null, _arg6:Function=null):void;
function set developmentServer(_arg1:String):void;
function get developmentServer():String;
}
}//package playerio
Section 8
//PartnerPay (playerio.PartnerPay)
package playerio {
public interface PartnerPay {
function trigger(_arg1:String, _arg2:uint, _arg3:Function=null, _arg4:Function=null):void;
function setTag(_arg1:String, _arg2:Function=null, _arg3:Function=null):void;
function get currentPartner():String;
}
}//package playerio
Section 9
//PayVault (playerio.PayVault)
package playerio {
public interface PayVault {
function get coins():int;
function get items():Array;
function has(_arg1:String):Boolean;
function first(_arg1:String):VaultItem;
function count(_arg1:String):uint;
function refresh(_arg1:Function=null, _arg2:Function=null):void;
function readHistory(_arg1:uint, _arg2:uint, _arg3:Function=null, _arg4:Function=null):void;
function credit(_arg1:uint, _arg2:String, _arg3:Function=null, _arg4:Function=null):void;
function debit(_arg1:uint, _arg2:String, _arg3:Function=null, _arg4:Function=null):void;
function consume(_arg1:Array, _arg2:Function=null, _arg3:Function=null):void;
function buy(_arg1:Array, _arg2:Boolean, _arg3:Function=null, _arg4:Function=null):void;
function give(_arg1:Array, _arg2:Function=null, _arg3:Function=null):void;
function getBuyDirectInfo(_arg1:String, _arg2:Object, _arg3:Array, _arg4:Function=null, _arg5:Function=null):void;
function getBuyCoinsInfo(_arg1:String, _arg2:Object, _arg3:Function=null, _arg4:Function=null):void;
}
}//package playerio
Section 10
//PlayerIO (playerio.PlayerIO)
package playerio {
import flash.display.*;
import flash.events.*;
import flash.system.*;
import flash.net.*;
public final class PlayerIO {
private static var wrapper:Loader;
private static var queue:Array = [];
private static var apiError:PlayerIOError;
private static var wo:Object = {};
public function PlayerIO(){
throw (new Error("You cannot create an instance of the PlayerIO class!"));
}
public static function connect(_arg1:Stage, _arg2:String, _arg3:String, _arg4:String, _arg5:String, _arg6:String, _arg7:Function, _arg8:Function=null):void{
proxy("connect", arguments);
}
public static function get quickConnect():QuickConnect{
return (new QuickConnect(proxy));
}
public static function gameFS(_arg1:String):GameFS{
return (new SimpleGameFS(_arg1, wo));
}
public static function showLogo(_arg1:Stage, _arg2:String):void{
proxy("showLogo", arguments);
}
private static function proxy(_arg1:String, _arg2:Object):void{
var api:*;
var path:Array;
var target = _arg1;
var args = _arg2;
if (apiError){
throwError(apiError, args[(args.callee.length - 1)]);
} else {
if (((wrapper) && (wrapper.content))){
try {
api = wrapper.content;
path = target.split(".");
while (path.length > 1) {
api = api[path.shift()];
};
api[path[0]].apply(null, args);
} catch(e:Error) {
throwError(new PlayerIOError(e.message, e.errorID), args[(args.callee.length - 1)]);
};
} else {
queue.push(function ():void{
args.callee.apply(null, args);
});
};
};
if (!wrapper){
loadAPI();
};
}
private static function loadAPI():void{
var loader:URLLoader;
wrapper = new Loader();
loader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, function (_arg1:Event):void{
wrapper.contentLoaderInfo.addEventListener(Event.COMPLETE, emptyQueue);
wrapper.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
wrapper.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleLoadError);
wrapper.loadBytes(loader.data, new LoaderContext(false, ApplicationDomain.currentDomain));
wo.wrapper = wrapper;
});
loader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleLoadError);
loader.load(new URLRequest("http://api.playerio.com/flashbridge/1"));
}
private static function handleLoadError(_arg1:Event=null):void{
apiError = new PlayerIOError((("Unable to connect to the API due to " + _arg1.type) + ". Please verify that your internet connection is working!"), 0);
emptyQueue();
}
private static function emptyQueue(_arg1:Event=null):void{
while (queue.length) {
queue.shift()();
};
}
private static function throwError(_arg1:PlayerIOError, _arg2:Function):void{
if (_arg2 != null){
_arg2(_arg1);
} else {
throw (PlayerIOError);
};
}
}
}//package playerio
Section 11
//PlayerIOError (playerio.PlayerIOError)
package playerio {
public class PlayerIOError extends Error {
protected var _type:PlayerIOError;
public static const UnsupportedMethod:PlayerIOError = new PlayerIOError("The method requested is not supported", 0);
;
public static const GeneralError:PlayerIOError = new PlayerIOError("A general error occured", 1);
;
public static const InternalError:PlayerIOError = new PlayerIOError("An unexpected error occured inside the Player.IO webservice. Please try again.", 2);
;
public static const AccessDenied:PlayerIOError = new PlayerIOError("Access is denied", 3);
;
public static const InvalidMessageFormat:PlayerIOError = new PlayerIOError("The message is malformatted", 4);
;
public static const MissingValue:PlayerIOError = new PlayerIOError("A value is missing", 5);
;
public static const GameRequired:PlayerIOError = new PlayerIOError("A game is required to do this action", 6);
;
public static const ExternalError:PlayerIOError = new PlayerIOError("An error occurred while contacting an external service", 7);
;
public static const ArgumentOutOfRange:PlayerIOError = new PlayerIOError("The given argument value is outside the range of allowed values.", 8);
;
public static const GameDisabled:PlayerIOError = new PlayerIOError("The game has been disabled, most likely because of missing payment.", 9);
;
public static const UnknownGame:PlayerIOError = new PlayerIOError("The game requested is not known by the server", 10);
;
public static const UnknownConnection:PlayerIOError = new PlayerIOError("The connection requested is not known by the server", 11);
;
public static const InvalidAuth:PlayerIOError = new PlayerIOError("The auth given is invalid or malformatted", 12);
;
public static const NoServersAvailable:PlayerIOError = new PlayerIOError("There is no server in any of the selected server clusters for the game that are eligible to start a new room in (they're all at full capacity or there are no servers in any of the clusters). Either change the selected clusters for your game in the admin panel, try again later or start some more servers for one of your clusters.", 13);
;
public static const RoomDataTooLarge:PlayerIOError = new PlayerIOError("The room data for the room was over the allowed size limit", 14);
;
public static const RoomAlreadyExists:PlayerIOError = new PlayerIOError("You are unable to create room because there is already a room with the specified id", 15);
;
public static const UnknownRoomType:PlayerIOError = new PlayerIOError("The game you're connected to does not have a room type with the specified name", 16);
;
public static const UnknownRoom:PlayerIOError = new PlayerIOError("There is no room running with that id", 17);
;
public static const MissingRoomId:PlayerIOError = new PlayerIOError("You can't join the room when the RoomID is null or the empty string", 18);
;
public static const RoomIsFull:PlayerIOError = new PlayerIOError("The room already has the maxmium amount of users in it.", 19);
;
public static const NotASearchColumn:PlayerIOError = new PlayerIOError("The key you specified is not set as searchable. You can change the searchable keys in the admin panel for the server type", 20);
;
public static const QuickConnectMethodNotEnabled:PlayerIOError = new PlayerIOError("The QuickConnect method (simple, facebook, kongregate...) is not enabled for the game. You can enable the various methods in the admin panel for the game", 21);
;
public static const UnknownUser:PlayerIOError = new PlayerIOError("The user is unknown", 22);
;
public static const InvalidPassword:PlayerIOError = new PlayerIOError("The password supplied is incorrect", 23);
;
public static const InvalidRegistrationData:PlayerIOError = new PlayerIOError("The supplied data is incorrect", 24);
;
public static const InvalidBigDBKey:PlayerIOError = new PlayerIOError("The key given for the BigDB object is not a valid BigDB key. BigDB keys must be between 1 and 50 word characters (no spaces).", 25);
;
public static const BigDBObjectTooLarge:PlayerIOError = new PlayerIOError("The object exceeds the maximum allowed size for BigDB objects.", 26);
;
public static const BigDBObjectDoesNotExist:PlayerIOError = new PlayerIOError("Could not locate the database object.", 27);
;
public static const UnknownTable:PlayerIOError = new PlayerIOError("The specified table does not exist.", 28);
;
public static const UnknownIndex:PlayerIOError = new PlayerIOError("The specified index does not exist.", 29);
;
public static const InvalidIndexValue:PlayerIOError = new PlayerIOError("The value given for the index, does not match the expeceded type.", 30);
;
public static const NotObjectCreator:PlayerIOError = new PlayerIOError("The operation was aborted because the user attempting the operation was not the original creator of the object accessed.", 31);
;
public static const KeyAlreadyUsed:PlayerIOError = new PlayerIOError("The key is in use by another database object", 32);
;
public static const StaleVersion:PlayerIOError = new PlayerIOError("BigDB object could not be saved using optimistic locks as it's out of date.", 33);
;
public static const CircularReference:PlayerIOError = new PlayerIOError("Cannot create circular references inside database objects", 34);
;
public static const HeartbeatFailed:PlayerIOError = new PlayerIOError("The server could not complete the heartbeat", 40);
;
public static const InvalidGameCode:PlayerIOError = new PlayerIOError("The game code is invalid", 41);
;
public static const VaultNotLoaded:PlayerIOError = new PlayerIOError("Cannot access coins or items before vault has been loaded. Please refresh the vault first.", 50);
;
public static const UnknownPayVaultProvider:PlayerIOError = new PlayerIOError("There is no PayVault provider with the specified id", 51);
;
public static const DirectPurchaseNotSupportedByProvider:PlayerIOError = new PlayerIOError("The specified PayVault provider does not support direct purchase", 52);
;
public static const BuyingCoinsNotSupportedByProvider:PlayerIOError = new PlayerIOError("The specified PayVault provider does not support buying coins", 54);
;
public static const NotEnoughCoins:PlayerIOError = new PlayerIOError("The user does not have enough coins in the PayVault to complete the purchase or debit.", 55);
;
public static const ItemNotInVault:PlayerIOError = new PlayerIOError("The item does not exist in the vault.", 56);
;
public static const InvalidPurchaseArguments:PlayerIOError = new PlayerIOError("The chosen provider rejected one or more of the purchase arguments", 57);
;
public static const InvalidPayVaultProviderSetup:PlayerIOError = new PlayerIOError("The chosen provider is not configured correctly in the admin panel", 58);
;
public static const UnknownPartnerPayAction:PlayerIOError = new PlayerIOError("Unable to locate the custom PartnerPay action with the given key", 70);
;
public function PlayerIOError(_arg1:String, _arg2:int){
_type = GeneralError;
super(_arg1, _arg2);
}
public function get type():PlayerIOError{
return (_type);
}
}
}//package playerio
Section 12
//QuickConnect (playerio.QuickConnect)
package playerio {
import flash.display.*;
public class QuickConnect {
private var _proxy:Function;
public function QuickConnect(_arg1:Function){
_proxy = _arg1;
}
public function simpleConnect(_arg1:Stage, _arg2:String, _arg3:String, _arg4:String, _arg5:Function=null, _arg6:Function=null):void{
_proxy("quickConnect.simpleConnect", arguments);
}
public function simpleRegister(_arg1:Stage, _arg2:String, _arg3:String, _arg4:String, _arg5:String, _arg6:String="", _arg7:String="", _arg8:Object=null, _arg9:String="", _arg10:Function=null, _arg11:Function=null):void{
_proxy("quickConnect.simpleRegister", arguments);
}
public function simpleGetCaptcha(_arg1:String, _arg2:int, _arg3:int, _arg4:Function=null, _arg5:Function=null):void{
_proxy("quickConnect.simpleGetCaptcha", arguments);
}
public function simpleRecoverPassword(_arg1:String, _arg2:String, _arg3:Function=null, _arg4:Function=null):void{
_proxy("quickConnect.simpleRecoverPassword", arguments);
}
public function kongregateConnect(_arg1:Stage, _arg2:String, _arg3:String, _arg4:String, _arg5:Function=null, _arg6:Function=null):void{
_proxy("quickConnect.kongregateConnect", arguments);
}
public function facebookConnect(_arg1:Stage, _arg2:String, _arg3:String, _arg4:String, _arg5:String="", _arg6:Function=null, _arg7:Function=null):void{
_proxy("quickConnect.facebookConnect", arguments);
}
public function facebookConnectPopup(_arg1:Stage, _arg2:String, _arg3:String, _arg4:Array, _arg5:String="", _arg6:Function=null, _arg7:Function=null):void{
_proxy("quickConnect.facebookConnectPopup", arguments);
}
public function facebookOAuthConnect(_arg1:Stage, _arg2:String, _arg3:String, _arg4:String="", _arg5:Function=null, _arg6:Function=null):void{
_proxy("quickConnect.facebookOAuthConnect", arguments);
}
public function facebookOAuthConnectPopup(_arg1:Stage, _arg2:String, _arg3:String, _arg4:Array, _arg5:String="", _arg6:Function=null, _arg7:Function=null):void{
_proxy("quickConnect.facebookOAuthConnectPopup", arguments);
}
}
}//package playerio
Section 13
//RoomInfo (playerio.RoomInfo)
package playerio {
public interface RoomInfo {
function get id():String;
function get serverType():String;
function get roomType():String;
function get onlineUsers():int;
function get data():Object;
function toString():String;
}
}//package playerio
Section 14
//SimpleGameFS (playerio.SimpleGameFS)
package playerio {
import playerio.*;
class SimpleGameFS implements GameFS {
private var gameId:String;
private var wo:Object;
function SimpleGameFS(_arg1:String, _arg2:Object){
this.gameId = _arg1;
this.wo = _arg2;
}
public function getURL(_arg1:String):String{
if (_arg1.substring(0, 1) != "/"){
throw (new Error("GameFS paths must be absolute and start with a slash (/). IE PlayerIO.gameFS(\"[gameid]\").getURL(\"/folder/file.extention\")", 0));
};
if (((((wo.wrapper) && (wo.wrapper.content))) && (wo.wrapper.content.hasOwnProperty("getURL")))){
return (wo.wrapper.content.getURL(gameId, _arg1));
};
return ((("http://r.playerio.com/r/" + gameId) + _arg1));
}
}
}//package playerio
Section 15
//VaultItem (playerio.VaultItem)
package playerio {
public dynamic class VaultItem {
public function get id():String{
return ("");
}
public function get itemKey():String{
return ("");
}
public function get purchaseDate():Date{
return (new Date());
}
}
}//package playerio
Section 16
//ScrollBar (sample.ui.components.scroll.ScrollBar)
package sample.ui.components.scroll {
import flash.events.*;
import sample.ui.components.*;
public class ScrollBar extends Component {
private var decArrow:ScrollButton;
private var incArrow:ScrollButton;
private var scrollbg:Box;
private var tracker:ScrollTracker;
private var _scrollSize:Number;// = 1000
private var _scrollViewable:Number;// = 200
private var _scrollValue:Number;// = 0
private var scrollListener:Function;
private var _mouseY:Number;
private var _mouseX:Number;
private var pixelSize:int;// = 10
public function ScrollBar(_arg1:Boolean=false){
var horizontal = _arg1;
super();
decArrow = new ScrollButton(1, pixelSize, decScroll);
incArrow = new ScrollButton(3, pixelSize, incScroll);
scrollbg = new Box().fill(0, 1, 3);
tracker = new ScrollTracker();
scrollbg.addEventListener(MouseEvent.MOUSE_DOWN, function (_arg1:MouseEvent):void{
if (scrollbg.mouseY > tracker.y){
incScrollJump();
} else {
decScrollJump();
};
});
tracker.addEventListener(MouseEvent.MOUSE_DOWN, function (_arg1:MouseEvent):void{
var handleMove:Function;
var e = _arg1;
handleMove = function (_arg1:Event):void{
changeByPx((tracker.mouseY - _mouseY));
if (tracker.upState.parent){
tracker.removeEventListener(Event.ENTER_FRAME, handleMove);
};
};
_mouseY = tracker.mouseY;
tracker.addEventListener(Event.ENTER_FRAME, handleMove);
tracker.addEventListener(MouseEvent.MOUSE_UP, function (_arg1:MouseEvent):void{
tracker.removeEventListener(Event.ENTER_FRAME, handleMove);
tracker.removeEventListener(MouseEvent.MOUSE_UP, arguments.callee);
});
});
addChild(scrollbg);
addChild(tracker);
addChild(decArrow);
addChild(incArrow);
tracker.width = pixelSize;
tracker.x = 0;
redraw();
}
public function changeByPx(_arg1:Number):void{
scrollValue = (scrollValue + ((_scrollSize / innerSize) * _arg1));
}
public function decScroll():void{
scrollValue = (_scrollValue - 15);
}
public function incScroll():void{
scrollValue = (_scrollValue + 15);
}
public function decScrollJump():void{
scrollValue = (_scrollValue - _scrollViewable);
}
public function incScrollJump():void{
scrollValue = (_scrollValue + _scrollViewable);
}
public function set scrollSize(_arg1:Number):void{
_scrollSize = _arg1;
_scrollValue = Math.max(Math.min(_scrollValue, (_scrollSize - _scrollViewable)), 0);
}
public function set scrollViewable(_arg1:Number):void{
_scrollViewable = _arg1;
_scrollValue = Math.max(Math.min(_scrollValue, (_scrollSize - _scrollViewable)), 0);
}
public function set scrollValue(_arg1:Number):void{
if (_arg1 != _scrollValue){
_scrollValue = Math.max(Math.min(_arg1, (_scrollSize - _scrollViewable)), 0);
if (scrollListener != null){
scrollListener(_scrollValue);
};
redraw();
};
}
public function get scrollValue():Number{
return (_scrollValue);
}
public function scroll(_arg1:Function):void{
scrollListener = _arg1;
}
private function get innerSize():Number{
return ((_height - (pixelSize * 2)));
}
override public function get width():Number{
return (_width);
}
override public function get height():Number{
return (_height);
}
override protected function redraw():void{
tracker.height = Math.max(((innerSize * _scrollViewable) / _scrollSize), 10);
tracker.y = ((pixelSize + 1) + ((_scrollValue / (_scrollSize - _scrollViewable)) * ((innerSize - tracker.height) - 1)));
scrollbg.width = pixelSize;
scrollbg.height = _height;
incArrow.y = (_height - pixelSize);
}
}
}//package sample.ui.components.scroll
Section 17
//ScrollBox (sample.ui.components.scroll.ScrollBox)
package sample.ui.components.scroll {
import flash.display.*;
import sample.ui.components.*;
import flash.geom.*;
public class ScrollBox extends Box {
private var _container:Sprite;
private var _mask:Sprite;
private var _scrollX:Number;// = 0
private var _scrollY:Number;// = 0
private var hscroll:ScrollBar;
public function ScrollBox(){
_container = new Content();
_mask = new Sprite();
hscroll = new ScrollBar();
super();
super.addChild(_container);
super.addChild(_mask);
super.addChild(hscroll);
_mask.graphics.beginFill(0, 1);
_mask.graphics.drawRect(0, 0, 100, 100);
_mask.graphics.endFill();
hscroll.scroll(function (_arg1:Number):void{
scrollY = _arg1;
});
_container.mask = _mask;
}
override public function add(... _args):Box{
var _local2:DisplayObject;
for each (_local2 in _args) {
_container.addChild(_local2);
};
redraw();
return (this);
}
public function set scrollX(_arg1:Number):void{
_scrollX = _arg1;
redraw();
}
public function set scrollY(_arg1:Number):void{
hscroll.scrollValue = _arg1;
_scrollY = _arg1;
redraw();
}
public function get scrollWidth():Number{
return ((_container.width - _mask.width));
}
public function get scrollHeight():Number{
return ((_container.height - _mask.height));
}
public function get scrollX():Number{
return (_scrollX);
}
public function get scrollY():Number{
return (_scrollY);
}
override public function get width():Number{
return (_width);
}
override public function get height():Number{
return (_height);
}
override public function addChild(_arg1:DisplayObject):DisplayObject{
return (_container.addChild(_arg1));
}
override public function removeChild(_arg1:DisplayObject):DisplayObject{
return (_container.removeChild(_arg1));
}
public function refresh():void{
redraw();
}
override protected function redraw():void{
var _local1:Number = _width;
if (_container.height > _height){
_width = (_width - 10);
hscroll.visible = true;
hscroll.scrollViewable = _height;
hscroll.scrollSize = ((_container.height + ((_top) || (0))) + ((_bottom) || (0)));
} else {
hscroll.visible = false;
hscroll.scrollValue = 0;
};
super.redraw();
_scrollX = Math.max(Math.min(_scrollX, scrollWidth), 0);
_scrollY = Math.max(Math.min(_scrollY, scrollHeight), 0);
_container.x = (_container.x - (_scrollX + 1));
_container.y = (_container.y - (_scrollY + 1));
hscroll.x = _width;
hscroll.y = 0;
hscroll.height = Math.ceil(_height);
_width = _local1;
this.scrollRect = new Rectangle(0, 0, (_width + 1), (_height + 1));
}
}
}//package sample.ui.components.scroll
import flash.display.*;
import sample.ui.components.*;
class Content extends Component {
private function Content(){
}
override protected function redraw():void{
var _local2:DisplayObject;
var _local1:int;
while (_local1 < numChildren) {
_local2 = getChildAt(_local1);
_local2.width = _width;
_local1++;
};
}
}
Section 18
//ScrollButton (sample.ui.components.scroll.ScrollButton)
package sample.ui.components.scroll {
import flash.utils.*;
import flash.display.*;
import flash.events.*;
import sample.ui.components.*;
public class ScrollButton extends SampleButton {
public function ScrollButton(_arg1:int=0, _arg2:int=10, _arg3:Function=null){
var direction = _arg1;
var size = _arg2;
var clickHandler = _arg3;
super();
this.upState = new Box().margin(0, 0, 0, 0).fill(0, 1, 3).minSize(size, size).add(new Box().add(drawArrow(0xFFFFFF, (size / 3), direction)));
this.downState = new Box().margin(0, 0, 0, 0).fill(0xFFFFFF, 1, 3).minSize(size, size).add(new Box().add(drawArrow(0x888888, (size / 3), direction)));
this.overState = new Box().margin(0, 0, 0, 0).fill(0xFFFFFF, 1, 3).minSize(size, size).add(new Box().add(drawArrow(0, (size / 3), direction)));
this.hitTestState = new Box().margin(0, 0, 0, 0).fill(0, 1, 3).minSize(size, size).add(new Box().add(drawArrow(0xFFFFFF, (size / 3), direction)));
if (clickHandler != null){
this.addEventListener(MouseEvent.MOUSE_DOWN, function (_arg1:MouseEvent):void{
var i:Number;
var e = _arg1;
clickHandler();
var n:int;
i = setInterval(function ():void{
if (e.target.upState.parent){
clearInterval(i);
return;
};
if (((e.target.downState.parent) && ((n++ > 5)))){
clickHandler();
};
}, 50);
e.target.addEventListener(MouseEvent.MOUSE_UP, function (_arg1:MouseEvent):void{
clearInterval(i);
_arg1.target.removeEventListener(MouseEvent.MOUSE_UP, arguments.callee);
});
});
};
}
private function drawArrow(_arg1:int, _arg2:int, _arg3:int=0):Sprite{
var _local4:Sprite = new Sprite();
var _local5:Graphics = _local4.graphics;
var _local6:Number = ((Math.PI / 2) * _arg3);
_local5.beginFill(_arg1, 1);
_local5.moveTo(((Math.cos((2.0943 - _local6)) * _arg2) + _arg2), ((Math.sin((2.0943 - _local6)) * _arg2) + _arg2));
_local5.lineTo(((Math.cos((4.18879 - _local6)) * _arg2) + _arg2), ((Math.sin((4.18879 - _local6)) * _arg2) + _arg2));
_local5.lineTo(((Math.cos(-(_local6)) * _arg2) + _arg2), ((Math.sin(-(_local6)) * _arg2) + _arg2));
return (_local4);
}
}
}//package sample.ui.components.scroll
Section 19
//ScrollTracker (sample.ui.components.scroll.ScrollTracker)
package sample.ui.components.scroll {
import sample.ui.components.*;
public class ScrollTracker extends SampleButton {
public function ScrollTracker(_arg1:Function=null){
super(_arg1);
_width = 20;
_height = 20;
this.upState = new Box().margin(0, 0, 0, 0).fill(0x999999, 1, 3);
this.downState = new Box().margin(0, 0, 0, 0).fill(0x888888, 1, 3);
this.overState = new Box().margin(0, 0, 0, 0).fill(0xFFFFFF, 1, 3);
this.hitTestState = new Box().margin(0, 0, 0, 0).fill(0xBBBBBB, 1, 3);
}
}
}//package sample.ui.components.scroll
Section 20
//Box (sample.ui.components.Box)
package sample.ui.components {
import flash.display.*;
public class Box extends Component {
protected var _top:Number;// = NAN
protected var _bottom:Number;// = NAN
protected var _left:Number;// = NAN
protected var _right:Number;// = NAN
protected var _color:int;
protected var _corner:Number;// = 0
protected var _alpha:Number;
protected var _strokeWidth:Number;
protected var _strokeColor:Number;
protected var _strokeAlpha:Number;
protected var useFill:Boolean;// = false
public function Box(){
redraw();
}
public function margin(_arg1:Number=NaN, _arg2:Number=NaN, _arg3:Number=NaN, _arg4:Number=NaN){
_top = _arg1;
_right = _arg2;
_bottom = _arg3;
_left = _arg4;
redraw();
return (this);
}
public function fill(_arg1:int=0, _arg2:Number=1, _arg3:Number=0){
_width = width;
_height = height;
_color = _arg1;
_corner = _arg3;
_alpha = _arg2;
useFill = true;
redraw();
return (this);
}
public function border(_arg1:Number=0, _arg2:Number=0, _arg3:Number=1){
_strokeWidth = _arg1;
_strokeColor = _arg2;
_strokeAlpha = _arg3;
redraw();
return (this);
}
public function minSize(_arg1:Number, _arg2:Number):Box{
this.minWidth = _arg1;
this.minHeight = _arg2;
redraw();
return (this);
}
public function add(... _args):Box{
var _local2:DisplayObject;
for each (_local2 in _args) {
addChild(_local2);
};
redraw();
return (this);
}
protected function get borderHeight():Number{
return (((_top) ? _top : 0 + (_bottom) ? _bottom : 0));
}
protected function get borderWidth():Number{
return (((_left) ? _left : 0 + (_right) ? _right : 0));
}
public function reset(_arg1:Boolean=true, _arg2:Array=null):void{
var _local4:DisplayObject;
var _local5:Function;
if (_arg1){
_arg2 = [];
};
var _local3:int;
while (_local3 < numChildren) {
_local4 = getChildAt(_local3);
if ((_local4 is Box)){
(_local4 as Box).reset(false, _arg2);
};
_local3++;
};
_arg2.push(redraw);
if (_arg1){
for each (_local5 in _arg2) {
_local5();
_local5();
};
};
}
override protected function redraw():void{
var _local4:DisplayObject;
var _local1:Number = _width;
var _local2:Number = _height;
var _local3:int;
while (_local3 < numChildren) {
_local4 = getChildAt(_local3);
_local1 = Math.max(_local1, (_local4.width + borderWidth));
_local2 = Math.max(_local2, (_local4.height + borderHeight));
if (!isNaN(_left)){
_local4.x = _left;
if (!isNaN(_right)){
_local4.width = (rwidth - borderWidth);
};
} else {
if (!isNaN(_right)){
_local4.x = ((_local1 - _local4.width) - _right);
} else {
_local4.x = ((Math.max(rwidth, _local1) - _local4.width) / 2);
};
};
if (!isNaN(_top)){
_local4.y = _top;
if (!isNaN(_bottom)){
_local4.height = (rheight - borderHeight);
};
} else {
if (!isNaN(_bottom)){
_local4.y = ((_local2 - _local4.height) - _bottom);
} else {
_local4.y = ((Math.max(rheight, _local2) - _local4.height) / 2);
};
};
_local3++;
};
graphics.clear();
if (_strokeWidth){
graphics.lineStyle(_strokeWidth, _strokeColor, _strokeAlpha, true);
if (((_minWidth) || (_minHeight))){
graphics.drawRoundRect(0, 0, Math.max(rwidth, _local1), Math.max(rheight, _local2), _corner);
} else {
graphics.drawRoundRect(0, 0, Math.max(rwidth, _width), Math.max(rheight, _height), _corner);
};
};
if (useFill){
graphics.beginFill(_color, _alpha);
if (((_minWidth) || (_minHeight))){
graphics.drawRoundRect(0, 0, Math.max(rwidth, _local1), Math.max(rheight, _local2), _corner);
} else {
graphics.drawRoundRect(0, 0, Math.max(rwidth, _width), Math.max(rheight, _height), _corner);
};
graphics.endFill();
};
}
}
}//package sample.ui.components
Section 21
//Columns (sample.ui.components.Columns)
package sample.ui.components {
import flash.display.*;
public class Columns extends Box {
private var container:Component;
private var _spacing:Number;// = 0
public function Columns(... _args){
var _local2:DisplayObject;
container = new Component();
super();
super.addChild(container);
for each (_local2 in _args) {
addChild(_local2);
};
}
override public function addChild(_arg1:DisplayObject):DisplayObject{
var _local2:DisplayObject = container.addChild(_arg1);
redraw();
return (_local2);
}
override public function removeChild(_arg1:DisplayObject):DisplayObject{
var _local2:DisplayObject = container.removeChild(_arg1);
redraw();
return (_local2);
}
public function spacing(_arg1:Number){
_spacing = (_arg1 / 2);
return (this);
}
override protected function redraw():void{
var _local3:DisplayObject;
var _local1:Number = ((_width - borderWidth) / container.numChildren);
var _local2:int;
while (_local2 < container.numChildren) {
_local3 = container.getChildAt(_local2);
_local3.width = (_local1 - _spacing);
_local3.x = ((_local1 + _spacing) * _local2);
_local2++;
};
super.redraw();
}
}
}//package sample.ui.components
Section 22
//Component (sample.ui.components.Component)
package sample.ui.components {
import flash.display.*;
public class Component extends Sprite {
protected var _width:Number;// = 0
protected var _height:Number;// = 0
protected var _minWidth:Number;// = 0
protected var _minHeight:Number;// = 0
override public function set width(_arg1:Number):void{
if (_width != _arg1){
_width = _arg1;
redraw();
};
}
override public function set height(_arg1:Number):void{
if (_height != _arg1){
_height = _arg1;
redraw();
};
}
public function get rwidth():Number{
return (Math.max(_width, _minWidth));
}
public function get rheight():Number{
return (Math.max(_height, _minHeight));
}
public function set minWidth(_arg1:Number):void{
if (_minWidth != _arg1){
_minWidth = _arg1;
redraw();
};
}
public function set minHeight(_arg1:Number):void{
if (_minHeight != _arg1){
_minHeight = _arg1;
redraw();
};
}
protected function redraw():void{
}
}
}//package sample.ui.components
Section 23
//Input (sample.ui.components.Input)
package sample.ui.components {
import flash.text.*;
public class Input extends Label {
public function Input(_arg1:String, _arg2:Number=12, _arg3:String="left", _arg4:Boolean=false){
super(_arg1, _arg2, _arg3);
this.type = TextFieldType.INPUT;
this.mouseEnabled = true;
this.border = true;
this.background = true;
this.borderColor = 5605512;
if (_arg4){
this.displayAsPassword = true;
};
}
public function setStyle(_arg1:Boolean=true, _arg2:Boolean=true, _arg3:Number=0xFFFFFF, _arg4:Number=5605512):Input{
this.border = _arg1;
this.borderColor = _arg4;
this.background = _arg2;
this.borderColor = _arg4;
return (this);
}
override public function Clone():Label{
return (new Input(this.text, (this.defaultTextFormat.size as Number), this.defaultTextFormat.align));
}
}
}//package sample.ui.components
Section 24
//Label (sample.ui.components.Label)
package sample.ui.components {
import flash.text.*;
public class Label extends TextField {
public function Label(_arg1:String, _arg2:Number=12, _arg3:String="left", _arg4:Number=0, _arg5:Boolean=false, _arg6:String=null){
var _local8:TextField;
super();
var _local7:TextFormat = new TextFormat();
_local7.font = ((_arg6) || ("Arial"));
if (_arg6){
embedFonts = true;
};
_local7.align = _arg3;
_local7.size = _arg2;
_local7.color = _arg4;
this.defaultTextFormat = _local7;
super.text = _arg1;
this.mouseEnabled = false;
if (_arg5){
this.multiline = true;
this.wordWrap = true;
};
resize();
}
override public function set text(_arg1:String):void{
super.text = _arg1;
resize();
}
public function clear():void{
super.text = "";
}
private function resize():void{
this.width = (this.textWidth + 10);
this.height = (this.textHeight + ((this.defaultTextFormat.size as Number) / 2));
}
override public function get height():Number{
return ((this.textHeight + 3));
}
public function Clone():Label{
return (new Label(this.text, (this.defaultTextFormat.size as Number), this.defaultTextFormat.align));
}
}
}//package sample.ui.components
Section 25
//Rows (sample.ui.components.Rows)
package sample.ui.components {
import flash.display.*;
public class Rows extends Component {
private var _spacing:Number;// = 10
public function Rows(... _args){
var _local2:DisplayObject;
super();
for each (_local2 in _args) {
addChild(_local2);
};
}
override public function addChild(_arg1:DisplayObject):DisplayObject{
var _local2:DisplayObject = super.addChild(_arg1);
redraw();
return (_local2);
}
override public function addChildAt(_arg1:DisplayObject, _arg2:int):DisplayObject{
var _local3:DisplayObject = super.addChildAt(_arg1, _arg2);
redraw();
return (_local3);
}
override public function removeChild(_arg1:DisplayObject):DisplayObject{
var _local2:DisplayObject = super.removeChild(_arg1);
redraw();
return (_local2);
}
public function removeChildren():void{
while (numChildren) {
super.removeChild(getChildAt(0));
};
redraw();
}
public function spacing(_arg1:Number){
_spacing = _arg1;
redraw();
return (this);
}
override protected function redraw():void{
var _local3:DisplayObject;
var _local1:Number = 0;
var _local2:int;
while (_local2 < numChildren) {
_local3 = getChildAt(_local2);
_local3.y = _local1;
_local3.width = _width;
_local1 = (_local1 + (_local3.height + _spacing));
_local2++;
};
super.redraw();
_height = _local1;
}
}
}//package sample.ui.components
Section 26
//SampleButton (sample.ui.components.SampleButton)
package sample.ui.components {
import flash.display.*;
import flash.events.*;
public class SampleButton extends SimpleButton {
protected var _width:Number;
protected var _height:Number;
protected var _clickHandler:Function;
public function SampleButton(_arg1:Function=null){
var clickHandler = _arg1;
super();
_clickHandler = function ():void{
if (clickHandler != null){
clickHandler();
};
};
if (_clickHandler != null){
addEventListener(Event.ADDED_TO_STAGE, handleAttach);
addEventListener(Event.REMOVED_FROM_STAGE, handleDetatch);
};
redraw();
}
public function handleAttach(_arg1:Event):void{
addEventListener(MouseEvent.CLICK, _clickHandler);
}
public function handleDetatch(_arg1:Event):void{
removeEventListener(MouseEvent.CLICK, _clickHandler);
}
override public function set width(_arg1:Number):void{
_width = _arg1;
redraw();
}
override public function set height(_arg1:Number):void{
_height = _arg1;
redraw();
}
protected function redraw():void{
if (this.upState){
this.upState.width = _width;
this.upState.height = _height;
};
if (this.downState){
this.downState.width = _width;
this.downState.height = _height;
};
if (this.overState){
this.overState.width = _width;
this.overState.height = _height;
};
if (this.hitTestState){
this.hitTestState.width = _width;
this.hitTestState.height = _height;
};
}
}
}//package sample.ui.components
Section 27
//TextButton (sample.ui.components.TextButton)
package sample.ui.components {
import flash.text.*;
public class TextButton extends SampleButton {
private var _text:String;
public function TextButton(_arg1:String, _arg2:Function=null){
var _local3:Label;
super(_arg2);
_text = _arg1;
_local3 = new Label(_text, 12, TextFormatAlign.CENTER);
this.upState = new Box().margin(0, 0, 0, 0).fill(0xFFFFFF, 1, 10).border(1, 5605512).add(new Box().add(_local3.Clone()));
this.downState = new Box().margin(0, 0, 0, 0).fill(5605512, 1, 10).border(1, 0).add(new Box().add(_local3.Clone()));
this.overState = new Box().margin(0, 0, 0, 0).fill(5614250, 1, 10).border(1, 0).add(new Box().add(_local3.Clone()));
this.hitTestState = new Box().margin(0, 0, 0, 0).fill(0xFFFFFF, 1, 10).border(1, 5614250).add(new Box().add(_local3.Clone()));
_width = (_local3.width + 12);
_height = (_local3.height + 10);
redraw();
}
}
}//package sample.ui.components
Section 28
//Chat (sample.ui.Chat)
package sample.ui {
import playerio.*;
import flash.display.*;
import flash.events.*;
import sample.ui.components.*;
import flash.text.*;
import sample.ui.components.scroll.*;
public class Chat extends Sprite {
private var _connection:Connection;
private var _stage:Stage;
private var base:Box;
private var input:Input;
private var content:Rows;
private var container:ScrollBox;
private var userlist:Rows;
private var users:Object;
public function Chat(_arg1:Stage, _arg2:Connection){
var stage = _arg1;
var connection = _arg2;
users = {};
super();
this._stage = stage;
this._connection = connection;
base = new Box().margin(5, 5, 5, 5).add(new Box().fill(0, 0.5, 10).margin(5, 5, 5, 5).add(new Box().margin(0, 0, NaN, 0).add(new Box().minSize(0, 150).fill(0xFFFFFF, 1, 3).margin(0, 0, 0, 0).add(new ScrollBox().margin(2, 2, 2, 2).add((userlist = new Rows().spacing(1)))))).add(new Box().margin(155, 0, 32, 0).add(new Box().fill(0xFFFFFF, 1, 3).margin(0, 0, 0, 0).add((container = new ScrollBox().margin(2, 2, 2, 2).add((content = new Rows().spacing(1))))))).add(new Box().margin(NaN, 0, 0, 0).add(new Box().minSize(0, 27).fill(0xFFFFFF, 1, 3).margin(3, 3, 3, 3).add(new Box().margin(0, 60, 0, 0).add(new Box().margin(2, 0, 0, 3).fill(0x666666, 0, 5).border(1, 0x444444, 1).add((input = new Input("").setStyle(false, false))))).add(new Box().margin(0, 0, 0, NaN).add(new Box().minSize(55, 0).margin(0, 0, 0, 0).add(new TextButton("Send", sendChatText)))))));
addChild(base);
_connection.addMessageHandler("ChatInit", onInit);
_connection.addMessageHandler("ChatMessage", onMessage);
_connection.addMessageHandler("ChatJoin", function (_arg1:Message, _arg2:String, _arg3:String){
addUser(_arg2, _arg3);
});
_connection.addMessageHandler("ChatLeft", function (_arg1:Message, _arg2:String){
removeUser(_arg2);
});
input.addEventListener(KeyboardEvent.KEY_DOWN, function (_arg1:KeyboardEvent){
if (_arg1.keyCode == 13){
sendChatText();
};
});
stage.addChild(this);
_stage.addEventListener(Event.RESIZE, handleResize);
handleResize();
}
public function sendMessage(_arg1:String){
if (((_connection.connected) && (!((_arg1 == ""))))){
_connection.send("ChatMessage", _arg1);
};
}
private function sendChatText():void{
sendMessage(input.text);
input.clear();
}
private function onInit(_arg1:Message, _arg2:String){
var _local3 = 1;
while (_local3 < _arg1.length) {
addUser(_arg1.getString(_local3), _arg1.getString((_local3 + 1)));
_local3 = (_local3 + 2);
};
}
private function addUser(_arg1:String, _arg2:String){
if (!users[_arg1]){
users[_arg1] = new Label(_arg2, 12, TextFormatAlign.LEFT, 0, true);
userlist.addChild(users[_arg1]);
base.reset();
};
}
private function removeUser(_arg1:String){
if (users[_arg1]){
userlist.removeChild(users[_arg1]);
delete users[_arg1];
base.reset();
};
}
private function onMessage(_arg1:Message, _arg2:String, _arg3:String){
if (content.numChildren > 50){
content.removeChild(content.getChildAt(0));
};
content.addChild(new Label(((users[_arg2].text + ": ") + _arg3), 12, TextFormatAlign.LEFT, 0, true));
base.reset();
container.scrollY = 100000;
}
private function handleResize(_arg1:Event=null){
base.height = _stage.stageHeight;
base.width = 250;
base.x = (_stage.stageWidth - 250);
}
}
}//package sample.ui
Section 29
//Lobby (sample.ui.Lobby)
package sample.ui {
import playerio.*;
import flash.display.*;
import flash.events.*;
import sample.ui.components.*;
import flash.text.*;
import sample.ui.components.scroll.*;
public class Lobby extends Sprite {
private var _stage:Stage;
private var _roomType:String;
private var _handleJoin:Function;
private var _handleJoinError:Function;
private var _client:Client;
private var base:Box;
private var createDialog:Box;
private var loader:Box;
private var roomContainer:Rows;
private var cancel:TextButton;
public function Lobby(_arg1:Client, _arg2:String, _arg3:Function, _arg4:Function=null){
var gamename:Input;
var client = _arg1;
var roomType = _arg2;
var handleJoin = _arg3;
var handleJoinError = _arg4;
super();
_stage = client.stage;
_client = client;
_roomType = roomType;
_handleJoin = handleJoin;
_handleJoinError = handleJoinError;
roomContainer = new Rows().spacing(2);
base = new Box().fill(0xFFFFFF, 0.8).margin(20, 20, 20, 20).add(new Box().fill(0, 0.5, 10).margin(10, 10, 10, 10).add(new Box().fill(0xFFFFFF, 1, 5).margin(10, 10, 10, 10).add(new Label("Lobby", 20, TextFormatAlign.LEFT)).add(new Box().margin(35, 0, 35, 0).add(new Box().margin(0, 0, 0, 0).fill(0, 0, 10).border(1, 0x555555, 1).add(new ScrollBox().margin(3, 1, 3, 3).add(roomContainer)))).add(new Box().margin(NaN, 0, 0, 0).add(new Columns().spacing(10).add((cancel = new TextButton("Cancel", hide)), new TextButton("Create new game!", showCreateRoom))))));
var _local6 = new Input("My Amazing game!", 12, TextFormatAlign.LEFT, false);
gamename = _local6;
createDialog = new Box().fill(0xFFFFFF, 0.8).add(new Box().fill(0, 0.5, 15).margin(10, 10, 10, 10).minSize(300, 0).add(new Box().fill(0xFFFFFF, 1, 5).margin(10, 10, 10, 10).minSize(300, 0).add(new Rows(new Label("Create new game", 20, TextFormatAlign.CENTER), new Label("Game name"), _local6, new Columns().spacing(10).margin(10).add(new TextButton("Cancel", hideCreateRoom), new TextButton("Create", function (){
createGame(gamename.text);
}))).spacing(3))));
loader = new Box().fill(0xFFFFFF, 0.8).add(new Label("Joining game.", 20)).add(new Box().margin(20).add(new Label("Please wait while we connect to the server.", 12)));
addChild(base);
realign();
}
public function showCreateRoom(_arg1:Event=null){
addChild(createDialog);
}
public function hideCreateRoom(_arg1:Event=null){
if (createDialog.parent){
removeChild(createDialog);
};
}
public function show(_arg1:Boolean=false):void{
_stage.addChild(this);
_stage.addEventListener(Event.RESIZE, realign);
refresh();
realign();
cancel.visible = !(_arg1);
trace(cancel.visible);
}
public function hide():void{
hideCreateRoom();
hideLoader();
if (this.parent){
_stage.removeChild(this);
};
_stage.removeEventListener(Event.RESIZE, realign);
}
private function showLoader():void{
addChild(loader);
}
private function hideLoader():void{
if (loader.parent){
removeChild(loader);
};
}
private function refresh():void{
roomContainer.removeChildren();
_client.multiplayer.listRooms(_roomType, {}, 50, 0, function (_arg1:Array){
var _local2:int;
while (_local2 < _arg1.length) {
roomContainer.addChild(new RoomEntry(_arg1[_local2], joinRoom));
_local2++;
};
base.reset();
}, function (_arg1:PlayerIOError){
trace("Unable to list rooms", _arg1);
});
}
private function joinRoom(_arg1:String):void{
showLoader();
_client.multiplayer.joinRoom(_arg1, {}, handleJoin, _handleJoinError);
}
private function createGame(_arg1:String):void{
hideCreateRoom();
showLoader();
_client.multiplayer.createRoom(null, _roomType, true, {name:_arg1}, joinRoom, _handleJoinError);
}
private function handleJoin(_arg1:Connection):void{
hide();
_handleJoin(_arg1);
}
private function realign(_arg1:Event=null):void{
base.width = _stage.stageWidth;
base.height = _stage.stageHeight;
createDialog.width = _stage.stageWidth;
createDialog.height = _stage.stageHeight;
loader.width = _stage.stageWidth;
loader.height = _stage.stageHeight;
}
}
}//package sample.ui
Section 30
//Prompt (sample.ui.Prompt)
package sample.ui {
import playerio.*;
import flash.display.*;
import flash.events.*;
import sample.ui.components.*;
import flash.text.*;
import sample.ui.components.scroll.*;
public class Prompt extends Box {
private var base:Box;
private var input:Input;
private var _callback:Function;
public function Prompt(_arg1:Stage, _arg2:String, _arg3:String, _arg4:Function){
_callback = _arg4;
fill(0xFFFFFF, 0.8).add(new Box().minSize(300, 110).fill(0, 0.5, 10).margin(10, 10, 10, 10).add(new Box().minSize(300, 110).fill(0xFFFFFF, 1, 10).margin(0, 0, 0, 0).add(new Box().margin(10).add(new Label(_arg2, 20))).add(new Box().margin(43, 20, NaN, 20).add(new Box().margin(2, 0, 0, 3).minSize(20, 25).fill(0x666666, 0, 5).border(1, 0x444444, 1).add((input = new Input(_arg3, 14, TextFormatAlign.CENTER).setStyle(false, false))))).add(new Box().margin(75).add(new TextButton("Join game", accept)))));
_arg1.addChild(this);
_arg1.addEventListener(Event.RESIZE, handleResize);
handleResize();
}
function accept():void{
if (input.text != ""){
stage.removeEventListener(Event.RESIZE, handleResize);
stage.removeChild(this);
_callback(input.text);
};
}
private function handleResize(_arg1:Event=null){
this.width = stage.stageWidth;
this.height = stage.stageHeight;
}
}
}//package sample.ui
Section 31
//RoomEntry (sample.ui.RoomEntry)
package sample.ui {
import playerio.*;
import sample.ui.components.*;
import flash.text.*;
public class RoomEntry extends Box {
public function RoomEntry(_arg1:RoomInfo, _arg2:Function){
var room = _arg1;
var joinHandler = _arg2;
super();
margin(1, 1, 1, 1).minSize(40, 35).add(new Box().margin(0, 0, 0, 0).fill(0xEEEEEE, 0.2, 10).border(1, 0xBBBBBB, 1).add(new Box().margin(NaN, NaN, NaN, 5).add(new Label(room.data.name))).add(new Box().margin(3, 3, 3).add(new Box().margin(0, 0, 0, 0).minSize(200, 0).add(new Columns(new Box().margin(5, 0, 0, 0).add(new Label((room.onlineUsers.toString() + " players"), 12, TextFormatAlign.CENTER)), new TextButton("Join Game", function (){
joinHandler(room.id);
}))))));
}
}
}//package sample.ui
Section 32
//InfoBox (InfoBox)
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class InfoBox extends MovieClip {
public var winner:TextField;
public var joinGame:SimpleButton;
public var playAgain:SimpleButton;
private var startCallback:Function;
private var joinCallback:Function;
public function InfoBox(_arg1:Function, _arg2:Function){
stop();
playAgain.visible = false;
playAgain.addEventListener(MouseEvent.CLICK, handleRestart);
joinGame.visible = false;
joinGame.addEventListener(MouseEvent.CLICK, handleJoin);
this.startCallback = _arg1;
this.joinCallback = _arg2;
}
public function Hide(){
this.visible = false;
}
public function Show(_arg1:String, _arg2:String=""){
winner.visible = false;
playAgain.visible = false;
joinGame.visible = false;
switch (_arg1){
case "showWinner":
winner.text = _arg2;
winner.visible = true;
case "full":
case "waiting":
if (_arg2 == "ok"){
(joinGame.visible = true);
};
case "tie":
if (_arg2 == "go"){
(playAgain.visible = true);
};
break;
default:
(playAgain.visible = true);
break;
};
this.gotoAndStop(_arg1);
(this.visible = true);
}
private function handleRestart(_arg1:MouseEvent){
startCallback();
}
private function handleJoin(_arg1:MouseEvent){
joinCallback();
}
}
}//package
Section 33
//TicTacToe (TicTacToe)
package {
import playerio.*;
import flash.display.*;
import flash.events.*;
import flash.text.*;
import sample.ui.*;
public class TicTacToe extends MovieClip {
public var spectating:MovieClip;
public var player2:TextField;
public var showTurn:MovieClip;
public var brickContainer:MovieClip;
public var player1:TextField;
private var connection:Connection;
private var tiles:Array;
private var hasTurn:Boolean;// = false
private var isInited:Boolean;// = false
private var infoBox:InfoBox;
private var imPlayer:Number;
private var isSpectator:Boolean;// = false
private var lobby:Lobby;
public function TicTacToe(){
tiles = [];
super();
stop();
new Prompt(stage, "What's your name?", ("Guest-" + ((Math.random() * 9999) << 0)), function (_arg1:String){
PlayerIO.connect(stage, "tictactoe-avkenqvdmu2kxsywmv1i6q", "public", _arg1, "", null, handleConnect, handleError);
});
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
}
private function handleConnect(_arg1:Client):void{
trace("Sucessfully connected to player.io");
lobby = new Lobby(_arg1, "TicTacToe", handleJoin, handleError);
lobby.show(true);
gotoAndStop(2);
}
private function handleJoin(_arg1:Connection):void{
var b:int;
var tile:Tile;
var connection = _arg1;
trace("Sucessfully connected to the multiplayer server");
showTurn.stop();
infoBox = new InfoBox(resetGame, joinGame);
addChild(infoBox);
var a:int;
while (a < 3) {
tiles[a] = [];
b = 0;
while (b < 3) {
tile = new Tile(b, a);
tile.addEventListener(MouseEvent.CLICK, handleClick);
brickContainer.addChild(tile);
tiles[a][b] = tile;
b = (b + 1);
};
a = (a + 1);
};
setTurn(false);
spectating.visible = false;
infoBox.Show("waiting");
this.connection = connection;
var chat:Chat = new Chat(stage, connection);
connection.addMessageHandler("init", function (_arg1:Message, _arg2:int, _arg3:String){
isSpectator = false;
spectating.visible = false;
imPlayer = _arg2;
((imPlayer == 0)) ? player1 : player2.text = _arg3;
});
connection.addMessageHandler("join", function (_arg1:Message, _arg2:String, _arg3:String){
player1.text = _arg2;
player2.text = _arg3;
});
connection.addMessageHandler("full", function (_arg1:Message){
infoBox.Show("full");
});
connection.addMessageHandler("reset", function (_arg1:Message, _arg2:int){
infoBox.Hide();
setTurn((_arg2 == imPlayer), true);
});
connection.addMessageHandler("left", function (_arg1:Message, _arg2:String, _arg3:String){
infoBox.Show("waiting", (isSpectator) ? "ok" : "");
player1.text = _arg2;
player2.text = _arg3;
setTurn(false);
});
connection.addMessageHandler("place", function (_arg1:Message, _arg2:int, _arg3:int, _arg4:String, _arg5:int){
tiles[_arg3][_arg2].SetState(_arg4);
setTurn((_arg5 == imPlayer));
});
connection.addMessageHandler("win", function (_arg1:Message, _arg2:int, _arg3:String){
if (isSpectator){
infoBox.Show("showWinner", _arg3);
} else {
infoBox.Show(((_arg2 == imPlayer)) ? "won" : "lost");
};
setTurn(false);
});
connection.addMessageHandler("tie", function (_arg1:Message){
infoBox.Show("tie", (isSpectator) ? "" : "go");
setTurn(false);
});
connection.addMessageHandler("spectator", function (_arg1:Message, _arg2:String, _arg3:String){
var _local6:int;
isSpectator = true;
player1.text = _arg2;
player2.text = _arg3;
var _local4:int;
var _local5 = 2;
while (_local5 < _arg1.length) {
_local6 = ((_local5 - 2) % 3);
tiles[_local4][_local6].SetState(_arg1.getString(_local5));
if (_local6 == 2){
_local4++;
};
_local5++;
};
spectating.visible = true;
infoBox.Hide();
});
}
private function resetGame():void{
connection.send("reset");
infoBox.Show("waiting");
}
private function joinGame():void{
trace("send join");
connection.send("join");
infoBox.Show("waiting");
}
private function handleClick(_arg1:MouseEvent):void{
var _local2:Tile = (_arg1.target as Tile);
if (hasTurn){
connection.send("click", _local2.XPosition, _local2.YPosition);
};
}
private function setTurn(_arg1:Boolean, _arg2:Boolean=false):void{
var _local4:int;
hasTurn = _arg1;
showTurn.gotoAndStop(((imPlayer == 0)) ? (_arg1) ? 1 : 2 : (_arg1) ? 2 : 1);
var _local3:int;
while (_local3 < 3) {
_local4 = 0;
while (_local4 < 3) {
tiles[_local3][_local4].enabled = hasTurn;
if (_arg2){
tiles[_local3][_local4].SetState("blank");
};
_local4++;
};
_local3++;
};
}
private function handleMessages(_arg1:Message){
trace("Recived the message", _arg1);
}
private function handleDisconnect():void{
trace("Disconnected from server");
}
private function handleError(_arg1:PlayerIOError):void{
trace("Got", _arg1);
gotoAndStop(3);
}
}
}//package
Section 34
//Tile (Tile)
package {
import flash.display.*;
import flash.events.*;
public class Tile extends MovieClip {
public var eventTarget:SimpleButton;
public var XPosition:int;
public var YPosition:int;
public function Tile(_arg1:int, _arg2:int){
stop();
this.x = (_arg1 * 100);
this.y = (_arg2 * 100);
this.XPosition = _arg1;
this.YPosition = _arg2;
eventTarget.addEventListener(MouseEvent.CLICK, handleClick);
}
public function SetState(_arg1:String){
switch (_arg1){
case "blank":
this.gotoAndStop("blank");
break;
case "cross":
this.gotoAndStop("cross");
break;
case "circle":
this.gotoAndStop("circle");
break;
};
}
override public function set enabled(_arg1:Boolean):void{
eventTarget.enabled = _arg1;
}
private function handleClick(_arg1:MouseEvent){
_arg1.stopImmediatePropagation();
dispatchEvent(new MouseEvent(MouseEvent.CLICK, true));
}
}
}//package