Section 1
//CDK (com.coreyoneil.collision.CDK)
package com.coreyoneil.collision {
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
import flash.text.*;
import flash.errors.*;
public class CDK {
private var colorTransform2:ColorTransform;
private var colorTransform1:ColorTransform;
private var _returnAngleType:String;
private var pixels1:ByteArray;
private var pixels2:ByteArray;
private var bmdResample:BitmapData;
private var _returnAngle:Boolean;
private var transMatrix2:Matrix;
private var rect1:Rectangle;
private var rect2:Rectangle;
private var transMatrix1:Matrix;
protected var objectCheckArray:Array;
private var _alphaThreshold:Number;
private var item1Registration:Point;
private var bmd1:BitmapData;
private var bmd2:BitmapData;
protected var objectArray:Array;
private var item2Registration:Point;
protected var objectCollisionArray:Array;
private var _numChildren:uint;
private var colorExclusionArray:Array;
public function CDK():void{
if (getQualifiedClassName(this) == "com.coreyoneil.collision::CDK"){
throw (new Error("CDK is an abstract class and is not meant for instantiation - use CollisionGroup or CollisionList"));
};
init();
}
public function get returnAngle():Boolean{
return (_returnAngle);
}
public function set returnAngle(_arg1:Boolean):void{
_returnAngle = _arg1;
}
protected function findCollisions(_arg1, _arg2):void{
var item1xDiff:Number;
var item1yDiff:Number;
var locY:Number;
var locX:Number;
var locStage:Point;
var alpha1:uint;
var alpha2:uint;
var colorFlag:Boolean;
var red1:uint;
var red2:uint;
var green1:uint;
var green2:uint;
var blue1:uint;
var blue2:uint;
var colorObj:Object;
var aPlus:uint;
var aMinus:uint;
var rPlus:uint;
var rMinus:uint;
var gPlus:uint;
var gMinus:uint;
var bPlus:uint;
var bMinus:uint;
var item1Flags:uint;
var item2Flags:uint;
var n:uint;
var angle:Number;
var recordedCollision:Object;
var item1 = _arg1;
var item2 = _arg2;
var item1_isText:Boolean;
var item2_isText:Boolean;
if ((item1 is TextField)){
item1_isText = ((item1.antiAliasType)=="advanced") ? true : false;
item1.antiAliasType = ((item1.antiAliasType)=="advanced") ? "normal" : item1.antiAliasType;
};
if ((item2 is TextField)){
item2_isText = ((item2.antiAliasType)=="advanced") ? true : false;
item2.antiAliasType = ((item2.antiAliasType)=="advanced") ? "normal" : item2.antiAliasType;
};
colorTransform1 = item1.transform.colorTransform;
colorTransform2 = item2.transform.colorTransform;
item1Registration = new Point();
item2Registration = new Point();
item1Registration = item1.localToGlobal(item1Registration);
item2Registration = item2.localToGlobal(item2Registration);
bmd1 = new BitmapData(item1.width, item1.height, true, 0xFFFFFF);
bmd2 = new BitmapData(item1.width, item1.height, true, 0xFFFFFF);
transMatrix1 = item1.transform.matrix;
var currentObj:* = item1;
while (currentObj.parent != null) {
transMatrix1.concat(currentObj.parent.transform.matrix);
currentObj = currentObj.parent;
};
rect1 = item1.getBounds(currentObj);
if (item1 != currentObj){
rect1.x = (rect1.x + currentObj.x);
rect1.y = (rect1.y + currentObj.y);
};
var _local4 = (item1Registration.x - rect1.left);
item1xDiff = _local4;
transMatrix1.tx = _local4;
_local4 = (item1Registration.y - rect1.top);
item1yDiff = _local4;
transMatrix1.ty = _local4;
transMatrix2 = item2.transform.matrix;
currentObj = item2;
while (currentObj.parent != null) {
transMatrix2.concat(currentObj.parent.transform.matrix);
currentObj = currentObj.parent;
};
transMatrix2.tx = (item2Registration.x - rect1.left);
transMatrix2.ty = (item2Registration.y - rect1.top);
bmd1.draw(item1, transMatrix1, colorTransform1, null, null, true);
bmd2.draw(item2, transMatrix2, colorTransform2, null, null, true);
pixels1 = bmd1.getPixels(new Rectangle(0, 0, bmd1.width, bmd1.height));
pixels2 = bmd2.getPixels(new Rectangle(0, 0, bmd1.width, bmd1.height));
var k:uint;
var value1:uint;
var value2:uint;
var collisionPoint:Number = -1;
var overlap:Boolean;
var overlapping:Array = [];
var hasColors:int = colorExclusionArray.length;
pixels1.position = 0;
pixels2.position = 0;
var pixelLength:int = pixels1.length;
while (k < pixelLength) {
k = pixels1.position;
try {
value1 = pixels1.readUnsignedInt();
value2 = pixels2.readUnsignedInt();
} catch(e:EOFError) {
break;
};
alpha1 = ((value1 >> 24) & 0xFF);
alpha2 = ((value2 >> 24) & 0xFF);
if ((((alpha1 > _alphaThreshold)) && ((alpha2 > _alphaThreshold)))){
colorFlag = false;
if (hasColors){
red1 = ((value1 >> 16) & 0xFF);
red2 = ((value2 >> 16) & 0xFF);
green1 = ((value1 >> 8) & 0xFF);
green2 = ((value2 >> 8) & 0xFF);
blue1 = (value1 & 0xFF);
blue2 = (value2 & 0xFF);
n = 0;
while (n < hasColors) {
colorObj = Object(colorExclusionArray[n]);
item1Flags = 0;
item2Flags = 0;
if ((((blue1 >= colorObj.bMinus)) && ((blue1 <= colorObj.bPlus)))){
item1Flags = (item1Flags + 1);
};
if ((((blue2 >= colorObj.bMinus)) && ((blue2 <= colorObj.bPlus)))){
item2Flags = (item2Flags + 1);
};
if ((((green1 >= colorObj.gMinus)) && ((green1 <= colorObj.gPlus)))){
item1Flags = (item1Flags + 1);
};
if ((((green2 >= colorObj.gMinus)) && ((green2 <= colorObj.gPlus)))){
item2Flags = (item2Flags + 1);
};
if ((((red1 >= colorObj.rMinus)) && ((red1 <= colorObj.rPlus)))){
item1Flags = (item1Flags + 1);
};
if ((((red2 >= colorObj.rMinus)) && ((red2 <= colorObj.rPlus)))){
item2Flags = (item2Flags + 1);
};
if ((((alpha1 >= colorObj.aMinus)) && ((alpha1 <= colorObj.aPlus)))){
item1Flags = (item1Flags + 1);
};
if ((((alpha2 >= colorObj.aMinus)) && ((alpha2 <= colorObj.aPlus)))){
item2Flags = (item2Flags + 1);
};
if ((((item1Flags == 4)) || ((item2Flags == 4)))){
colorFlag = true;
};
n = (n + 1);
};
};
if (!colorFlag){
overlap = true;
collisionPoint = (k >> 2);
locY = (collisionPoint / bmd1.width);
locX = (collisionPoint % bmd1.width);
locY = (locY - item1yDiff);
locX = (locX - item1xDiff);
locStage = item1.localToGlobal(new Point(locX, locY));
overlapping.push(locStage);
};
};
};
if (overlap){
angle = (_returnAngle) ? findAngle(item1, item2) : 0;
recordedCollision = {object1:item1, object2:item2, angle:angle, overlapping:overlapping};
objectCollisionArray.push(recordedCollision);
};
if (item1_isText){
item1.antiAliasType = "advanced";
};
if (item2_isText){
item2.antiAliasType = "advanced";
};
_local4 = false;
item2_isText = _local4;
item1_isText = _local4;
}
private function init():void{
objectCheckArray = [];
objectCollisionArray = [];
objectArray = [];
colorExclusionArray = [];
_alphaThreshold = 0;
_returnAngle = true;
_returnAngleType = "RADIANS";
}
public function dispose():void{
objectArray = [];
}
public function excludeColor(_arg1:uint, _arg2:uint=0xFF, _arg3:uint=20, _arg4:uint=20, _arg5:uint=20):void{
var _local8:uint;
var _local9:uint;
var _local10:uint;
var _local11:uint;
var _local12:uint;
var _local13:uint;
var _local14:uint;
var _local15:uint;
var _local6:int = colorExclusionArray.length;
var _local7:uint;
while (_local7 < _local6) {
if (colorExclusionArray[_local7].color == _arg1){
throw (new Error((("Color could not be added - color already in the exclusion list [" + _arg1) + "]")));
};
_local7++;
};
_local8 = (((_arg1 >> 24) & 0xFF) + _arg2);
_local9 = (_local8 - (_arg2 << 1));
_local10 = (((_arg1 >> 16) & 0xFF) + _arg3);
_local11 = (_local10 - (_arg3 << 1));
_local12 = (((_arg1 >> 8) & 0xFF) + _arg4);
_local13 = (_local12 - (_arg4 << 1));
_local14 = ((_arg1 & 0xFF) + _arg5);
_local15 = (_local14 - (_arg5 << 1));
var _local16:Object = {color:_arg1, aPlus:_local8, aMinus:_local9, rPlus:_local10, rMinus:_local11, gPlus:_local12, gMinus:_local13, bPlus:_local14, bMinus:_local15};
colorExclusionArray.push(_local16);
}
public function get numChildren():uint{
return (objectArray.length);
}
public function get alphaThreshold():Number{
return (_alphaThreshold);
}
public function removeItem(_arg1):void{
var _local2:int = objectArray.indexOf(_arg1);
if (_local2 > -1){
objectArray.splice(_local2, 1);
} else {
throw (new Error((_arg1 + " could not be removed - object not found in item list.")));
};
}
public function set returnAngleType(_arg1:String):void{
_arg1 = _arg1.toUpperCase();
switch (_arg1){
case "DEGREES":
case "DEGREE":
case "DEG":
case "DEGS":
_returnAngleType = "DEGREES";
break;
case "RADIANS":
case "RADIAN":
case "RAD":
case "RADS":
_returnAngleType = "RADIANS";
break;
default:
throw (new Error("returnAngleType expects 'DEGREES' or 'RADIANS'"));
};
}
private function findAngle(_arg1:DisplayObject, _arg2:DisplayObject):Number{
var pixel:uint;
var thisAlpha:uint;
var lastAlpha:int;
var edgePoint:int;
var k:uint;
var upperLimit:int;
var colorFlag:Boolean;
var red1:uint;
var green1:uint;
var blue1:uint;
var colorObj:Object;
var a:uint;
var r:uint;
var g:uint;
var b:uint;
var item1Flags:uint;
var n:uint;
var item1 = _arg1;
var item2 = _arg2;
var center:Point = new Point((item1.width >> 1), (item1.height >> 1));
var pixels:ByteArray = pixels2;
transMatrix2.tx = (transMatrix2.tx + center.x);
transMatrix2.ty = (transMatrix2.ty + center.y);
bmdResample = new BitmapData((item1.width << 1), (item1.height << 1), true, 0xFFFFFF);
bmdResample.draw(item2, transMatrix2, colorTransform2, null, null, true);
pixels = bmdResample.getPixels(new Rectangle(0, 0, bmdResample.width, bmdResample.height));
center.x = (bmdResample.width >> 1);
center.y = (bmdResample.height >> 1);
var columnHeight:uint = Math.round(bmdResample.height);
var rowWidth:uint = Math.round(bmdResample.width);
var edgeArray:Array = [];
var hasColors:int = colorExclusionArray.length;
var j:uint;
while (j < columnHeight) {
k = ((j * rowWidth) << 2);
pixels.position = k;
lastAlpha = -1;
upperLimit = (((j + 1) * rowWidth) << 2);
while (k < upperLimit) {
k = pixels.position;
try {
pixel = pixels.readUnsignedInt();
} catch(e:EOFError) {
break;
};
thisAlpha = ((pixel >> 24) & 0xFF);
if (lastAlpha == -1){
lastAlpha = thisAlpha;
} else {
if (thisAlpha > _alphaThreshold){
colorFlag = false;
if (hasColors){
red1 = ((pixel >> 16) & 0xFF);
green1 = ((pixel >> 8) & 0xFF);
blue1 = (pixel & 0xFF);
n = 0;
while (n < hasColors) {
colorObj = Object(colorExclusionArray[n]);
item1Flags = 0;
if ((((blue1 >= colorObj.bMinus)) && ((blue1 <= colorObj.bPlus)))){
item1Flags = (item1Flags + 1);
};
if ((((green1 >= colorObj.gMinus)) && ((green1 <= colorObj.gPlus)))){
item1Flags = (item1Flags + 1);
};
if ((((red1 >= colorObj.rMinus)) && ((red1 <= colorObj.rPlus)))){
item1Flags = (item1Flags + 1);
};
if ((((thisAlpha >= colorObj.aMinus)) && ((thisAlpha <= colorObj.aPlus)))){
item1Flags = (item1Flags + 1);
};
if (item1Flags == 4){
colorFlag = true;
};
n = (n + 1);
};
};
if (!colorFlag){
edgeArray.push((k >> 2));
};
};
};
};
j = (j + 1);
};
var numEdges:int = edgeArray.length;
var slopeYAvg:Number = 0;
var slopeXAvg:Number = 0;
j = 0;
while (j < numEdges) {
edgePoint = int(edgeArray[j]);
slopeYAvg = (slopeYAvg + (center.y - (edgePoint / rowWidth)));
slopeXAvg = (slopeXAvg + ((edgePoint % rowWidth) - center.x));
j = (j + 1);
};
var average:Number = -(Math.atan2(slopeYAvg, slopeXAvg));
average = ((_returnAngleType == "RADIANS")) ? average : (average * 57.2957795);
return (average);
}
public function addItem(_arg1):void{
if ((_arg1 is DisplayObject)){
objectArray.push(_arg1);
} else {
throw (new Error((("Cannot add item: " + _arg1) + " - item must be a Display Object.")));
};
}
public function get returnAngleType():String{
return (_returnAngleType);
}
public function set alphaThreshold(_arg1:Number):void{
if ((((_arg1 <= 1)) && ((_arg1 >= 0)))){
_alphaThreshold = (_arg1 * 0xFF);
} else {
throw (new Error("alphaThreshold expects a value from 0 to 1"));
};
}
public function removeExcludeColor(_arg1:uint):void{
var _local2:Boolean;
var _local3:int = colorExclusionArray.length;
var _local4:uint;
while (_local4 < _local3) {
if (colorExclusionArray[_local4].color == _arg1){
colorExclusionArray.splice(_local4, 1);
_local2 = true;
break;
};
_local4++;
};
if (!_local2){
throw (new Error((("Color could not be removed - color not found in exclusion list [" + _arg1) + "]")));
};
}
protected function clearArrays():void{
objectCheckArray = [];
objectCollisionArray = [];
}
}
}//package com.coreyoneil.collision
Section 2
//CollisionGroup (com.coreyoneil.collision.CollisionGroup)
package com.coreyoneil.collision {
import flash.display.*;
public class CollisionGroup extends CDK {
public function CollisionGroup(... _args):void{
var _local2:uint;
while (_local2 < _args.length) {
addItem(_args[_local2]);
_local2++;
};
}
public function checkCollisions():Array{
var _local2:DisplayObject;
var _local3:DisplayObject;
var _local5:uint;
clearArrays();
var _local1:uint = objectArray.length;
var _local4:uint;
while (_local4 < (_local1 - 1)) {
_local2 = DisplayObject(objectArray[_local4]);
_local5 = (_local4 + 1);
while (_local5 < _local1) {
_local3 = DisplayObject(objectArray[_local5]);
if (_local2.hitTestObject(_local3)){
if ((_local3.width * _local3.height) > (_local2.width * _local2.height)){
objectCheckArray.push([_local2, _local3]);
} else {
objectCheckArray.push([_local3, _local2]);
};
};
_local5++;
};
_local4++;
};
_local1 = objectCheckArray.length;
_local4 = 0;
while (_local4 < _local1) {
findCollisions(DisplayObject(objectCheckArray[_local4][0]), DisplayObject(objectCheckArray[_local4][1]));
_local4++;
};
return (objectCollisionArray);
}
}
}//package com.coreyoneil.collision
Section 3
//AutoAlphaPlugin (gs.plugins.AutoAlphaPlugin)
package gs.plugins {
import flash.display.*;
import gs.*;
public class AutoAlphaPlugin extends TweenPlugin {
protected var _tweenVisible:Boolean;
protected var _target:Object;
protected var _visible:Boolean;
protected var _tween:TweenLite;
public static const VERSION:Number = 1;
public static const API:Number = 1;
public function AutoAlphaPlugin(){
this.propName = "autoAlpha";
this.overwriteProps = ["alpha", "visible"];
this.onComplete = onCompleteTween;
}
override public function killProps(_arg1:Object):void{
super.killProps(_arg1);
_tweenVisible = !(Boolean(("visible" in _arg1)));
}
public function onCompleteTween():void{
if (((((_tweenVisible) && (!((_tween.vars.runBackwards == true))))) && ((_tween.ease == _tween.vars.ease)))){
_target.visible = _visible;
};
}
override public function onInitTween(_arg1:Object, _arg2, _arg3:TweenLite):Boolean{
_target = _arg1;
_tween = _arg3;
_visible = Boolean(!((_arg2 == 0)));
_tweenVisible = true;
addTween(_arg1, "alpha", _arg1.alpha, _arg2, "alpha");
return (true);
}
override public function set changeFactor(_arg1:Number):void{
updateTweens(_arg1);
if (((!((_target.visible == true))) && (_tweenVisible))){
_target.visible = true;
};
}
}
}//package gs.plugins
Section 4
//EndArrayPlugin (gs.plugins.EndArrayPlugin)
package gs.plugins {
import flash.display.*;
import gs.*;
import gs.utils.tween.*;
public class EndArrayPlugin extends TweenPlugin {
protected var _a:Array;
protected var _info:Array;
public static const VERSION:Number = 1.01;
public static const API:Number = 1;
public function EndArrayPlugin(){
_info = [];
super();
this.propName = "endArray";
this.overwriteProps = ["endArray"];
}
public function init(_arg1:Array, _arg2:Array):void{
_a = _arg1;
var _local3:int = (_arg2.length - 1);
while (_local3 > -1) {
if (((!((_arg1[_local3] == _arg2[_local3]))) && (!((_arg1[_local3] == null))))){
_info[_info.length] = new ArrayTweenInfo(_local3, _a[_local3], (_arg2[_local3] - _a[_local3]));
};
_local3--;
};
}
override public function onInitTween(_arg1:Object, _arg2, _arg3:TweenLite):Boolean{
if (((!((_arg1 is Array))) || (!((_arg2 is Array))))){
return (false);
};
init((_arg1 as Array), _arg2);
return (true);
}
override public function set changeFactor(_arg1:Number):void{
var _local2:int;
var _local3:ArrayTweenInfo;
var _local4:Number;
var _local5:int;
if (this.round){
_local2 = (_info.length - 1);
while (_local2 > -1) {
_local3 = _info[_local2];
_local4 = (_local3.start + (_local3.change * _arg1));
_local5 = ((_local4)<0) ? -1 : 1;
_a[_local3.index] = ((((_local4 % 1) * _local5))>0.5) ? (int(_local4) + _local5) : int(_local4);
_local2--;
};
} else {
_local2 = (_info.length - 1);
while (_local2 > -1) {
_local3 = _info[_local2];
_a[_local3.index] = (_local3.start + (_local3.change * _arg1));
_local2--;
};
};
}
}
}//package gs.plugins
Section 5
//FramePlugin (gs.plugins.FramePlugin)
package gs.plugins {
import flash.display.*;
import gs.*;
public class FramePlugin extends TweenPlugin {
protected var _target:MovieClip;
public var frame:int;
public static const VERSION:Number = 1.01;
public static const API:Number = 1;
public function FramePlugin(){
this.propName = "frame";
this.overwriteProps = ["frame"];
this.round = true;
}
override public function onInitTween(_arg1:Object, _arg2, _arg3:TweenLite):Boolean{
if (((!((_arg1 is MovieClip))) || (isNaN(_arg2)))){
return (false);
};
_target = (_arg1 as MovieClip);
this.frame = _target.currentFrame;
addTween(this, "frame", this.frame, _arg2, "frame");
return (true);
}
override public function set changeFactor(_arg1:Number):void{
updateTweens(_arg1);
_target.gotoAndStop(this.frame);
}
}
}//package gs.plugins
Section 6
//RemoveTintPlugin (gs.plugins.RemoveTintPlugin)
package gs.plugins {
public class RemoveTintPlugin extends TintPlugin {
public static const VERSION:Number = 1.01;
public static const API:Number = 1;
public function RemoveTintPlugin(){
this.propName = "removeTint";
}
}
}//package gs.plugins
Section 7
//TintPlugin (gs.plugins.TintPlugin)
package gs.plugins {
import flash.display.*;
import gs.*;
import flash.geom.*;
import gs.utils.tween.*;
public class TintPlugin extends TweenPlugin {
protected var _target:DisplayObject;
protected var _ct:ColorTransform;
protected var _ignoreAlpha:Boolean;
public static const VERSION:Number = 1.1;
public static const API:Number = 1;
protected static var _props:Array = ["redMultiplier", "greenMultiplier", "blueMultiplier", "alphaMultiplier", "redOffset", "greenOffset", "blueOffset", "alphaOffset"];
public function TintPlugin(){
this.propName = "tint";
this.overwriteProps = ["tint"];
}
public function init(_arg1:DisplayObject, _arg2:ColorTransform):void{
var _local3:int;
var _local4:String;
_target = _arg1;
_ct = _target.transform.colorTransform;
_local3 = (_props.length - 1);
while (_local3 > -1) {
_local4 = _props[_local3];
if (_ct[_local4] != _arg2[_local4]){
_tweens[_tweens.length] = new TweenInfo(_ct, _local4, _ct[_local4], (_arg2[_local4] - _ct[_local4]), "tint", false);
};
_local3--;
};
}
override public function onInitTween(_arg1:Object, _arg2, _arg3:TweenLite):Boolean{
if (!(_arg1 is DisplayObject)){
return (false);
};
var _local4:ColorTransform = new ColorTransform();
if (((!((_arg2 == null))) && (!((_arg3.exposedVars.removeTint == true))))){
_local4.color = uint(_arg2);
};
_ignoreAlpha = true;
init((_arg1 as DisplayObject), _local4);
return (true);
}
override public function set changeFactor(_arg1:Number):void{
var _local2:ColorTransform;
updateTweens(_arg1);
if (_ignoreAlpha){
_local2 = _target.transform.colorTransform;
_ct.alphaMultiplier = _local2.alphaMultiplier;
_ct.alphaOffset = _local2.alphaOffset;
};
_target.transform.colorTransform = _ct;
}
}
}//package gs.plugins
Section 8
//TweenPlugin (gs.plugins.TweenPlugin)
package gs.plugins {
import gs.*;
import gs.utils.tween.*;
public class TweenPlugin {
public var overwriteProps:Array;
protected var _tweens:Array;
public var propName:String;
public var onComplete:Function;
public var round:Boolean;
protected var _changeFactor:Number;// = 0
public static const VERSION:Number = 1.03;
public static const API:Number = 1;
public function TweenPlugin(){
_tweens = [];
super();
}
protected function updateTweens(_arg1:Number):void{
var _local2:int;
var _local3:TweenInfo;
var _local4:Number;
var _local5:int;
if (this.round){
_local2 = (_tweens.length - 1);
while (_local2 > -1) {
_local3 = _tweens[_local2];
_local4 = (_local3.start + (_local3.change * _arg1));
_local5 = ((_local4)<0) ? -1 : 1;
_local3.target[_local3.property] = ((((_local4 % 1) * _local5))>0.5) ? (int(_local4) + _local5) : int(_local4);
_local2--;
};
} else {
_local2 = (_tweens.length - 1);
while (_local2 > -1) {
_local3 = _tweens[_local2];
_local3.target[_local3.property] = (_local3.start + (_local3.change * _arg1));
_local2--;
};
};
}
public function set changeFactor(_arg1:Number):void{
updateTweens(_arg1);
_changeFactor = _arg1;
}
protected function addTween(_arg1:Object, _arg2:String, _arg3:Number, _arg4, _arg5:String=null):void{
var _local6:Number;
if (_arg4 != null){
_local6 = ((typeof(_arg4))=="number") ? (_arg4 - _arg3) : Number(_arg4);
if (_local6 != 0){
_tweens[_tweens.length] = new TweenInfo(_arg1, _arg2, _arg3, _local6, ((_arg5) || (_arg2)), false);
};
};
}
public function killProps(_arg1:Object):void{
var _local2:int;
_local2 = (this.overwriteProps.length - 1);
while (_local2 > -1) {
if ((this.overwriteProps[_local2] in _arg1)){
this.overwriteProps.splice(_local2, 1);
};
_local2--;
};
_local2 = (_tweens.length - 1);
while (_local2 > -1) {
if ((_tweens[_local2].name in _arg1)){
_tweens.splice(_local2, 1);
};
_local2--;
};
}
public function onInitTween(_arg1:Object, _arg2, _arg3:TweenLite):Boolean{
addTween(_arg1, this.propName, _arg1[this.propName], _arg2, this.propName);
return (true);
}
public function get changeFactor():Number{
return (_changeFactor);
}
public static function activate(_arg1:Array):Boolean{
var _local2:int;
var _local3:Object;
_local2 = (_arg1.length - 1);
while (_local2 > -1) {
_local3 = new (_arg1[_local2]);
TweenLite.plugins[_local3.propName] = _arg1[_local2];
_local2--;
};
return (true);
}
}
}//package gs.plugins
Section 9
//VisiblePlugin (gs.plugins.VisiblePlugin)
package gs.plugins {
import flash.display.*;
import gs.*;
public class VisiblePlugin extends TweenPlugin {
protected var _target:Object;
protected var _visible:Boolean;
protected var _tween:TweenLite;
public static const VERSION:Number = 1;
public static const API:Number = 1;
public function VisiblePlugin(){
this.propName = "visible";
this.overwriteProps = ["visible"];
this.onComplete = onCompleteTween;
}
public function onCompleteTween():void{
if (((!((_tween.vars.runBackwards == true))) && ((_tween.ease == _tween.vars.ease)))){
_target.visible = _visible;
};
}
override public function onInitTween(_arg1:Object, _arg2, _arg3:TweenLite):Boolean{
_target = _arg1;
_tween = _arg3;
_visible = Boolean(_arg2);
return (true);
}
override public function set changeFactor(_arg1:Number):void{
if (_target.visible != true){
_target.visible = true;
};
}
}
}//package gs.plugins
Section 10
//VolumePlugin (gs.plugins.VolumePlugin)
package gs.plugins {
import flash.display.*;
import gs.*;
import flash.media.*;
public class VolumePlugin extends TweenPlugin {
protected var _target:Object;
protected var _st:SoundTransform;
public static const VERSION:Number = 1.01;
public static const API:Number = 1;
public function VolumePlugin(){
this.propName = "volume";
this.overwriteProps = ["volume"];
}
override public function onInitTween(_arg1:Object, _arg2, _arg3:TweenLite):Boolean{
if (((isNaN(_arg2)) || (!(_arg1.hasOwnProperty("soundTransform"))))){
return (false);
};
_target = _arg1;
_st = _target.soundTransform;
addTween(_st, "volume", _st.volume, _arg2, "volume");
return (true);
}
override public function set changeFactor(_arg1:Number):void{
updateTweens(_arg1);
_target.soundTransform = _st;
}
}
}//package gs.plugins
Section 11
//ArrayTweenInfo (gs.utils.tween.ArrayTweenInfo)
package gs.utils.tween {
public class ArrayTweenInfo {
public var change:Number;
public var start:Number;
public var index:uint;
public function ArrayTweenInfo(_arg1:uint, _arg2:Number, _arg3:Number){
this.index = _arg1;
this.start = _arg2;
this.change = _arg3;
}
}
}//package gs.utils.tween
Section 12
//TweenInfo (gs.utils.tween.TweenInfo)
package gs.utils.tween {
public class TweenInfo {
public var start:Number;
public var name:String;
public var change:Number;
public var target:Object;
public var property:String;
public var isPlugin:Boolean;
public function TweenInfo(_arg1:Object, _arg2:String, _arg3:Number, _arg4:Number, _arg5:String, _arg6:Boolean){
this.target = _arg1;
this.property = _arg2;
this.start = _arg3;
this.change = _arg4;
this.name = _arg5;
this.isPlugin = _arg6;
}
}
}//package gs.utils.tween
Section 13
//TweenLite (gs.TweenLite)
package gs {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import gs.utils.tween.*;
import gs.plugins.*;
public class TweenLite {
public var started:Boolean;
public var delay:Number;
protected var _hasUpdate:Boolean;
protected var _hasPlugins:Boolean;
public var initted:Boolean;
public var active:Boolean;
public var startTime:Number;
public var target:Object;
public var duration:Number;
public var gc:Boolean;
public var tweens:Array;
public var vars:Object;
public var ease:Function;
public var exposedVars:Object;
public var initTime:Number;
public var combinedTimeScale:Number;
public static const version:Number = 10.092;
private static var _timer:Timer = new Timer(2000);
public static var defaultEase:Function = TweenLite.easeOut;
public static var plugins:Object = {};
public static var currentTime:uint;
public static var masterList:Dictionary = new Dictionary(false);
protected static var _reservedProps:Object = {ease:1, delay:1, overwrite:1, onComplete:1, onCompleteParams:1, runBackwards:1, startAt:1, onUpdate:1, onUpdateParams:1, roundProps:1, onStart:1, onStartParams:1, persist:1, renderOnStart:1, proxiedEase:1, easeParams:1, yoyo:1, loop:1, onCompleteListener:1, onUpdateListener:1, onStartListener:1, orientToBezier:1, timeScale:1};
public static var killDelayedCallsTo:Function = TweenLite.killTweensOf;
public static var timingSprite:Sprite = new Sprite();
public static var overwriteManager:Object;
private static var _tlInitted:Boolean;
public function TweenLite(_arg1:Object, _arg2:Number, _arg3:Object){
if (_arg1 == null){
return;
};
if (!_tlInitted){
TweenPlugin.activate([TintPlugin, RemoveTintPlugin, FramePlugin, AutoAlphaPlugin, VisiblePlugin, VolumePlugin, EndArrayPlugin]);
currentTime = getTimer();
timingSprite.addEventListener(Event.ENTER_FRAME, updateAll, false, 0, true);
if (overwriteManager == null){
overwriteManager = {mode:1, enabled:false};
};
_timer.addEventListener("timer", killGarbage, false, 0, true);
_timer.start();
_tlInitted = true;
};
this.vars = _arg3;
this.duration = ((_arg2) || (0.001));
this.delay = ((_arg3.delay) || (0));
this.combinedTimeScale = ((_arg3.timeScale) || (1));
this.active = Boolean((((_arg2 == 0)) && ((this.delay == 0))));
this.target = _arg1;
if (typeof(this.vars.ease) != "function"){
this.vars.ease = defaultEase;
};
if (this.vars.easeParams != null){
this.vars.proxiedEase = this.vars.ease;
this.vars.ease = easeProxy;
};
this.ease = this.vars.ease;
this.exposedVars = ((this.vars.isTV)==true) ? this.vars.exposedVars : this.vars;
this.tweens = [];
this.initTime = currentTime;
this.startTime = (this.initTime + (this.delay * 1000));
var _local4:int = ((((_arg3.overwrite == undefined)) || (((!(overwriteManager.enabled)) && ((_arg3.overwrite > 1)))))) ? overwriteManager.mode : int(_arg3.overwrite);
if (((!((_arg1 in masterList))) || ((_local4 == 1)))){
masterList[_arg1] = [this];
} else {
masterList[_arg1].push(this);
};
if ((((((this.vars.runBackwards == true)) && (!((this.vars.renderOnStart == true))))) || (this.active))){
initTweenVals();
if (this.active){
render((this.startTime + 1));
} else {
render(this.startTime);
};
if (((((!((this.exposedVars.visible == null))) && ((this.vars.runBackwards == true)))) && ((this.target is DisplayObject)))){
this.target.visible = this.exposedVars.visible;
};
};
}
public function get enabled():Boolean{
return ((this.gc) ? false : true);
}
public function set enabled(_arg1:Boolean):void{
var _local2:Array;
var _local3:Boolean;
var _local4:int;
if (_arg1){
if (!(this.target in masterList)){
masterList[this.target] = [this];
} else {
_local2 = masterList[this.target];
_local4 = (_local2.length - 1);
while (_local4 > -1) {
if (_local2[_local4] == this){
_local3 = true;
break;
};
_local4--;
};
if (!_local3){
_local2[_local2.length] = this;
};
};
};
this.gc = (_arg1) ? false : true;
if (this.gc){
this.active = false;
} else {
this.active = this.started;
};
}
public function clear():void{
this.tweens = [];
this.vars = (this.exposedVars = {ease:this.vars.ease});
_hasUpdate = false;
}
public function render(_arg1:uint):void{
var _local3:Number;
var _local4:TweenInfo;
var _local5:int;
var _local2:Number = ((_arg1 - this.startTime) * 0.001);
if (_local2 >= this.duration){
_local2 = this.duration;
_local3 = ((((this.ease == this.vars.ease)) || ((this.duration == 0.001)))) ? 1 : 0;
} else {
_local3 = this.ease(_local2, 0, 1, this.duration);
};
_local5 = (this.tweens.length - 1);
while (_local5 > -1) {
_local4 = this.tweens[_local5];
_local4.target[_local4.property] = (_local4.start + (_local3 * _local4.change));
_local5--;
};
if (_hasUpdate){
this.vars.onUpdate.apply(null, this.vars.onUpdateParams);
};
if (_local2 == this.duration){
complete(true);
};
}
public function activate():void{
this.started = (this.active = true);
if (!this.initted){
initTweenVals();
};
if (this.vars.onStart != null){
this.vars.onStart.apply(null, this.vars.onStartParams);
};
if (this.duration == 0.001){
this.startTime = (this.startTime - 1);
};
}
public function initTweenVals():void{
var _local1:String;
var _local2:int;
var _local3:*;
var _local4:TweenInfo;
if (((!((this.exposedVars.timeScale == undefined))) && (this.target.hasOwnProperty("timeScale")))){
this.tweens[this.tweens.length] = new TweenInfo(this.target, "timeScale", this.target.timeScale, (this.exposedVars.timeScale - this.target.timeScale), "timeScale", false);
};
for (_local1 in this.exposedVars) {
if ((_local1 in _reservedProps)){
} else {
if ((_local1 in plugins)){
_local3 = new (plugins[_local1]);
if (_local3.onInitTween(this.target, this.exposedVars[_local1], this) == false){
this.tweens[this.tweens.length] = new TweenInfo(this.target, _local1, this.target[_local1], ((typeof(this.exposedVars[_local1]))=="number") ? (this.exposedVars[_local1] - this.target[_local1]) : Number(this.exposedVars[_local1]), _local1, false);
} else {
this.tweens[this.tweens.length] = new TweenInfo(_local3, "changeFactor", 0, 1, ((_local3.overwriteProps.length)==1) ? _local3.overwriteProps[0] : "_MULTIPLE_", true);
_hasPlugins = true;
};
} else {
this.tweens[this.tweens.length] = new TweenInfo(this.target, _local1, this.target[_local1], ((typeof(this.exposedVars[_local1]))=="number") ? (this.exposedVars[_local1] - this.target[_local1]) : Number(this.exposedVars[_local1]), _local1, false);
};
};
};
if (this.vars.runBackwards == true){
_local2 = (this.tweens.length - 1);
while (_local2 > -1) {
_local4 = this.tweens[_local2];
this.tweens[_local2].start = (_local4.start + _local4.change);
_local4.change = -(_local4.change);
_local2--;
};
};
if (this.vars.onUpdate != null){
_hasUpdate = true;
};
if (((TweenLite.overwriteManager.enabled) && ((this.target in masterList)))){
overwriteManager.manageOverwrites(this, masterList[this.target]);
};
this.initted = true;
}
protected function easeProxy(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number):Number{
return (this.vars.proxiedEase.apply(null, arguments.concat(this.vars.easeParams)));
}
public function killVars(_arg1:Object):void{
if (overwriteManager.enabled){
overwriteManager.killVars(_arg1, this.exposedVars, this.tweens);
};
}
public function complete(_arg1:Boolean=false):void{
var _local2:int;
if (!_arg1){
if (!this.initted){
initTweenVals();
};
this.startTime = (currentTime - ((this.duration * 1000) / this.combinedTimeScale));
render(currentTime);
return;
};
if (_hasPlugins){
_local2 = (this.tweens.length - 1);
while (_local2 > -1) {
if (((this.tweens[_local2].isPlugin) && (!((this.tweens[_local2].target.onComplete == null))))){
this.tweens[_local2].target.onComplete();
};
_local2--;
};
};
if (this.vars.persist != true){
this.enabled = false;
};
if (this.vars.onComplete != null){
this.vars.onComplete.apply(null, this.vars.onCompleteParams);
};
}
public static function updateAll(_arg1:Event=null):void{
var _local4:Array;
var _local5:int;
var _local6:TweenLite;
var _local2:uint = (currentTime = getTimer());
var _local3:Dictionary = masterList;
for each (_local4 in _local3) {
_local5 = (_local4.length - 1);
while (_local5 > -1) {
_local6 = _local4[_local5];
if (_local6.active){
_local6.render(_local2);
} else {
if (_local6.gc){
_local4.splice(_local5, 1);
} else {
if (_local2 >= _local6.startTime){
_local6.activate();
_local6.render(_local2);
};
};
};
_local5--;
};
};
}
public static function removeTween(_arg1:TweenLite, _arg2:Boolean=true):void{
if (_arg1 != null){
if (_arg2){
_arg1.clear();
};
_arg1.enabled = false;
};
}
public static function killTweensOf(_arg1:Object=null, _arg2:Boolean=false):void{
var _local3:Array;
var _local4:int;
var _local5:TweenLite;
if (((!((_arg1 == null))) && ((_arg1 in masterList)))){
_local3 = masterList[_arg1];
_local4 = (_local3.length - 1);
while (_local4 > -1) {
_local5 = _local3[_local4];
if (((_arg2) && (!(_local5.gc)))){
_local5.complete(false);
};
_local5.clear();
_local4--;
};
delete masterList[_arg1];
};
}
public static function from(_arg1:Object, _arg2:Number, _arg3:Object):TweenLite{
_arg3.runBackwards = true;
return (new TweenLite(_arg1, _arg2, _arg3));
}
public static function easeOut(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:Number):Number{
_arg1 = (_arg1 / _arg4);
return ((((-(_arg3) * _arg1) * (_arg1 - 2)) + _arg2));
}
protected static function killGarbage(_arg1:TimerEvent):void{
var _local3:Object;
var _local2:Dictionary = masterList;
for (_local3 in _local2) {
if (_local2[_local3].length == 0){
delete _local2[_local3];
};
};
}
public static function delayedCall(_arg1:Number, _arg2:Function, _arg3:Array=null):TweenLite{
return (new TweenLite(_arg2, 0, {delay:_arg1, onComplete:_arg2, onCompleteParams:_arg3, overwrite:0}));
}
public static function to(_arg1:Object, _arg2:Number, _arg3:Object):TweenLite{
return (new TweenLite(_arg1, _arg2, _arg3));
}
}
}//package gs
Section 14
//MochiAd (mochi.as3.MochiAd)
package mochi.as3 {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
public class MochiAd {
public static function getVersion():String{
return (MochiServices.getVersion());
}
public static function showClickAwayAd(_arg1:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var options = _arg1;
var DEFAULTS:Object = {ad_timeout:2000, regpt:"o", method:"showClickAwayAd", res:"300x250", no_bg:true, ad_started:function ():void{
}, ad_finished:function ():void{
}, ad_loaded:function (_arg1:Number, _arg2:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
clip = options.clip;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
options.ad_finished();
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
mc.unloadAd = function ():void{
MochiAd.unload(clip);
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.rpc = function (_arg1:Number, _arg2:Object):void{
MochiAd.rpc(clip, _arg1, _arg2);
};
var sendHostProgress:Boolean;
mc.regContLC = function (_arg1:String):void{
mc._containerLCName = _arg1;
};
chk["onEnterFrame"] = function ():void{
var _local4:Number;
if (!this.parent){
delete this.onEnterFrame;
return;
};
var _local1:Object = this.parent._mochiad_ctr;
var _local2:Number = (getTimer() - this.started);
var _local3:Boolean;
if (!chk.showing){
_local4 = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (_local4 > 0){
chk.showing = true;
_local3 = true;
chk.started = getTimer();
} else {
if (_local2 > chk.ad_timeout){
options.ad_failed();
_local3 = true;
};
};
};
if (this.root == null){
_local3 = true;
};
if (_local3){
delete this.onEnterFrame;
};
};
doOnEnterFrame(chk);
}
public static function _isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
public static function _allowDomains(_arg1:String):String{
var _local2:String = _arg1.split("/")[2].split(":")[0];
if (Security.sandboxType == "application"){
return (_local2);
};
Security.allowDomain("*");
Security.allowDomain(_local2);
Security.allowInsecureDomain("*");
Security.allowInsecureDomain(_local2);
return (_local2);
}
public static function unload(_arg1:Object):Boolean{
if (((_arg1.clip) && (_arg1.clip._mochiad))){
_arg1 = _arg1.clip;
};
if (_arg1.origFrameRate != undefined){
_arg1.stage.frameRate = _arg1.origFrameRate;
};
if (!_arg1._mochiad){
return (false);
};
if (_arg1._mochiad._containerLCName != undefined){
_arg1._mochiad.lc.send(_arg1._mochiad._containerLCName, "notify", {id:"unload"});
};
if (_arg1._mochiad.onUnload){
_arg1._mochiad.onUnload();
};
delete _arg1._mochiad_loaded;
delete _arg1._mochiad;
return (true);
}
public static function showInterLevelAd(_arg1:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var options = _arg1;
var DEFAULTS:Object = {ad_timeout:2000, fadeout_time:250, regpt:"o", method:"showTimedAd", ad_started:function ():void{
if ((this.clip is MovieClip)){
this.clip.stop();
} else {
throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_finished:function ():void{
if ((this.clip is MovieClip)){
this.clip.play();
} else {
throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_loaded:function (_arg1:Number, _arg2:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
clip = options.clip;
var ad_msec:Number = 11000;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time:Number = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
options.ad_finished();
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.ad_msec = ad_msec;
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function ():void{
if (!this.parent){
delete this.onEnterFrame;
delete this.fadeFunction;
return;
};
var _local1:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time)));
if (_local1 > 0){
this.parent.alpha = (_local1 * 0.01);
} else {
MochiAd.unload(clip);
delete this["onEnterFrame"];
};
};
mc.unloadAd = function ():void{
MochiAd.unload(clip);
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.adjustProgress = function (_arg1:Number):void{
var _local2:Object = mc._mochiad_wait;
_local2.server_control = true;
_local2.showing = true;
_local2.started = getTimer();
_local2.ad_msec = (_arg1 - 250);
};
mc.rpc = function (_arg1:Number, _arg2:Object):void{
MochiAd.rpc(clip, _arg1, _arg2);
};
chk["onEnterFrame"] = function ():void{
var _local4:Number;
if (!this.parent){
delete this.onEnterFrame;
delete this.fadeFunction;
return;
};
var _local1:Object = this.parent._mochiad_ctr;
var _local2:Number = (getTimer() - this.started);
var _local3:Boolean;
if (!chk.showing){
_local4 = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (_local4 > 0){
chk.showing = true;
chk.started = getTimer();
MochiAd.adShowing(clip);
} else {
if (_local2 > chk.ad_timeout){
options.ad_failed();
_local3 = true;
};
};
};
if (_local2 > chk.ad_msec){
_local3 = true;
};
if (_local3){
if (this.server_control){
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = this.fadeFunction;
};
};
};
doOnEnterFrame(chk);
}
public static function _parseOptions(_arg1:Object, _arg2:Object):Object{
var _local4:String;
var _local5:Array;
var _local6:Number;
var _local7:Array;
var _local3:Object = {};
for (_local4 in _arg2) {
_local3[_local4] = _arg2[_local4];
};
if (_arg1){
for (_local4 in _arg1) {
_local3[_local4] = _arg1[_local4];
};
};
if (_local3.clip == undefined){
throw (new Error("MochiAd is missing the 'clip' parameter. This should be a MovieClip, Sprite or an instance of a class that extends MovieClip or Sprite."));
};
_arg1 = _local3.clip.loaderInfo.parameters.mochiad_options;
if (_arg1){
_local5 = _arg1.split("&");
_local6 = 0;
while (_local6 < _local5.length) {
_local7 = _local5[_local6].split("=");
_local3[unescape(_local7[0])] = unescape(_local7[1]);
_local6++;
};
};
if (_local3.id == "test"){
trace("[MochiAd] WARNING: Using the MochiAds test identifier, make sure to use the code from your dashboard, not this example!");
};
return (_local3);
}
public static function _cleanup(_arg1:Object):void{
var k:String;
var lc:LocalConnection;
var f:Function;
var mc = _arg1;
if (("lc" in mc)){
lc = mc.lc;
f = function ():void{
try {
lc.client = null;
lc.close();
} catch(e:Error) {
};
};
setTimeout(f, 0);
};
var idx:Number = DisplayObjectContainer(mc).numChildren;
while (idx > 0) {
idx = (idx - 1);
DisplayObjectContainer(mc).removeChildAt(idx);
};
for (k in mc) {
delete mc[k];
};
}
public static function load(_arg1:Object):MovieClip{
var clip:Object;
var k:String;
var server:String;
var hostname:String;
var lc:LocalConnection;
var name:String;
var loader:Loader;
var g:Function;
var req:URLRequest;
var v:Object;
var options = _arg1;
var DEFAULTS:Object = {server:"http://x.mochiads.com/srv/1/", method:"load", depth:10333, id:"_UNKNOWN_"};
options = MochiAd._parseOptions(options, DEFAULTS);
options.swfv = 9;
options.mav = MochiAd.getVersion();
clip = options.clip;
if (!MochiAd._isNetworkAvailable()){
return (null);
};
try {
if (clip._mochiad_loaded){
return (null);
};
} catch(e:Error) {
throw (new Error("MochiAd requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic."));
};
var depth:Number = options.depth;
delete options.depth;
var mc:MovieClip = createEmptyMovieClip(clip, "_mochiad", depth);
var wh:Array = MochiAd._getRes(options, clip);
options.res = ((wh[0] + "x") + wh[1]);
options.server = (options.server + options.id);
delete options.id;
clip._mochiad_loaded = true;
if (clip.loaderInfo.loaderURL.indexOf("http") == 0){
options.as3_swf = clip.loaderInfo.loaderURL;
} else {
trace("[MochiAd] NOTE: Security Sandbox Violation errors below are normal");
};
var lv:URLVariables = new URLVariables();
for (k in options) {
v = options[k];
if (!(v is Function)){
lv[k] = v;
};
};
server = lv.server;
delete lv.server;
hostname = _allowDomains(server);
lc = new LocalConnection();
lc.client = mc;
name = ["", Math.floor(new Date().getTime()), Math.floor((Math.random() * 999999))].join("_");
lc.allowDomain("*", "localhost");
lc.allowInsecureDomain("*", "localhost");
lc.connect(name);
mc.lc = lc;
mc.lcName = name;
lv.lc = name;
lv.st = getTimer();
loader = new Loader();
g = function (_arg1:Object):void{
_arg1.target.removeEventListener(_arg1.type, arguments.callee);
MochiAd.unload(clip);
};
loader.contentLoaderInfo.addEventListener(Event.UNLOAD, g);
req = new URLRequest(((server + ".swf?cacheBust=") + new Date().getTime()));
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function (_arg1:IOErrorEvent):void{
trace("[MochiAds] Blocked URL");
});
loader.load(req);
mc.addChild(loader);
mc._mochiad_ctr = loader;
return (mc);
}
public static function runMethod(_arg1:Object, _arg2:String, _arg3:Array):Object{
var _local4:Array = _arg2.split(".");
var _local5:Number = 0;
while (_local5 < (_local4.length - 1)) {
if ((((_arg1[_local4[_local5]] == undefined)) || ((_arg1[_local4[_local5]] == null)))){
return (undefined);
};
_arg1 = _arg1[_local4[_local5]];
_local5++;
};
if (typeof(_arg1[_local4[_local5]]) == "function"){
return (_arg1[_local4[_local5]].apply(_arg1, _arg3));
};
return (undefined);
}
public static function createEmptyMovieClip(_arg1:Object, _arg2:String, _arg3:Number):MovieClip{
var _local4:MovieClip = new MovieClip();
if (((false) && (_arg3))){
_arg1.addChildAt(_local4, _arg3);
} else {
_arg1.addChild(_local4);
};
_arg1[_arg2] = _local4;
_local4["_name"] = _arg2;
return (_local4);
}
public static function _getRes(_arg1:Object, _arg2:Object):Array{
var _local6:Array;
var _local3:Object = _arg2.getBounds(_arg2.root);
var _local4:Number = 0;
var _local5:Number = 0;
if (typeof(_arg1.res) != "undefined"){
_local6 = _arg1.res.split("x");
_local4 = parseFloat(_local6[0]);
_local5 = parseFloat(_local6[1]);
} else {
_local4 = (_local3.xMax - _local3.xMin);
_local5 = (_local3.yMax - _local3.yMin);
};
if ((((_local4 == 0)) || ((_local5 == 0)))){
_local4 = _arg2.stage.stageWidth;
_local5 = _arg2.stage.stageHeight;
};
return ([_local4, _local5]);
}
public static function adShowing(_arg1:Object):void{
_arg1.origFrameRate = _arg1.stage.frameRate;
_arg1.stage.frameRate = 30;
}
public static function getValue(_arg1:Object, _arg2:String):Object{
var _local3:Array = _arg2.split(".");
var _local4:Number = 0;
while (_local4 < (_local3.length - 1)) {
if ((((_arg1[_local3[_local4]] == undefined)) || ((_arg1[_local3[_local4]] == null)))){
return (undefined);
};
_arg1 = _arg1[_local3[_local4]];
_local4++;
};
return (_arg1[_local3[_local4]]);
}
public static function rpc(_arg1:Object, _arg2:Number, _arg3:Object):void{
var _local4:Object;
var _local5:Object;
switch (_arg3.id){
case "setValue":
MochiAd.setValue(_arg1, _arg3.objectName, _arg3.value);
break;
case "getValue":
_local4 = MochiAd.getValue(_arg1, _arg3.objectName);
_arg1._mochiad.lc.send(_arg1._mochiad._containerLCName, "rpcResult", _arg2, _local4);
break;
case "runMethod":
_local5 = MochiAd.runMethod(_arg1, _arg3.method, _arg3.args);
_arg1._mochiad.lc.send(_arg1._mochiad._containerLCName, "rpcResult", _arg2, _local5);
break;
default:
trace(("[mochiads rpc] unknown rpc id: " + _arg3.id));
};
}
public static function setValue(_arg1:Object, _arg2:String, _arg3:Object):void{
var _local4:Array = _arg2.split(".");
var _local5:Number = 0;
while (_local5 < (_local4.length - 1)) {
if ((((_arg1[_local4[_local5]] == undefined)) || ((_arg1[_local4[_local5]] == null)))){
return;
};
_arg1 = _arg1[_local4[_local5]];
_local5++;
};
_arg1[_local4[_local5]] = _arg3;
}
public static function showPreGameAd(_arg1:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var complete:Boolean;
var unloaded:Boolean;
var sendHostProgress:Boolean;
var fn:Function;
var r:MovieClip;
var options = _arg1;
var DEFAULTS:Object = {ad_timeout:3000, fadeout_time:250, regpt:"o", method:"showPreloaderAd", color:0xFF8A00, background:16777161, outline:13994812, no_progress_bar:false, ad_started:function ():void{
if ((this.clip is MovieClip)){
this.clip.stop();
} else {
throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_finished:function ():void{
if ((this.clip is MovieClip)){
this.clip.play();
} else {
throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_loaded:function (_arg1:Number, _arg2:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}, ad_progress:function (_arg1:Number):void{
}, progress_override:function (_arg1:Object):Number{
return (NaN);
}, bar_offset:0};
options = MochiAd._parseOptions(options, DEFAULTS);
if ("c862232051e0a94e1c3609b3916ddb17".substr(0) == "dfeada81ac97cde83665f81c12da7def"){
options.ad_started();
fn = function ():void{
options.ad_finished();
};
setTimeout(fn, 100);
return;
};
clip = options.clip;
var ad_msec:Number = 11000;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time:Number = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
var fn:Function = function ():void{
options.ad_finished();
};
setTimeout(fn, 100);
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.x = (w * -0.5);
chk.y = (h * -0.5);
var bar:MovieClip = createEmptyMovieClip(chk, "_mochiad_bar", 4);
if (options.no_progress_bar){
bar.visible = false;
delete options.no_progress_bar;
} else {
bar.x = (10 + options.bar_offset);
bar.y = (h - 20);
};
var bar_w:Number = ((w - bar.x) - 10);
var bar_color:Number = options.color;
delete options.color;
var bar_background:Number = options.background;
delete options.background;
var bar_outline:Number = options.outline;
delete options.outline;
var backing_mc:MovieClip = createEmptyMovieClip(bar, "_outline", 1);
var backing:Object = backing_mc.graphics;
backing.beginFill(bar_background);
backing.moveTo(0, 0);
backing.lineTo(bar_w, 0);
backing.lineTo(bar_w, 10);
backing.lineTo(0, 10);
backing.lineTo(0, 0);
backing.endFill();
var inside_mc:MovieClip = createEmptyMovieClip(bar, "_inside", 2);
var inside:Object = inside_mc.graphics;
inside.beginFill(bar_color);
inside.moveTo(0, 0);
inside.lineTo(bar_w, 0);
inside.lineTo(bar_w, 10);
inside.lineTo(0, 10);
inside.lineTo(0, 0);
inside.endFill();
inside_mc.scaleX = 0;
var outline_mc:MovieClip = createEmptyMovieClip(bar, "_outline", 3);
var outline:Object = outline_mc.graphics;
outline.lineStyle(0, bar_outline, 100);
outline.moveTo(0, 0);
outline.lineTo(bar_w, 0);
outline.lineTo(bar_w, 10);
outline.lineTo(0, 10);
outline.lineTo(0, 0);
chk.ad_msec = ad_msec;
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
chk.last_pcnt = 0;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function ():void{
var _local1:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time)));
if (_local1 > 0){
this.parent.alpha = (_local1 * 0.01);
} else {
MochiAd.unload(clip);
delete this["onEnterFrame"];
};
};
complete = false;
unloaded = false;
var progress:Number = Math.min(1, options.progress_override(clip));
var f:Function = function (_arg1:Event):void{
_arg1.target.removeEventListener(_arg1.type, arguments.callee);
complete = true;
if (unloaded){
MochiAd.unload(clip);
};
};
if (!isNaN(progress)){
complete = (progress == 1);
} else {
if (clip.loaderInfo.bytesLoaded == clip.loaderInfo.bytesTotal){
complete = true;
} else {
if ((clip.root is MovieClip)){
r = (clip.root as MovieClip);
if (r.framesLoaded >= r.totalFrames){
complete = true;
} else {
clip.loaderInfo.addEventListener(Event.COMPLETE, f);
};
} else {
clip.loaderInfo.addEventListener(Event.COMPLETE, f);
};
};
};
mc.unloadAd = function ():void{
unloaded = true;
if (complete){
MochiAd.unload(clip);
};
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.adjustProgress = function (_arg1:Number):void{
var _local2:Object = mc._mochiad_wait;
_local2.server_control = true;
_local2.showing = true;
_local2.started = getTimer();
_local2.ad_msec = _arg1;
};
mc.rpc = function (_arg1:Number, _arg2:Object):void{
MochiAd.rpc(clip, _arg1, _arg2);
};
mc.rpcTestFn = function (_arg1:String):Object{
trace(("[MOCHIAD rpcTestFn] " + _arg1));
return (_arg1);
};
mc.regContLC = function (_arg1:String):void{
mc._containerLCName = _arg1;
};
sendHostProgress = false;
mc.sendHostLoadProgress = function (_arg1:String):void{
sendHostProgress = true;
};
chk["onEnterFrame"] = function ():void{
var _local12:Number;
if (((!(this.parent)) || (!(this.parent.parent)))){
delete this["onEnterFrame"];
return;
};
var _local1:Object = this.parent.parent.root;
var _local2:Object = this.parent._mochiad_ctr;
var _local3:Number = (getTimer() - this.started);
var _local4:Boolean;
var _local5:Number = _local1.loaderInfo.bytesTotal;
var _local6:Number = _local1.loaderInfo.bytesLoaded;
var _local7:Number = Math.min(1, options.progress_override(_local1));
if (_local7 == 1){
complete = true;
};
if (complete){
_local6 = Math.max(1, _local6);
_local5 = _local6;
};
var _local8:Number = ((100 * _local6) / _local5);
if (!isNaN(_local7)){
_local8 = (100 * _local7);
};
var _local9:Number = ((100 * _local3) / chk.ad_msec);
var _local10:Object = this._mochiad_bar._inside;
var _local11:Number = Math.min(100, Math.min(((_local8) || (0)), _local9));
_local11 = Math.max(this.last_pcnt, _local11);
this.last_pcnt = _local11;
_local10.scaleX = (_local11 * 0.01);
options.ad_progress(_local11);
if (sendHostProgress){
clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"hostLoadPcnt", pcnt:_local8});
if (_local8 >= 100){
sendHostProgress = false;
};
};
if (!chk.showing){
_local12 = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (_local12 > 0){
chk.showing = true;
chk.started = getTimer();
MochiAd.adShowing(clip);
} else {
if ((((_local3 > chk.ad_timeout)) && ((_local8 == 100)))){
options.ad_failed();
_local4 = true;
};
};
};
if (_local3 > chk.ad_msec){
_local4 = true;
};
if (((complete) && (_local4))){
if (unloaded){
MochiAd.unload(_local1);
} else {
if (this.server_control){
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = chk.fadeFunction;
};
};
};
};
doOnEnterFrame(chk);
}
public static function showPreloaderAd(_arg1:Object):void{
trace("[MochiAd] DEPRECATED: showPreloaderAd was renamed to showPreGameAd in 2.0");
MochiAd.showPreGameAd(_arg1);
}
public static function showTimedAd(_arg1:Object):void{
trace("[MochiAd] DEPRECATED: showTimedAd was renamed to showInterLevelAd in 2.0");
MochiAd.showInterLevelAd(_arg1);
}
public static function doOnEnterFrame(_arg1:MovieClip):void{
var mc = _arg1;
var f:Function = function (_arg1:Object):void{
if (((("onEnterFrame" in mc)) && (mc.onEnterFrame))){
mc.onEnterFrame();
} else {
_arg1.target.removeEventListener(_arg1.type, arguments.callee);
};
};
mc.addEventListener(Event.ENTER_FRAME, f);
}
}
}//package mochi.as3
Section 15
//MochiCoins (mochi.as3.MochiCoins)
package mochi.as3 {
public class MochiCoins {
public static const STORE_HIDE:String = "StoreHide";
public static const LOGGED_IN:String = "LoggedIn";
public static const STORE_ITEMS:String = "StoreItems";
public static const NO_USER:String = "NoUser";
public static const PROPERTIES_SIZE:String = "PropertiesSize";
public static const ITEM_NEW:String = "ItemNew";
public static const USER_INFO:String = "UserInfo";
public static const IO_ERROR:String = "IOError";
public static const ITEM_OWNED:String = "ItemOwned";
public static const PROPERTIES_SAVED:String = "PropertySaved";
public static const WIDGET_LOADED:String = "WidgetLoaded";
public static const ERROR:String = "Error";
public static const LOGGED_OUT:String = "LoggedOut";
public static const PROFILE_SHOW:String = "ProfileShow";
public static const LOGIN_HIDE:String = "LoginHide";
public static const LOGIN_SHOW:String = "LoginShow";
public static const STORE_SHOW:String = "StoreShow";
public static const PROFILE_HIDE:String = "ProfileHide";
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
public static function showItem(_arg1:Object=null):void{
if (((!(_arg1)) || (!((typeof(_arg1.item) == "string"))))){
trace("ERROR: showItem call must pass an Object with an item key");
return;
};
MochiServices.bringToTop();
MochiServices.send("coins_showItem", {options:_arg1}, null, null);
}
public static function saveUserProperties(_arg1:Object):void{
MochiServices.send("coins_saveUserProperties", _arg1);
}
public static function triggerEvent(_arg1:String, _arg2:Object):void{
_dispatcher.triggerEvent(_arg1, _arg2);
}
public static function showLoginWidget(_arg1:Object=null):void{
MochiServices.setContainer();
MochiServices.bringToTop();
MochiServices.send("coins_showLoginWidget", {options:_arg1});
}
public static function getStoreItems():void{
MochiServices.send("coins_getStoreItems");
}
public static function getVersion():String{
return (MochiServices.getVersion());
}
public static function showStore(_arg1:Object=null):void{
MochiServices.bringToTop();
MochiServices.send("coins_showStore", {options:_arg1}, null, null);
}
public static function addEventListener(_arg1:String, _arg2:Function):void{
_dispatcher.addEventListener(_arg1, _arg2);
}
public static function getUserInfo():void{
MochiServices.send("coins_getUserInfo");
}
public static function hideLoginWidget():void{
MochiServices.send("coins_hideLoginWidget");
}
public static function removeEventListener(_arg1:String, _arg2:Function):void{
_dispatcher.removeEventListener(_arg1, _arg2);
}
public static function showVideo(_arg1:Object=null):void{
if (((!(_arg1)) || (!((typeof(_arg1.item) == "string"))))){
trace("ERROR: showVideo call must pass an Object with an item key");
return;
};
MochiServices.bringToTop();
MochiServices.send("coins_showVideo", {options:_arg1}, null, null);
}
}
}//package mochi.as3
Section 16
//MochiDigits (mochi.as3.MochiDigits)
package mochi.as3 {
public final class MochiDigits {
private var Sibling:MochiDigits;
private var Fragment:Number;
private var Encoder:Number;
public function MochiDigits(_arg1:Number=0, _arg2:uint=0):void{
Encoder = 0;
setValue(_arg1, _arg2);
}
public function reencode():void{
var _local1:uint = int((2147483647 * Math.random()));
Fragment = (Fragment ^ (_local1 ^ Encoder));
Encoder = _local1;
}
public function set value(_arg1:Number):void{
setValue(_arg1);
}
public function toString():String{
var _local1:String = String.fromCharCode((Fragment ^ Encoder));
if (Sibling != null){
_local1 = (_local1 + Sibling.toString());
};
return (_local1);
}
public function setValue(_arg1:Number=0, _arg2:uint=0):void{
var _local3:String = _arg1.toString();
var _temp1 = _arg2;
_arg2 = (_arg2 + 1);
Fragment = (_local3.charCodeAt(_temp1) ^ Encoder);
if (_arg2 < _local3.length){
Sibling = new MochiDigits(_arg1, _arg2);
} else {
Sibling = null;
};
reencode();
}
public function get value():Number{
return (Number(this.toString()));
}
public function addValue(_arg1:Number):void{
value = (value + _arg1);
}
}
}//package mochi.as3
Section 17
//MochiEventDispatcher (mochi.as3.MochiEventDispatcher)
package mochi.as3 {
public class MochiEventDispatcher {
private var eventTable:Object;
public function MochiEventDispatcher():void{
eventTable = {};
}
public function triggerEvent(_arg1:String, _arg2:Object):void{
var _local3:Object;
if (eventTable[_arg1] == undefined){
return;
};
for (_local3 in eventTable[_arg1]) {
var _local6 = eventTable[_arg1];
_local6[_local3](_arg2);
};
}
public function removeEventListener(_arg1:String, _arg2:Function):void{
var _local3:Object;
if (eventTable[_arg1] == undefined){
eventTable[_arg1] = [];
return;
};
for (_local3 in eventTable[_arg1]) {
if (eventTable[_arg1][_local3] != _arg2){
} else {
eventTable[_arg1].splice(Number(_local3), 1);
};
};
}
public function addEventListener(_arg1:String, _arg2:Function):void{
removeEventListener(_arg1, _arg2);
eventTable[_arg1].push(_arg2);
}
}
}//package mochi.as3
Section 18
//MochiEvents (mochi.as3.MochiEvents)
package mochi.as3 {
import flash.display.*;
public class MochiEvents {
public static const ALIGN_BOTTOM_LEFT:String = "ALIGN_BL";
public static const FORMAT_LONG:String = "LongForm";
public static const ALIGN_BOTTOM:String = "ALIGN_B";
public static const ACHIEVEMENT_RECEIVED:String = "AchievementReceived";
public static const FORMAT_SHORT:String = "ShortForm";
public static const ALIGN_TOP_RIGHT:String = "ALIGN_TR";
public static const ALIGN_BOTTOM_RIGHT:String = "ALIGN_BR";
public static const ALIGN_TOP:String = "ALIGN_T";
public static const ALIGN_LEFT:String = "ALIGN_L";
public static const ALIGN_RIGHT:String = "ALIGN_R";
public static const ALIGN_TOP_LEFT:String = "ALIGN_TL";
public static const ALIGN_CENTER:String = "ALIGN_C";
private static var _dispatcher:MochiEventDispatcher = new MochiEventDispatcher();
private static var gameStart:Number;
private static var levelStart:Number;
public static function addEventListener(_arg1:String, _arg2:Function):void{
_dispatcher.addEventListener(_arg1, _arg2);
}
public static function removeEventListener(_arg1:String, _arg2:Function):void{
_dispatcher.removeEventListener(_arg1, _arg2);
}
public static function startSession(_arg1:String):void{
MochiServices.send("events_beginSession", {achievementID:_arg1}, null, null);
}
public static function triggerEvent(_arg1:String, _arg2:Object):void{
_dispatcher.triggerEvent(_arg1, _arg2);
}
public static function setNotifications(_arg1:MovieClip, _arg2:Object):void{
var _local4:Object;
var _local3:Object = {};
for (_local4 in _arg2) {
_local3[_local4] = _arg2[_local4];
};
_local3.clip = _arg1;
MochiServices.send("events_setNotifications", _local3, null, null);
}
public static function endGame():void{
var _local1:Number = (new Date().time - gameStart);
trigger("end_game", {time:_local1});
}
public static function startGame():void{
gameStart = new Date().time;
trigger("start_game");
}
public static function trigger(_arg1:String, _arg2:Object=null):void{
if (_arg2 == null){
_arg2 = {};
} else {
if (_arg2["kind"] != undefined){
trace("WARNING: optional arguements package contains key 'id', it will be overwritten");
_arg2["kind"] = _arg1;
};
};
MochiServices.send("events_triggerEvent", {eventObject:_arg2}, null, null);
}
public static function getVersion():String{
return (MochiServices.getVersion());
}
public static function startLevel():void{
levelStart = new Date().time;
trigger("start_level");
}
public static function endLevel():void{
var _local1:Number = (new Date().time - levelStart);
trigger("end_level", {time:_local1});
}
}
}//package mochi.as3
Section 19
//MochiScores (mochi.as3.MochiScores)
package mochi.as3 {
import flash.display.*;
import flash.text.*;
public class MochiScores {
private static var boardID:String;
public static var onErrorHandler:Object;
public static var onCloseHandler:Object;
public static function showLeaderboard(_arg1:Object=null):void{
var n:Number;
var options = _arg1;
if (options != null){
delete options.clip;
MochiServices.setContainer();
MochiServices.bringToTop();
if (options.name != null){
if ((options.name is TextField)){
if (options.name.text.length > 0){
options.name = options.name.text;
};
};
};
if (options.score != null){
if ((options.score is TextField)){
if (options.score.text.length > 0){
options.score = options.score.text;
};
} else {
if ((options.score is MochiDigits)){
options.score = options.score.value;
};
};
n = Number(options.score);
if (isNaN(n)){
trace((("ERROR: Submitted score '" + options.score) + "' will be rejected, score is 'Not a Number'"));
} else {
if ((((n == Number.NEGATIVE_INFINITY)) || ((n == Number.POSITIVE_INFINITY)))){
trace((("ERROR: Submitted score '" + options.score) + "' will be rejected, score is an infinite"));
} else {
if (Math.floor(n) != n){
trace((("WARNING: Submitted score '" + options.score) + "' will be truncated"));
};
options.score = n;
};
};
};
if (options.onDisplay != null){
options.onDisplay();
} else {
if (MochiServices.clip != null){
if ((MochiServices.clip is MovieClip)){
MochiServices.clip.stop();
} else {
trace("Warning: Container is not a MovieClip, cannot call default onDisplay.");
};
};
};
} else {
options = {};
if ((MochiServices.clip is MovieClip)){
MochiServices.clip.stop();
} else {
trace("Warning: Container is not a MovieClip, cannot call default onDisplay.");
};
};
if (options.onClose != null){
onCloseHandler = options.onClose;
} else {
onCloseHandler = function ():void{
if ((MochiServices.clip is MovieClip)){
MochiServices.clip.play();
} else {
trace("Warning: Container is not a MovieClip, cannot call default onClose.");
};
};
};
if (options.onError != null){
onErrorHandler = options.onError;
} else {
onErrorHandler = null;
};
if (options.boardID == null){
if (MochiScores.boardID != null){
options.boardID = MochiScores.boardID;
};
};
MochiServices.warnID(options.boardID, true);
trace("[MochiScores] NOTE: Security Sandbox Violation errors below are normal");
MochiServices.send("scores_showLeaderboard", {options:options}, null, onClose);
}
public static function closeLeaderboard():void{
MochiServices.send("scores_closeLeaderboard");
}
public static function getPlayerInfo(_arg1:Object, _arg2:Object=null):void{
MochiServices.send("scores_getPlayerInfo", null, _arg1, _arg2);
}
public static function requestList(_arg1:Object, _arg2:Object=null):void{
MochiServices.send("scores_requestList", null, _arg1, _arg2);
}
public static function scoresArrayToObjects(_arg1:Object):Object{
var _local3:Number;
var _local4:Number;
var _local5:Object;
var _local6:Object;
var _local7:String;
var _local8:String;
var _local2:Object = {};
for (_local7 in _arg1) {
if (typeof(_arg1[_local7]) == "object"){
if (((!((_arg1[_local7].cols == null))) && (!((_arg1[_local7].rows == null))))){
_local2[_local7] = [];
_local5 = _arg1[_local7];
_local4 = 0;
while (_local4 < _local5.rows.length) {
_local6 = {};
_local3 = 0;
while (_local3 < _local5.cols.length) {
_local6[_local5.cols[_local3]] = _local5.rows[_local4][_local3];
_local3++;
};
_local2[_local7].push(_local6);
_local4++;
};
} else {
_local2[_local7] = {};
for (_local8 in _arg1[_local7]) {
_local2[_local7][_local8] = _arg1[_local7][_local8];
};
};
} else {
_local2[_local7] = _arg1[_local7];
};
};
return (_local2);
}
public static function submit(_arg1:Number, _arg2:String, _arg3:Object=null, _arg4:Object=null):void{
_arg1 = Number(_arg1);
if (isNaN(_arg1)){
trace((("ERROR: Submitted score '" + String(_arg1)) + "' will be rejected, score is 'Not a Number'"));
} else {
if ((((_arg1 == Number.NEGATIVE_INFINITY)) || ((_arg1 == Number.POSITIVE_INFINITY)))){
trace((("ERROR: Submitted score '" + String(_arg1)) + "' will be rejected, score is an infinite"));
} else {
if (Math.floor(_arg1) != _arg1){
trace((("WARNING: Submitted score '" + String(_arg1)) + "' will be truncated"));
};
_arg1 = Number(_arg1);
};
};
MochiServices.send("scores_submit", {score:_arg1, name:_arg2}, _arg3, _arg4);
}
public static function onClose(_arg1:Object=null):void{
if (((((_arg1) && ((_arg1.error == true)))) && (onErrorHandler))){
if (_arg1.errorCode == null){
_arg1.errorCode = "IOError";
};
onErrorHandler(_arg1.errorCode);
MochiServices.doClose();
return;
};
onCloseHandler();
MochiServices.doClose();
}
public static function setBoardID(_arg1:String):void{
MochiServices.warnID(_arg1, true);
MochiScores.boardID = _arg1;
MochiServices.send("scores_setBoardID", {boardID:_arg1});
}
}
}//package mochi.as3
Section 20
//MochiServices (mochi.as3.MochiServices)
package mochi.as3 {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
public class MochiServices {
private static var _container:Object;
private static var _connected:Boolean = false;
private static var _swfVersion:String;
private static var _preserved:Object;
public static var netupAttempted:Boolean = false;
private static var _sendChannel:LocalConnection;
public static var servicesSync:MochiSync = new MochiSync();
private static var _clip:MovieClip;
private static var _id:String;
private static var _services:String = "services.swf";
private static var _servURL:String = "http://www.mochiads.com/static/lib/services/";
public static var widget:Boolean = false;
private static var _timer:Timer;
private static var _sendChannelName:String;
private static var _loader:Loader;
private static var _connecting:Boolean = false;
private static var _mochiLocalConnection:MovieClip;
private static var _listenChannelName:String = "__ms_";
public static var onError:Object;
public static var netup:Boolean = true;
private static var _mochiLC:String = "MochiLC.swf";
public static function isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
public static function get connected():Boolean{
return (_connected);
}
private static function onReceive(_arg1:Object):void{
var methodName:String;
var pkg = _arg1;
var cb:String = pkg.callbackID;
var cblst:Object = _clip._callbacks[cb];
if (!cblst){
return;
};
var method:* = cblst.callbackMethod;
methodName = "";
var obj:Object = cblst.callbackObject;
if (((obj) && ((typeof(method) == "string")))){
methodName = method;
if (obj[method] != null){
method = obj[method];
} else {
trace((("Error: Method " + method) + " does not exist."));
};
};
if (method != undefined){
try {
method.apply(obj, pkg.args);
} catch(error:Error) {
trace(((("Error invoking callback method '" + methodName) + "': ") + error.toString()));
};
} else {
if (obj != null){
try {
obj(pkg.args);
} catch(error:Error) {
trace(("Error invoking method on object: " + error.toString()));
};
};
};
delete _clip._callbacks[cb];
}
public static function get childClip():Object{
return (_clip);
}
public static function send(_arg1:String, _arg2:Object=null, _arg3:Object=null, _arg4:Object=null):void{
if (_connected){
_mochiLocalConnection.send(_sendChannelName, "onReceive", {methodName:_arg1, args:_arg2, callbackID:_clip._nextcallbackID});
} else {
if ((((_clip == null)) || (!(_connecting)))){
trace(("Error: MochiServices not connected. Please call MochiServices.connect(). Function: " + _arg1));
handleError(_arg2, _arg3, _arg4);
flush(true);
return;
};
_clip._queue.push({methodName:_arg1, args:_arg2, callbackID:_clip._nextcallbackID});
};
if (_clip != null){
if (((!((_clip._callbacks == null))) && (!((_clip._nextcallbackID == null))))){
_clip._callbacks[_clip._nextcallbackID] = {callbackObject:_arg3, callbackMethod:_arg4};
_clip._nextcallbackID++;
};
};
}
private static function init(_arg1:String, _arg2:Object):void{
_id = _arg1;
if (_arg2 != null){
_container = _arg2;
loadCommunicator(_arg1, _container);
};
}
private static function clickMovie(_arg1:String, _arg2:Function):MovieClip{
var _local4:int;
var _local14:Loader;
var _local3:Array = [150, 21, 0, 7, 1, 0, 0, 0, 0, 98, 116, 110, 0, 7, 2, 0, 0, 0, 0, 116, 104, 105, 115, 0, 28, 150, 22, 0, 0, 99, 114, 101, 97, 116, 101, 69, 109, 112, 116, 121, 77, 111, 118, 105, 101, 67, 108, 105, 112, 0, 82, 135, 1, 0, 0, 23, 150, 13, 0, 4, 0, 0, 111, 110, 82, 101, 108, 101, 97, 115, 101, 0, 142, 8, 0, 0, 0, 0, 2, 42, 0, 114, 0, 150, 17, 0, 0, 32, 0, 7, 1, 0, 0, 0, 8, 0, 0, 115, 112, 108, 105, 116, 0, 82, 135, 1, 0, 1, 23, 150, 7, 0, 4, 1, 7, 0, 0, 0, 0, 78, 150, 8, 0, 0, 95, 98, 108, 97, 110, 107, 0, 154, 1, 0, 0, 150, 7, 0, 0, 99, 108, 105, 99, 107, 0, 150, 7, 0, 4, 1, 7, 1, 0, 0, 0, 78, 150, 27, 0, 7, 2, 0, 0, 0, 7, 0, 0, 0, 0, 0, 76, 111, 99, 97, 108, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 0, 64, 150, 6, 0, 0, 115, 101, 110, 100, 0, 82, 79, 150, 15, 0, 4, 0, 0, 95, 97, 108, 112, 104, 97, 0, 7, 0, 0, 0, 0, 79, 150, 23, 0, 7, 0xFF, 0, 0xFF, 0, 7, 1, 0, 0, 0, 4, 0, 0, 98, 101, 103, 105, 110, 70, 105, 108, 108, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 109, 111, 118, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 100, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 100, 0, 0, 0, 7, 100, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 100, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 25, 0, 7, 0, 0, 0, 0, 7, 0, 0, 0, 0, 7, 2, 0, 0, 0, 4, 0, 0, 108, 105, 110, 101, 84, 111, 0, 82, 23, 150, 16, 0, 7, 0, 0, 0, 0, 4, 0, 0, 101, 110, 100, 70, 105, 108, 108, 0, 82, 23];
var _local5:Array = [104, 0, 31, 64, 0, 7, 208, 0, 0, 12, 1, 0, 67, 2, 0xFF, 0xFF, 0xFF, 63, 3];
var _local6:Array = [0, 64, 0, 0, 0];
var _local7:MovieClip = new MovieClip();
var _local8:LocalConnection = new LocalConnection();
var _local9:String = ((("_click_" + Math.floor((Math.random() * 999999))) + "_") + Math.floor(new Date().time));
_local8 = new LocalConnection();
_local7.lc = _local8;
_local7.click = _arg2;
_local8.client = _local7;
_local8.connect(_local9);
var _local10:ByteArray = new ByteArray();
var _local11:ByteArray = new ByteArray();
_local11.endian = Endian.LITTLE_ENDIAN;
_local11.writeShort(1);
_local11.writeUTFBytes(((_arg1 + " ") + _local9));
_local11.writeByte(0);
var _local12:uint = ((_local3.length + _local11.length) + 4);
var _local13:uint = (_local12 + 35);
_local10.endian = Endian.LITTLE_ENDIAN;
_local10.writeUTFBytes("FWS");
_local10.writeByte(8);
_local10.writeUnsignedInt(_local13);
for each (_local4 in _local5) {
_local10.writeByte(_local4);
};
_local10.writeUnsignedInt(_local12);
_local10.writeByte(136);
_local10.writeShort(_local11.length);
_local10.writeBytes(_local11);
for each (_local4 in _local3) {
_local10.writeByte(_local4);
};
for each (_local4 in _local6) {
_local10.writeByte(_local4);
};
_local14 = new Loader();
_local14.loadBytes(_local10);
_local7.addChild(_local14);
return (_local7);
}
public static function stayOnTop():void{
_container.addEventListener(Event.ENTER_FRAME, MochiServices.bringToTop, false, 0, true);
if (_clip != null){
_clip.visible = true;
};
}
public static function addLinkEvent(_arg1:String, _arg2:String, _arg3:DisplayObjectContainer, _arg4:Function=null):void{
var avm1Click:DisplayObject;
var x:String;
var req:URLRequest;
var loader:Loader;
var setURL:Function;
var err:Function;
var complete:Function;
var url = _arg1;
var burl = _arg2;
var btn = _arg3;
var onClick = _arg4;
var vars:Object = new Object();
vars["mav"] = getVersion();
vars["swfv"] = "9";
vars["swfurl"] = btn.loaderInfo.loaderURL;
vars["fv"] = Capabilities.version;
vars["os"] = Capabilities.os;
vars["lang"] = Capabilities.language;
vars["scres"] = ((Capabilities.screenResolutionX + "x") + Capabilities.screenResolutionY);
var s = "?";
var i:Number = 0;
for (x in vars) {
if (i != 0){
s = (s + "&");
};
i = (i + 1);
s = (((s + x) + "=") + escape(vars[x]));
};
req = new URLRequest("http://x.mochiads.com/linkping.swf");
loader = new Loader();
setURL = function (_arg1:String):void{
if (avm1Click){
btn.removeChild(avm1Click);
};
avm1Click = clickMovie(_arg1, onClick);
var _local2:Rectangle = btn.getBounds(btn);
btn.addChild(avm1Click);
avm1Click.x = _local2.x;
avm1Click.y = _local2.y;
avm1Click.scaleX = (0.01 * _local2.width);
avm1Click.scaleY = (0.01 * _local2.height);
};
err = function (_arg1:Object):void{
netup = false;
_arg1.target.removeEventListener(_arg1.type, arguments.callee);
setURL(burl);
};
complete = function (_arg1:Object):void{
_arg1.target.removeEventListener(_arg1.type, arguments.callee);
};
if (netup){
setURL((url + s));
} else {
setURL(burl);
};
if (!((netupAttempted) || (_connected))){
netupAttempted = true;
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, err);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete);
loader.load(req);
};
}
public static function warnID(_arg1:String, _arg2:Boolean):void{
_arg1 = _arg1.toLowerCase();
if (_arg1.length != 16){
trace((("WARNING: " + (_arg2) ? "board" : "game") + " ID is not the appropriate length"));
return;
} else {
if (_arg1 == "1e113c7239048b3f"){
if (_arg2){
trace("WARNING: Using testing board ID");
} else {
trace("WARNING: Using testing board ID as game ID");
};
return;
} else {
if (_arg1 == "84993a1de4031cd8"){
if (_arg2){
trace("WARNING: Using testing game ID as board ID");
} else {
trace("WARNING: Using testing game ID");
};
return;
};
};
};
var _local3:Number = 0;
while (_local3 < _arg1.length) {
switch (_arg1.charAt(_local3)){
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
case "a":
case "b":
case "c":
case "d":
case "e":
case "f":
break;
default:
trace(("WARNING: Board ID contains illegal characters: " + _arg1));
return;
};
_local3++;
};
}
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();
} catch(error:Error) {
};
};
}
public static function allowDomains(_arg1:String):String{
var _local2:String;
if (Security.sandboxType != "application"){
Security.allowDomain("*");
Security.allowInsecureDomain("*");
};
if (_arg1.indexOf("http://") != -1){
_local2 = _arg1.split("/")[2].split(":")[0];
if (Security.sandboxType != "application"){
Security.allowDomain(_local2);
Security.allowInsecureDomain(_local2);
};
};
return (_local2);
}
public static function getVersion():String{
return ("3.3 as3");
}
public static function doClose():void{
_container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop);
}
private static function flush(_arg1:Boolean):void{
var _local2:Object;
var _local3:Object;
if (((_clip) && (_clip._queue))){
while (_clip._queue.length > 0) {
_local2 = _clip._queue.shift();
_local3 = null;
if (_local2 != null){
if (_local2.callbackID != null){
_local3 = _clip._callbacks[_local2.callbackID];
};
delete _clip._callbacks[_local2.callbackID];
if (((_arg1) && (!((_local3 == null))))){
handleError(_local2.args, _local3.callbackObject, _local3.callbackMethod);
};
};
};
};
}
public static function get id():String{
return (_id);
}
private static function onEvent(_arg1:Object):void{
var _local2:String = _arg1.target;
var _local3:String = _arg1.event;
switch (_local2){
case "events":
MochiEvents.triggerEvent(_arg1.event, _arg1.args);
break;
case "coins":
MochiCoins.triggerEvent(_arg1.event, _arg1.args);
break;
case "sync":
servicesSync.triggerEvent(_arg1.event, _arg1.args);
break;
};
}
private static function urlOptions(_arg1:Object):Object{
var _local3:String;
var _local4:Array;
var _local5:Number;
var _local6:Array;
var _local2:Object = {};
if (_arg1.stage){
_local3 = _arg1.stage.loaderInfo.parameters.mochiad_options;
} else {
_local3 = _arg1.loaderInfo.parameters.mochiad_options;
};
if (_local3){
_local4 = _local3.split("&");
_local5 = 0;
while (_local5 < _local4.length) {
_local6 = _local4[_local5].split("=");
_local2[unescape(_local6[0])] = unescape(_local6[1]);
_local5++;
};
};
return (_local2);
}
public static function setContainer(_arg1:Object=null, _arg2:Boolean=true):void{
if (_arg1 != null){
if ((_arg1 is Sprite)){
_container = _arg1;
};
};
if (_arg2){
if ((_container is Sprite)){
Sprite(_container).addChild(_clip);
};
};
}
private static function handleError(_arg1:Object, _arg2:Object, _arg3:Object):void{
var args = _arg1;
var callbackObject = _arg2;
var callbackMethod = _arg3;
if (args != null){
if (args.onError != null){
args.onError.apply(null, ["NotConnected"]);
};
if (((!((args.options == null))) && (!((args.options.onError == null))))){
args.options.onError.apply(null, ["NotConnected"]);
};
};
if (callbackMethod != null){
args = {};
args.error = true;
args.errorCode = "NotConnected";
if (((!((callbackObject == null))) && ((callbackMethod is String)))){
try {
var _local5 = callbackObject;
_local5[callbackMethod](args);
} catch(error:Error) {
};
} else {
if (callbackMethod != null){
try {
callbackMethod.apply(args);
} catch(error:Error) {
};
};
};
};
}
private static function loadError(_arg1:Object):void{
_clip._mochiad_ctr_failed = true;
trace("MochiServices could not load.");
MochiServices.disconnect();
MochiServices.onError("IOError");
}
private static function initComChannels():void{
if (!_connected){
trace("[SERVICES_API] connected!");
_connecting = false;
_connected = true;
_mochiLocalConnection.send(_sendChannelName, "onReceive", {methodName:"handshakeDone"});
_mochiLocalConnection.send(_sendChannelName, "onReceive", {methodName:"registerGame", preserved:_preserved, id:_id, clip:_container, version:getVersion(), parentURL:_container.loaderInfo.loaderURL});
_clip.onReceive = onReceive;
_clip.onEvent = onEvent;
_clip.onError = function ():void{
MochiServices.onError("IOError");
};
while (_clip._queue.length > 0) {
_mochiLocalConnection.send(_sendChannelName, "onReceive", _clip._queue.shift());
};
};
}
private static function loadLCBridge(_arg1:Object):void{
var loader:Loader;
var clip = _arg1;
loader = new Loader();
var mochiLCURL:String = (_servURL + _mochiLC);
var req:URLRequest = new URLRequest(mochiLCURL);
var complete:Function = function (_arg1:Object):void{
_mochiLocalConnection = MovieClip(loader.content);
listen();
};
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
loader.load(req);
clip.addChild(loader);
}
private static function listen():void{
_mochiLocalConnection.connect(_listenChannelName);
_clip.handshake = function (_arg1:Object):void{
MochiServices.comChannelName = _arg1.newChannel;
};
trace("Waiting for MochiAds services to connect...");
}
public static function get clip():Object{
return (_container);
}
public static function set comChannelName(_arg1:String):void{
if (_arg1 != null){
if (_arg1.length > 3){
_sendChannelName = (_arg1 + "_fromgame");
initComChannels();
};
};
}
private static function loadCommunicator(_arg1:String, _arg2:Object):MovieClip{
var _local3:String = ("_mochiservices_com_" + _arg1);
if (_clip != null){
return (_clip);
};
if (!MochiServices.isNetworkAvailable()){
return (null);
};
if (urlOptions(_arg2).servURL){
_servURL = urlOptions(_arg2).servURL;
};
var _local4:String = (_servURL + _services);
if (urlOptions(_arg2).servicesURL){
_local4 = urlOptions(_arg2).servicesURL;
};
_listenChannelName = (_listenChannelName + ((Math.floor(new Date().time) + "_") + Math.floor((Math.random() * 99999))));
MochiServices.allowDomains(_local4);
_clip = createEmptyMovieClip(_arg2, _local3, 10336, false);
loadLCBridge(_clip);
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError);
var _local5:URLRequest = new URLRequest(_local4);
var _local6:URLVariables = new URLVariables();
_local6.listenLC = _listenChannelName;
_local6.mochiad_options = _arg2.loaderInfo.parameters.mochiad_options;
_local6.api_version = getVersion();
if (widget){
_local6.widget = true;
};
_local5.data = _local6;
_loader.load(_local5);
_clip.addChild(_loader);
_clip._mochiservices_com = _loader;
_sendChannel = new LocalConnection();
_clip._queue = [];
_clip._nextcallbackID = 0;
_clip._callbacks = {};
_timer = new Timer(10000, 1);
_timer.addEventListener(TimerEvent.TIMER, connectWait);
_timer.start();
return (_clip);
}
public static function connect(_arg1:String, _arg2:Object, _arg3:Object=null):void{
var id = _arg1;
var clip = _arg2;
var onError = _arg3;
warnID(id, false);
if ((clip is DisplayObject)){
if (((!(_connected)) && ((_clip == null)))){
trace("MochiServices Connecting...");
_connecting = true;
init(id, clip);
};
} else {
trace("Error, MochiServices requires a Sprite, Movieclip or instance of the stage.");
};
if (onError != null){
MochiServices.onError = onError;
} else {
if (MochiServices.onError == null){
MochiServices.onError = function (_arg1:String):void{
trace(_arg1);
};
};
};
}
public static function createEmptyMovieClip(_arg1:Object, _arg2:String, _arg3:Number, _arg4:Boolean=true):MovieClip{
var parent = _arg1;
var name = _arg2;
var depth = _arg3;
var doAdd = _arg4;
var mc:MovieClip = new MovieClip();
if (doAdd){
if (((false) && (depth))){
parent.addChildAt(mc, depth);
} else {
parent.addChild(mc);
};
};
try {
parent[name] = mc;
} catch(e:Error) {
throw (new Error("MochiServices requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic."));
};
mc["_name"] = name;
return (mc);
}
public static function bringToTop(_arg1:Event=null):void{
var e = _arg1;
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) {
trace("Warning: Depth sort error.");
_container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop);
};
};
}
public static function connectWait(_arg1:TimerEvent):void{
if (!_connected){
_clip._mochiad_ctr_failed = true;
trace("MochiServices could not load. (timeout)");
MochiServices.disconnect();
MochiServices.onError("IOError");
};
}
}
}//package mochi.as3
Section 21
//MochiSync (mochi.as3.MochiSync)
package mochi.as3 {
import flash.utils.*;
public dynamic class MochiSync extends Proxy {
private var _syncContainer:Object;
public static var SYNC_PROPERTY:String = "UpdateProperty";
public static var SYNC_REQUEST:String = "SyncRequest";
public function MochiSync():void{
_syncContainer = {};
}
override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function setProperty(_arg1, _arg2):void{
if (_syncContainer[_arg1] == _arg2){
return;
};
var _local3:String = _arg1.toString();
_syncContainer[_local3] = _arg2;
MochiServices.send("sync_propUpdate", {name:_local3, value:_arg2});
}
override "http://www.adobe.com/2006/actionscript/flash/proxy"?? function getProperty(_arg1){
return (_syncContainer[_arg1]);
}
public function triggerEvent(_arg1:String, _arg2:Object):void{
switch (_arg1){
case SYNC_REQUEST:
MochiServices.send("sync_syncronize", _syncContainer);
break;
case SYNC_PROPERTY:
_syncContainer[_arg2.name] = _arg2.value;
break;
};
}
}
}//package mochi.as3
Section 22
//HiScoresBtn_7 (trafficMadness_fla.HiScoresBtn_7)
package trafficMadness_fla {
import flash.display.*;
public dynamic class HiScoresBtn_7 extends MovieClip {
public function HiScoresBtn_7(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 23
//Instructionsbtn_9 (trafficMadness_fla.Instructionsbtn_9)
package trafficMadness_fla {
import flash.display.*;
public dynamic class Instructionsbtn_9 extends MovieClip {
public function Instructionsbtn_9(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 24
//MainMenuBtn_16 (trafficMadness_fla.MainMenuBtn_16)
package trafficMadness_fla {
import flash.display.*;
public dynamic class MainMenuBtn_16 extends MovieClip {
public function MainMenuBtn_16(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 25
//MainTimeline (trafficMadness_fla.MainTimeline)
package trafficMadness_fla {
import flash.display.*;
import flash.events.*;
import gs.*;
import flash.geom.*;
import mochi.as3.*;
import com.coreyoneil.collision.*;
import flash.utils.*;
import flash.media.*;
import flash.text.*;
import flash.net.*;
import flash.system.*;
import flash.errors.*;
import adobe.utils.*;
import flash.accessibility.*;
import flash.external.*;
import flash.filters.*;
import flash.printing.*;
import flash.profiler.*;
import flash.sampler.*;
import flash.ui.*;
import flash.xml.*;
public dynamic class MainTimeline extends MovieClip {
public var score1_txt:TextField;
public var score5_txt:TextField;
public var score9_txt:TextField;
public var inPlay:MovieClip;
public var name4_txt:TextField;
public var name8_txt:TextField;
public var crashSnd;
public var moreGamesBtn:MovieClip;
public var sfxTransform;
public var blur:BitmapData;
public var finished:Boolean;
public var instructionsBtn:MovieClip;
public var hiScoresBtn:MovieClip;
public var mainMenuBtn:MovieClip;
public var playBtn:MovieClip;
public var score4_txt:TextField;
public var score8_txt:TextField;
public var bulletBlocker1:MovieClip;
public var bulletBlocker2:MovieClip;
public var bulletBlocker3:MovieClip;
public var bulletBlocker4:MovieClip;
public var bulletBlocker5:MovieClip;
public var bulletBlocker6:MovieClip;
public var bulletBlocker7:MovieClip;
public var bulletBlocker8:MovieClip;
public var bulletBlocker9:MovieClip;
public var name10_txt:TextField;
public var blurCanvas:Bitmap;
public var scoreTx:TextField;
public var bulletBlocker10:MovieClip;
public var bulletBlocker11:MovieClip;
public var bulletBlocker12:MovieClip;
public var bulletBlocker13:MovieClip;
public var name7_txt:TextField;
public var musicTransform;
public var name3_txt:TextField;
public var fxCanvas:MovieClip;
public var soundBtn:MovieClip;
public var spriteHolder:MovieClip;
public var shootSnd;
public var warningLight:MovieClip;
public var explode:MovieClip;
public var turret:MovieClip;
public var blurHolder:MovieClip;
public var loaderBar:MovieClip;
public var musicSnd;
public var score3_txt:TextField;
public var score7_txt:TextField;
public var musicChan:SoundChannel;
public var soundFxChan:SoundChannel;
public var name2_txt:TextField;
public var name6_txt:TextField;
public var uiHolder:MovieClip;
public var score10_txt:TextField;
public var sp1:MovieClip;
public var sp2:MovieClip;
public var sp3:MovieClip;
public var sp4:MovieClip;
public var score2_txt:TextField;
public var score6_txt:TextField;
public var lastScore:int;
public var timeoutStack:Array;
public var name1_txt:TextField;
public var name5_txt:TextField;
public var name9_txt:TextField;
public var revSnd;
public var game:Object;
public var musicBtn:MovieClip;
public function MainTimeline(){
addFrameScript(0, frame1, 1, frame2, 5, frame6, 14, frame15, 19, frame20, 24, frame25, 32, frame33);
}
public function onMouseUpPlayBtn(_arg1:MouseEvent){
gotoGame();
}
public function onMouseUpPlayAgainBtn(_arg1:MouseEvent){
game.gameOverPopUp.nameTx.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDownNameTx);
game.gameOverPopUp.parent.removeChild(game.gameOverPopUp);
game.gameOverPopUp = null;
gotoMenu();
}
public function loader(_arg1:Event){
var _local2:* = stage.loaderInfo.bytesTotal;
var _local3:* = stage.loaderInfo.bytesLoaded;
var _local4:* = Math.round(((_local3 * 100) / _local2));
loaderBar.scaleX = (_local4 / 100);
if ((((((_local3 >= _local2)) && ((_local3 > 4)))) && ((finished == false)))){
setTimeout(endPreload, 2000);
finished = true;
};
}
public function fisherYates(_arg1){
var _local3:*;
var _local4:*;
var _local5:*;
var _local2:* = _arg1.length;
while (_local2--) {
_local3 = Math.floor((Math.random() * (_local2 + 1)));
_local4 = _arg1[_local2];
_local5 = _arg1[_local3];
_arg1[_local2] = _local5;
_arg1[_local3] = _local4;
};
}
public function newCar(_arg1:Object){
var _local4:*;
var _local2:* = false;
var _local3:MovieClip = new Car();
_local3.label = "car";
if (game.level < 10){
_local4 = 8;
} else {
if (game.level < 30){
_local4 = 13;
} else {
_local4 = 14;
};
};
var _local5:int = (int((Math.random() * _local4)) + 1);
if ((((((_local5 == 12)) || ((_local5 == 13)))) || ((_local5 == 14)))){
_local2 = true;
};
if (_local5 == 14){
_local3.tank = true;
addTimeout(readyToFire, 5000, _local3);
} else {
_local3.tank = false;
};
_local3.gotoAndStop(_local5);
_local3.x = _arg1.x;
_local3.y = _arg1.y;
_local3.rotation = _arg1.carRotation;
_local3.minSpeed = 1;
_local3.maxSpeed = 5;
_local3.speed = _local3.minSpeed;
_local3.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownCar);
_local3.buttonMode = true;
_local3.mouseChildren = false;
_local3.spawnPoint = _arg1;
_local3.inPlay = false;
_local3.killMe = false;
_arg1.locked = true;
var _local6:int = int((Math.random() * game.unlockPause));
_local6 = Math.max(_local6, game.minUnlockPause);
if (((_local2) && ((_local6 < 6000)))){
_local6 = 6000;
};
addTimeout(unlockSpawnPoint, _local6, _arg1);
spriteHolder.addChild(_local3);
game.carStack.push(_local3);
}
public function onMouseUpMoreGamesBtn(_arg1:MouseEvent){
gotoKill5();
}
public function checkCarForCollision(_arg1:MovieClip):Boolean{
var _local5:MovieClip;
var _local2:Boolean;
var _local3:int;
var _local4:int = game.carStack.length;
_local3 = 0;
while (_local3 < _local4) {
_local5 = game.carStack[_local3];
if (_arg1 != _local5){
if (((_arg1.hit.hitTestObject(_local5.hit)) && (((_local5.hit.hitTestObject(inPlay)) && (_arg1.hit.hitTestObject(inPlay)))))){
_arg1.rotation = (_arg1.rotation + 5);
_local5.rotation = (_local5.rotation + 5);
_local2 = true;
break;
};
};
_local3++;
};
return (_local2);
}
public function startGameLoop(){
addEventListener(Event.ENTER_FRAME, gameLoop);
}
public function onMouseUpStage(_arg1:MouseEvent){
gotoUrl("http://www.kill5.com");
}
function frame15(){
setMenu();
stop();
}
public function onMouseUpMusicBtn(_arg1:MouseEvent){
var _local2:* = _arg1.target;
if (_local2.state == 1){
setMusicVolume(0);
_local2.state = 0;
_local2.gotoAndStop("off");
} else {
trace("ON!");
setMusicVolume(1);
_local2.state = 1;
_local2.gotoAndStop("on");
};
}
function frame1(){
timeoutStack = new Array();
soundFxChan = new SoundChannel();
musicChan = new SoundChannel();
sfxTransform = new SoundTransform();
musicTransform = new SoundTransform();
crashSnd = new CrashSnd();
revSnd = new RevSnd();
shootSnd = new ShootSnd();
musicSnd = new MusicSnd();
lastScore = -1;
blur = new BitmapData(550, 500, true, 0);
blurCanvas = new Bitmap(blur);
MochiServices.connect("bddbe2b870ea37fb", root);
MochiAd.showPreGameAd({clip:root, id:"bddbe2b870ea37fb", res:"550x500"});
}
function frame2(){
stage.showDefaultContextMenu = false;
stage.scaleMode = StageScaleMode.NO_SCALE;
finished = false;
stage.addEventListener(Event.ENTER_FRAME, loader);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpStage);
stop();
}
function frame6(){
setSoundControl();
}
function frame20(){
setGame();
stop();
}
public function carsCrashed(){
hideFx();
game.gameOver = true;
addTimeout(addGameOver, 1000);
soundFxChan = crashSnd.play(0, 0, sfxTransform);
}
public function onMouseUpHiScoresBtn(_arg1:MouseEvent){
gotoHiScores();
}
function frame25(){
setHiScores();
stop();
}
public function pointAtMouse(_arg1){
var _local2:* = (mouseX - _arg1.x);
var _local3:* = (mouseY - _arg1.y);
return (((Math.atan2(_local3, _local2) * 180) / Math.PI));
}
public function onMouseUpMainMenuBtn(_arg1:MouseEvent){
gotoMenu();
}
public function onMouseUpTweetBtn(_arg1:MouseEvent){
gotoUrl((("http://twitter.com/home?status=I just scored " + lastScore) + " at Traffic Madness...Reckon you can beat me? http://bit.ly/trfmad"));
}
function frame33(){
setInstructions();
}
public function scoreSubmitComplete(){
game.gameOverPopUp.parent.removeChild(game.gameOverPopUp);
game.gameOverPopUp = null;
gotoHiScores();
}
public function rollOverGrow(_arg1){
_arg1.target.gotoAndStop("over");
TweenLite.to(_arg1.target, 0.25, {scaleX:1, scaleY:1});
}
public function updateBullets(){
var _local3:*;
var _local4:*;
var _local5:*;
var _local1:int;
var _local2:int = game.bulletStack.length;
_local1 = 0;
while (_local1 < _local2) {
_local3 = game.bulletStack[_local1];
_local4 = (Math.sin((_local3.rotation * (Math.PI / 180))) * 2);
_local5 = (Math.cos((_local3.rotation * (Math.PI / 180))) * 2);
_local3.x = (_local3.x + _local4);
_local3.y = (_local3.y - _local5);
if (!_local3.hitTestObject(inPlay)){
_local3.killMe = true;
};
if (_local3.killMe){
game.collisionGroup.removeItem(_local3);
_local3.parent.removeChild(_local3);
game.bulletStack.splice(_local1, 1);
_local1--;
_local2--;
_local3 = null;
};
_local1++;
};
}
public function fireBulletFromTank(_arg1){
var _local2:* = _arg1[0];
fireBullet(_local2);
}
public function endPreload():void{
stage.removeEventListener(Event.ENTER_FRAME, loader);
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpStage);
gotoAndPlay("loaded");
}
public function gotoInstructions(){
gotoAndStop("instructions");
}
public function setSoundControl(){
musicBtn.state = 1;
musicBtn.addEventListener(MouseEvent.MOUSE_UP, onMouseUpMusicBtn);
musicBtn.buttonMode = true;
musicBtn.mouseChildren = false;
soundBtn.state = 1;
soundBtn.addEventListener(MouseEvent.MOUSE_UP, onMouseUpSoundBtn);
soundBtn.buttonMode = true;
soundBtn.mouseChildren = false;
setSoundFxVolume(0.6);
setMusicVolume(1);
}
public function onMouseUpCar(_arg1:MouseEvent){
clickCar(_arg1.target);
}
public function readyToFire(_arg1){
var _local2:* = _arg1[0];
_local2.warningLight.gotoAndStop("on");
addTimeout(fireBulletFromTank, 1000, _local2);
}
public function fireBullet(_arg1){
var _local2:* = _arg1;
var _local3:* = new Bullet();
_local3.label = "bullet";
_local3.owner = _local2;
_local3.killMe = false;
blurHolder.addChild(_local3);
var _local4:* = _local2.turret.bGuide;
var _local5:* = new Point(_local4.x, _local4.y);
var _local6:* = _local2.turret.localToGlobal(_local5);
_local3.x = _local6.x;
_local3.y = _local6.y;
_local3.rotation = pointAtMouse(_local3);
_local3.rotation = (_local3.rotation + 90);
game.collisionGroup.addItem(_local3);
game.bulletStack.push(_local3);
soundFxChan = shootSnd.play(0, 0, sfxTransform);
}
public function setMenu(){
prepButton(playBtn, rollOver, rollOut, onMouseUpPlayBtn);
prepButton(instructionsBtn, rollOver, rollOut, onMouseUpInstructionsBtn);
prepButton(hiScoresBtn, rollOver, rollOut, onMouseUpHiScoresBtn);
prepButton(moreGamesBtn, rollOver, rollOut, onMouseUpMoreGamesBtn);
}
public function onMouseDownCar(_arg1:MouseEvent){
game.lastCar = _arg1.target;
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpStageInGame);
}
public function rollOver(_arg1){
_arg1.target.gotoAndStop("over");
}
public function onMouseUpInstructionsBtn(_arg1:MouseEvent){
gotoInstructions();
}
public function gotoKill5(){
gotoUrl("http://kill5.com");
}
public function rollOutShrink(_arg1){
_arg1.target.gotoAndStop("out");
TweenLite.to(_arg1.target, 0.25, {scaleX:0.85, scaleY:0.85});
}
public function gotoHiScores(){
gotoAndStop("hiScores");
}
public function setHiScores(){
MochiScores.setBoardID("45ca29a4df648611");
MochiScores.requestList(this, "displayScores");
prepButton(mainMenuBtn, rollOver, rollOut, onMouseUpMainMenuBtn);
prepButton(moreGamesBtn, rollOver, rollOut, onMouseUpMoreGamesBtn);
prepButton(playBtn, rollOver, rollOut, onMouseUpPlayBtn);
}
public function gotoUrl(_arg1){
var _local2:String = _arg1;
var _local3:URLRequest = new URLRequest(_local2);
navigateToURL(_local3, "_blank");
}
public function showExplode(_arg1){
explode.x = _arg1.x;
explode.y = _arg1.y;
}
public function setInstructions(){
prepButton(mainMenuBtn, rollOver, rollOut, onMouseUpMainMenuBtn);
prepButton(moreGamesBtn, rollOver, rollOut, onMouseUpMoreGamesBtn);
prepButton(playBtn, rollOver, rollOut, onMouseUpPlayBtn);
}
public function clickCar(_arg1){
if (_arg1.speed == _arg1.minSpeed){
_arg1.speed = _arg1.maxSpeed;
_arg1.parent.removeChild(_arg1);
blurHolder.addChild(_arg1);
soundFxChan = revSnd.play(0, 0, sfxTransform);
} else {
if (_arg1.speed == _arg1.maxSpeed){
_arg1.speed = 0;
_arg1.parent.removeChild(_arg1);
spriteHolder.addChild(_arg1);
} else {
if (_arg1.speed == 0){
_arg1.speed = _arg1.minSpeed;
};
};
};
}
public function onMouseUpSoundBtn(_arg1:MouseEvent){
var _local2:* = _arg1.target;
if (_local2.state == 1){
setSoundFxVolume(0);
_local2.state = 0;
_local2.gotoAndStop("off");
} else {
setSoundFxVolume(1);
_local2.state = 1;
_local2.gotoAndStop("on");
};
}
public function unlockSpawnPoint(_arg1:Array){
var _local2:Object = _arg1[0];
_local2.locked = false;
}
public function updateUi(){
var _local1:String = String(game.score);
var _local2:int = _local1.length;
var _local3:int = (6 - _local2);
var _local4:int;
var _local5:String = _local1;
_local4 = 0;
while (_local4 < _local3) {
_local5 = ("0" + _local5);
_local4++;
};
scoreTx.text = _local5;
}
public function levelUp(_arg1){
game.freq = (game.freq - 1);
game.unlockPause = (game.unlockPause - 50);
game.freq = Math.max(game.freq, game.minFreq);
game.unlockPause = Math.max(game.unlockPause, game.minUnlockPause);
game.level++;
addTimeout(levelUp, 5000);
}
public function addFx(){
var _local1:Rectangle = new Rectangle(0, 0, 550, 500);
var _local2:* = new ColorTransform(1, 1, 1, 1, 0, 0, 0, -70);
blur.draw(blurHolder, null, null);
blur.colorTransform(_local1, _local2);
fxCanvas.addChild(blurCanvas);
}
public function onMouseUpStageInGame(_arg1:MouseEvent){
if (game.lastCar != null){
clickCar(game.lastCar);
game.lastGame = null;
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpStageInGame);
};
}
public function onMouseUpSubmitScore(_arg1:MouseEvent){
var _local2:String = game.gameOverPopUp.nameTx.text;
if (((!((_local2 == ""))) && (!((_local2 == "Enter your name"))))){
MochiScores.setBoardID("45ca29a4df648611");
MochiScores.submit(game.score, _local2);
game.gameOverPopUp.nameTx.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDownNameTx);
scoreSubmitComplete();
} else {
game.gameOverPopUp.nameTx.text = "Enter your name";
};
}
public function clearAllTimeouts(){
var _local3:int;
var _local1:int;
var _local2:int = timeoutStack.length;
_local1 = 0;
while (_local1 < _local2) {
_local3 = timeoutStack[_local1];
clearTimeout(_local3);
_local1++;
};
timeoutStack = new Array();
}
public function gotoMenu(){
gotoAndStop("menu");
}
public function setSoundFxVolume(_arg1){
trace(("SET FX VOLUME " + _arg1));
sfxTransform.volume = _arg1;
var _local2:* = new SoundTransform(_arg1, 0);
soundFxChan.soundTransform = _local2;
}
public function displayScores(_arg1){
var _local2:* = [name1_txt, name2_txt, name3_txt, name4_txt, name5_txt, name6_txt, name7_txt, name8_txt, name9_txt, name10_txt];
var _local3:* = [score1_txt, score2_txt, score3_txt, score4_txt, score5_txt, score6_txt, score7_txt, score8_txt, score9_txt, score10_txt];
var _local4:Object = MochiScores.scoresArrayToObjects(_arg1.scores);
var _local5:* = _arg1.scores.alltime.rows.length;
var _local6:* = 0;
_local6 = 0;
while (_local6 < _local5) {
_local2[_local6].text = _arg1.scores.alltime.rows[_local6][1];
_local3[_local6].text = _arg1.scores.alltime.rows[_local6][0];
_local6++;
};
}
public function setScreen(){
blur = new BitmapData(550, 500, true, 0);
blurCanvas = new Bitmap(blur);
inPlay.mouseChildren = false;
inPlay.mouseEnabled = false;
fxCanvas.mouseEnabled = false;
fxCanvas.mouseChildren = false;
}
public function addTimeout(_arg1, _arg2, _arg3=null, _arg4=null, _arg5=null, _arg6=null){
var _local7:int = setTimeout(_arg1, _arg2, [_arg3, _arg4, _arg5, _arg6]);
timeoutStack.push(_local7);
}
public function updateCars(){
var _local5:MovieClip;
var _local6:Object;
var _local1:int;
var _local2:int = game.carStack.length;
_local1 = 0;
while (_local1 < _local2) {
_local5 = game.carStack[_local1];
if (_local5.tank){
_local5.turret.rotation = ((pointAtMouse(_local5) + 90) - _local5.rotation);
};
_local5.x = (_local5.x + (_local5.speed * _local5.spawnPoint.xDir));
_local5.y = (_local5.y + (_local5.speed * _local5.spawnPoint.yDir));
if (((!(_local5.hit.hitTestObject(inPlay))) && (_local5.inPlay))){
_local5.killMe = true;
game.score++;
} else {
if (((_local5.hit.hitTestObject(inPlay)) && (!(_local5.inPlay)))){
_local5.inPlay = true;
game.collisionGroup.addItem(_local5);
};
};
if (_local5.killMe){
game.collisionGroup.removeItem(_local5);
_local5.parent.removeChild(_local5);
game.carStack.splice(_local1, 1);
_local1--;
_local2--;
_local5 = null;
};
_local1++;
};
var _local3:* = int((Math.random() * game.freq));
_local3 = Math.max(10, _local3);
var _local4:int = int((Math.random() * _local3));
if (_local4 == 0){
_local6 = findSpawnPoint();
if (_local6 != null){
newCar(_local6);
};
};
}
public function findSpawnPoint():Object{
var _local4:Object;
fisherYates(game.spawnStack);
var _local1:Object;
var _local2:int;
var _local3:int = game.spawnStack.length;
_local2 = 0;
while (_local2 < _local3) {
_local4 = game.spawnStack[_local2];
if (_local4.locked == false){
_local1 = _local4;
break;
};
_local2++;
};
return (_local1);
}
public function setGame(){
newGame();
}
public function rollOut(_arg1){
_arg1.target.gotoAndStop("out");
}
public function resetGameVars(){
var _local7:MovieClip;
game = new Object();
game.score = 0;
game.level = 0;
game.gameOver = false;
game.carStack = new Array();
game.bulletStack = new Array();
game.freq = 50;
game.unlockPause = 5000;
game.crash = false;
game.minFreq = 10;
game.minUnlockPause = 2000;
game.lastCar = null;
game.collisionGroup = new CollisionGroup();
game.bulletBlockerStack = [bulletBlocker1, bulletBlocker2, bulletBlocker3, bulletBlocker4, bulletBlocker5, bulletBlocker6, bulletBlocker7, bulletBlocker8, bulletBlocker9, bulletBlocker10, bulletBlocker11, bulletBlocker12, bulletBlocker13];
var _local1:int;
var _local2:int = game.bulletBlockerStack.length;
_local1 = 0;
while (_local1 < _local2) {
_local7 = game.bulletBlockerStack[_local1];
_local7.label = "blocker";
game.collisionGroup.addItem(_local7);
_local7.alpha = 0.01;
_local1++;
};
game.spawnStack = new Array();
var _local3:Object = new Object();
_local3.x = sp1.x;
_local3.y = sp1.y;
_local3.locked = false;
_local3.carRotation = 270;
_local3.xDir = 1;
_local3.yDir = 0;
game.spawnStack.push(_local3);
var _local4:Object = new Object();
_local4.x = sp2.x;
_local4.y = sp2.y;
_local4.locked = false;
_local4.carRotation = 90;
_local4.xDir = -1;
_local4.yDir = 0;
game.spawnStack.push(_local4);
var _local5:Object = new Object();
_local5.x = sp3.x;
_local5.y = sp3.y;
_local5.locked = false;
_local5.carRotation = 0;
_local5.xDir = 0;
_local5.yDir = 1;
game.spawnStack.push(_local5);
var _local6:Object = new Object();
_local6.x = sp4.x;
_local6.y = sp4.y;
_local6.locked = false;
_local6.carRotation = 180;
_local6.xDir = 0;
_local6.yDir = -1;
game.spawnStack.push(_local6);
}
public function addGameOver(_arg1){
stopGameLoop();
musicChan.stop();
clearAllTimeouts();
lastScore = game.score;
game.gameOverPopUp = new GameOverPopUp();
uiHolder.addChild(game.gameOverPopUp);
stage.focus = game.gameOverPopUp.nameTx;
game.gameOverPopUp.nameTx.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownNameTx);
game.gameOverPopUp.scoreTx.text = game.score;
prepButton(game.gameOverPopUp.submitBtn, rollOver, rollOut, onMouseUpSubmitScore);
prepButton(game.gameOverPopUp.playAgainBtn, rollOver, rollOut, onMouseUpPlayAgainBtn);
prepButton(game.gameOverPopUp.tweetBtn, rollOver, rollOut, onMouseUpTweetBtn);
stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpStageInGame);
}
public function newGame(){
musicChan = musicSnd.play(0, 999, musicTransform);
resetGameVars();
setScreen();
firstRun();
startGameLoop();
}
public function gameLoop(_arg1:Event){
if (!game.gameOver){
updateBullets();
updateCars();
updateUi();
addFx();
checkAllCollisions();
};
}
public function hideFx(){
fxCanvas.visible = false;
}
public function prepButton(_arg1, _arg2, _arg3, _arg4){
_arg1.addEventListener(MouseEvent.MOUSE_OVER, _arg2);
_arg1.addEventListener(MouseEvent.MOUSE_OUT, _arg3);
_arg1.addEventListener(MouseEvent.MOUSE_UP, _arg4);
_arg1.buttonMode = true;
_arg1.mouseChildren = false;
}
public function firstRun(){
var _local1:Object = findSpawnPoint();
if (_local1 != null){
newCar(_local1);
};
levelUp(null);
}
public function returnToMenu(_arg1){
musicChan.stop();
clearAllTimeouts();
gotoMenu();
}
public function stopGameLoop(){
removeEventListener(Event.ENTER_FRAME, gameLoop);
}
public function checkAllCollisions(){
var _local2:int;
var _local3:int;
var _local4:Object;
var _local1:* = game.collisionGroup.checkCollisions();
if (_local1.length > 0){
_local2 = 0;
_local3 = _local1.length;
_local2 = 0;
while (_local2 < _local3) {
_local4 = _local1[_local2];
if ((((_local4.object1.label == "car")) && ((_local4.object2.label == "car")))){
if (((_local4.object1.inPlay) && (_local4.object2.inPlay))){
carsCrashed();
showExplode(new Point(_local4.object1.x, _local4.object1.y));
break;
};
} else {
if ((((_local4.object1.label == "bullet")) && ((_local4.object2.label == "car")))){
if (((((!((_local4.object1.owner == _local4.object2))) && ((_local4.object1.killMe == false)))) && (_local4.object2.inPlay))){
_local4.object1.visible = false;
carsCrashed();
showExplode(new Point(_local4.object1.x, _local4.object1.y));
break;
};
} else {
if ((((_local4.object1.label == "bullet")) && ((_local4.object2.label == "blocker")))){
_local4.object1.killMe = true;
};
};
};
_local2++;
};
};
}
public function setMusicVolume(_arg1){
musicTransform.volume = _arg1;
var _local2:* = new SoundTransform();
_local2.volume = _arg1;
musicChan.soundTransform = _local2;
}
public function onKeyDownNameTx(_arg1:KeyboardEvent){
var _local2:* = _arg1.target;
if (_local2.text == "Enter your name"){
_local2.text = "";
};
}
public function gotoGame(){
gotoAndStop("game");
}
}
}//package trafficMadness_fla
Section 26
//MoreGamesbtn_10 (trafficMadness_fla.MoreGamesbtn_10)
package trafficMadness_fla {
import flash.display.*;
public dynamic class MoreGamesbtn_10 extends MovieClip {
public function MoreGamesbtn_10(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 27
//MusicOnOff_Btn_5 (trafficMadness_fla.MusicOnOff_Btn_5)
package trafficMadness_fla {
import flash.display.*;
public dynamic class MusicOnOff_Btn_5 extends MovieClip {
public var inner:MovieClip;
public function MusicOnOff_Btn_5(){
addFrameScript(1, frame2);
}
function frame2(){
stop();
}
}
}//package trafficMadness_fla
Section 28
//PlayAgainBtn_21 (trafficMadness_fla.PlayAgainBtn_21)
package trafficMadness_fla {
import flash.display.*;
public dynamic class PlayAgainBtn_21 extends MovieClip {
public function PlayAgainBtn_21(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 29
//PlayBtn_8 (trafficMadness_fla.PlayBtn_8)
package trafficMadness_fla {
import flash.display.*;
public dynamic class PlayBtn_8 extends MovieClip {
public function PlayBtn_8(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 30
//PreAnim_1 (trafficMadness_fla.PreAnim_1)
package trafficMadness_fla {
import flash.display.*;
public dynamic class PreAnim_1 extends MovieClip {
public function PreAnim_1(){
addFrameScript(49, frame50);
}
function frame50(){
stop();
}
}
}//package trafficMadness_fla
Section 31
//SoundOnOff_Btn_4 (trafficMadness_fla.SoundOnOff_Btn_4)
package trafficMadness_fla {
import flash.display.*;
public dynamic class SoundOnOff_Btn_4 extends MovieClip {
public function SoundOnOff_Btn_4(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 32
//SubmitScoreBtn_22 (trafficMadness_fla.SubmitScoreBtn_22)
package trafficMadness_fla {
import flash.display.*;
public dynamic class SubmitScoreBtn_22 extends MovieClip {
public function SubmitScoreBtn_22(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 33
//WarningLight_17 (trafficMadness_fla.WarningLight_17)
package trafficMadness_fla {
import flash.display.*;
public dynamic class WarningLight_17 extends MovieClip {
public function WarningLight_17(){
addFrameScript(0, frame1);
}
function frame1(){
stop();
}
}
}//package trafficMadness_fla
Section 34
//Bullet (Bullet)
package {
import flash.display.*;
public dynamic class Bullet extends MovieClip {
}
}//package
Section 35
//Car (Car)
package {
import flash.display.*;
public dynamic class Car extends MovieClip {
public var turret:MovieClip;
public var hit:MovieClip;
public var warningLight:MovieClip;
}
}//package
Section 36
//CrashSnd (CrashSnd)
package {
import flash.media.*;
public dynamic class CrashSnd extends Sound {
}
}//package
Section 37
//GameOverPopUp (GameOverPopUp)
package {
import flash.display.*;
import flash.text.*;
public dynamic class GameOverPopUp extends MovieClip {
public var playAgainBtn:MovieClip;
public var submitBtn:MovieClip;
public var tweetBtn:MovieClip;
public var scoreTx:TextField;
public var nameTx:TextField;
}
}//package
Section 38
//MusicSnd (MusicSnd)
package {
import flash.media.*;
public dynamic class MusicSnd extends Sound {
}
}//package
Section 39
//RevSnd (RevSnd)
package {
import flash.media.*;
public dynamic class RevSnd extends Sound {
}
}//package
Section 40
//ShootSnd (ShootSnd)
package {
import flash.media.*;
public dynamic class ShootSnd extends Sound {
}
}//package