Section 1
//Bonus (game.Bonus)
package game {
import flash.events.*;
public class Bonus extends GameObject {
public static var leftImageClass:Class = Bonus_leftImageClass;
public static var speed:Number = 2;
public static var rightImageClass:Class = Bonus_rightImageClass;
public function Bonus(){
super(0, 200, 40, 10);
var rand:Number = Math.random();
if (rand < 0.5){
x = -20;
vx = speed;
} else {
vx = (speed * -1);
x = 640;
};
Game.timer.addEventListener("timer", move);
}
override public function move(event:TimerEvent):void{
x = (x + vx);
if (((((x + w) < 0)) || ((x > 640)))){
destroy();
};
dispatchEvent(new Event("objectChanged"));
}
override public function destroy():void{
dispatchEvent(new Event("objectDestroyed"));
Game.timer.removeEventListener("timer", move);
speed = (speed + 0.1);
}
public function getImage():Class{
if (vx > 0){
return (leftImageClass);
};
return (rightImageClass);
}
public static function reset():void{
speed = 2;
}
}
}//package game
Section 2
//Bonus_leftImageClass (game.Bonus_leftImageClass)
package game {
import mx.core.*;
public class Bonus_leftImageClass extends BitmapAsset {
}
}//package game
Section 3
//Bonus_rightImageClass (game.Bonus_rightImageClass)
package game {
import mx.core.*;
public class Bonus_rightImageClass extends BitmapAsset {
}
}//package game
Section 4
//Bouncer (game.Bouncer)
package game {
import flash.events.*;
public class Bouncer extends GameObject {
public static var maxSpeed:Number = 4;
public static var speed:Number = 2;
public static var width:Number = 50;
public static var minWidth:Number = 10;
public static var imageClass:Class = Bouncer_imageClass;
public function Bouncer(x:int=0){
super(x, 370, width, 10);
var rand:Number = Math.random();
if (rand < 0.5){
x = -(width);
vx = speed;
} else {
vx = (speed * -1);
x = 640;
};
Game.timer.addEventListener("timer", move);
}
override public function move(event:TimerEvent):void{
if (y <= 370){
y = 370;
vy = 0;
} else {
vy = (vy - 0.3);
y = (y + vy);
};
super.move(event);
}
public static function reduceWidth():void{
if (width > minWidth){
width = (width - 0.8);
};
}
public static function reset():void{
speed = 1;
width = 50;
}
public static function addSpeed():void{
if (speed < maxSpeed){
speed = (speed + 0.1);
};
}
}
}//package game
Section 5
//Bouncer_imageClass (game.Bouncer_imageClass)
package game {
import mx.core.*;
public class Bouncer_imageClass extends BitmapAsset {
}
}//package game
Section 6
//Game (game.Game)
package game {
import flash.events.*;
import flash.utils.*;
import gamegraphics.*;
public class Game extends EventDispatcher {
public var obstacle:Obstacle;
private var destroyDoubleBoards:Boolean;// = false
public var overWithoutHit:int;// = 0
public var scores:int;// = 0
private var powerupRounds:int;
private var bonus:Bonus;
private var destroySlowBoards:Boolean;// = false
public var bouncers:Array;
public var lastScores:int;// = 0
private var sinceLastBouncer:int;// = 0
public var jumper:Jumper;
public var bounces:int;// = 0
public var lastGameScores:int;// = 0
public static var powerup:int = 0;
public static var timer:Timer;
private static var powerupMaxRounds:int = 250;
public function Game(){
super();
timer = new Timer(20);
timer.addEventListener("timer", onTimer);
}
public function wentOver():void{
overWithoutHit++;
dispatchEvent(new Event("wentOver"));
}
private function addBouncer(x:int):void{
var newBouncer:Bouncer = new Bouncer(x);
bouncers.push(newBouncer);
var event:Event = new ObjectCreatedEvent(newBouncer, Bouncer.imageClass);
dispatchEvent(event);
}
public function moveDown():void{
jumper.vy = 4;
}
public function stopMoveLeft():void{
if (jumper.vx == -4){
jumper.vx = 0;
};
}
private function setPowerup():void{
var i:int;
var rand:Number = Math.random();
if (rand < 0.33){
powerup = 1;
} else {
if (rand < 0.66){
while (i < bouncers.length) {
bouncers[i].vx = (bouncers[i].vx / 2);
i++;
};
powerup = 2;
} else {
powerup = 3;
addBouncer(0);
addBouncer(250);
addBouncer(500);
};
};
timer.addEventListener("timer", handlePowerup);
dispatchEvent(new Event("powerupped"));
new TimeBar(jumper.x, (jumper.y - 13), 25, 5, timer, powerupMaxRounds, this, jumper);
}
public function addScores(amt:int):void{
scores = (scores + amt);
lastScores = amt;
dispatchEvent(new Event("scoresChanged"));
}
private function onTimer(event:TimerEvent):void{
}
private function handlePowerup(event:Event):void{
powerupRounds++;
if (powerupRounds > powerupMaxRounds){
removePowerup(null);
};
}
private function removeDoubleBoards():void{
bouncers[3].destroy();
bouncers[4].destroy();
bouncers[5].destroy();
bouncers.pop();
bouncers.pop();
bouncers.pop();
destroyDoubleBoards = false;
}
public function resume():void{
timer.start();
}
private function removePowerup(event:Event):void{
if (powerup == 2){
destroySlowBoards = true;
};
if (powerup == 3){
destroyDoubleBoards = true;
};
powerup = 0;
timer.removeEventListener("timer", handlePowerup);
powerupRounds = 0;
}
public function stopMoveDown():void{
jumper.vy = 0;
}
public function moveRight():void{
jumper.vx = 4;
}
public function moveUp():void{
jumper.vy = -4;
}
public function addObstacle(x:int, y:int):void{
obstacle = new Obstacle(x, y);
dispatchEvent(new ObjectCreatedEvent(obstacle, Obstacle.imageClass));
}
private function removeSlowBoards():void{
var i:int;
while (i < bouncers.length) {
bouncers[i].vx = (bouncers[i].vx * 2);
i++;
};
destroySlowBoards = false;
}
private function addJumper():void{
jumper = new Jumper(this, 310, 50, 20, 30);
var event:Event = new ObjectCreatedEvent(jumper, Jumper.imageClass, 40, true, 10);
dispatchEvent(event);
}
public function start():void{
powerup = 0;
overWithoutHit = 0;
scores = 0;
bouncers = new Array();
addObstacle(320, 230);
addJumper();
addBouncer(50);
addBouncer(200);
addBouncer(400);
timer.reset();
}
public function gameOver():void{
timer.stop();
jumper.destroy();
if (powerup != 0){
removePowerup(null);
};
if (destroyDoubleBoards){
removeDoubleBoards();
};
if (destroySlowBoards){
removeSlowBoards();
};
Bouncer.reset();
Bonus.reset();
bounces = 0;
if (bonus != null){
removeBonus();
};
var i:int;
while (i < bouncers.length) {
bouncers[i].destroy();
i++;
};
bouncers.pop();
bouncers.pop();
bouncers.pop();
lastGameScores = scores;
start();
dispatchEvent(new Event("gameover"));
dispatchEvent(new Event("scoresChanged"));
}
public function stopMoveRight():void{
if (jumper.vx == 4){
jumper.vx = 0;
};
}
public function stopMoveUp():void{
jumper.vy = 0;
}
public function checkHit():Boolean{
if (((!((bonus == null))) && (((jumper.isInside(bonus)) || (bonus.isInside(jumper)))))){
removeBonus(null);
setPowerup();
};
if ((((((jumper.distanceTo(obstacle) < (obstacle.w / 2))) && (!((jumper.overGoingPhase == 3))))) && (!((jumper.overGoingPhase == 4))))){
jumper.overGoingPhase = 3;
if (overWithoutHit > 0){
overWithoutHit--;
};
dispatchEvent(new Event("obstacleTouched"));
};
var i:int;
while (i < bouncers.length) {
if (((jumper.isInside(bouncers[i])) || (bouncers[i].isInside(jumper)))){
jumper.y = ((bouncers[i].y - jumper.h) - 1);
jumper.jump();
if (bouncers[i].w > Bouncer.minWidth){
bouncers[i].w = (bouncers[i].w - 2);
};
if (powerup == 2){
bouncers[i].vx = (bouncers[i].vx + ((bouncers[i].vx / Math.abs(bouncers[i].vx)) * 0.2));
} else {
bouncers[i].vx = (bouncers[i].vx + ((bouncers[i].vx / Math.abs(bouncers[i].vx)) * 0.4));
};
bouncers[i].vx = -(bouncers[i].vx);
bouncers[i].vy = 3;
bouncers[i].y = (bouncers[i].y + 1);
bouncers[i].update();
bounces++;
jumper.overGoingPhase = 0;
if ((bounces % 8) == 0){
addBonus();
};
addScores((1 + overWithoutHit));
if (destroyDoubleBoards){
removeDoubleBoards();
};
if (destroySlowBoards){
removeSlowBoards();
};
return (true);
};
i++;
};
if (jumper.y > 430){
gameOver();
};
return (false);
}
public function pause():void{
timer.stop();
}
public function moveLeft():void{
jumper.vx = -4;
}
private function removeBonus(event:Event=null):void{
bonus.removeEventListener("objectDestroyed", removeBonus);
if (event == null){
bonus.destroy();
};
bonus = null;
}
private function addBonus():void{
bonus = new Bonus();
bonus.addEventListener("objectDestroyed", removeBonus);
var event:Event = new ObjectCreatedEvent(bonus, bonus.getImage(), 40, true, 0, 30);
dispatchEvent(event);
}
}
}//package game
Section 7
//GameObject (game.GameObject)
package game {
import flash.events.*;
public class GameObject extends EventDispatcher {
public var y:Number;
public var vx:Number;// = 0
private var theGame:Game;
public var vy:Number;// = 0
public var h:Number;
public var w:Number;
public var ay:Number;// = 0
public var ax:Number;// = 0
public var x:Number;
public function GameObject(x:int, y:int, w:int, h:int, vx:Number=0, vy:Number=0){
super();
this.theGame = theGame;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.vx = vx;
this.vy = vy;
}
public function getW():int{
return (w);
}
public function getX():int{
return (x);
}
public function move(event:TimerEvent):void{
if (x < 0){
vx = -(vx);
x = 0;
};
if ((x + w) > 640){
vx = -(vx);
x = (640 - w);
};
x = (x + vx);
dispatchEvent(new Event("objectChanged"));
}
public function setPos(x:int, y:int):void{
this.x = x;
this.y = y;
dispatchEvent(new Event("objectChanged"));
}
public function isInside(obj:GameObject):Boolean{
if ((((((((x >= obj.x)) && ((x <= (obj.x + obj.w))))) && ((y >= obj.y)))) && ((y <= (obj.y + obj.h))))){
return (true);
};
if (((((((((x + w) >= obj.x)) && (((x + w) <= (obj.x + obj.w))))) && ((y >= obj.y)))) && ((y <= (obj.y + obj.h))))){
return (true);
};
if ((((((((x >= obj.x)) && ((x <= (obj.x + obj.w))))) && (((y + h) >= obj.y)))) && (((y + h) <= (obj.y + obj.h))))){
return (true);
};
if (((((((((x + w) >= obj.x)) && (((x + w) <= (obj.x + obj.w))))) && (((y + h) >= obj.y)))) && (((y + h) <= (obj.y + obj.h))))){
return (true);
};
if ((((((((x <= obj.x)) && (((x + w) >= (obj.x + obj.w))))) && ((y >= obj.y)))) && (((y + h) <= (obj.y + obj.h))))){
return (true);
};
if ((((((((x >= obj.x)) && (((x + w) <= (obj.x + obj.w))))) && ((y <= obj.y)))) && (((y + h) >= (obj.y + obj.h))))){
return (true);
};
return (false);
}
public function distanceTo(obj:GameObject):Number{
return (Math.sqrt((Math.pow(((x + (w / 2)) - (obj.x + (obj.w / 2))), 2) + Math.pow(((y + (h / 2)) - (obj.y + (obj.h / 2))), 2))));
}
public function update():void{
dispatchEvent(new Event("objectChanged"));
}
public function getY():int{
return (y);
}
public function getH():int{
return (h);
}
public function destroy():void{
dispatchEvent(new ObjectChangedEvent(this, "objectDestroyed"));
Game.timer.removeEventListener("timer", move);
}
}
}//package game
Section 8
//GraphicsChangedEvent (game.GraphicsChangedEvent)
package game {
import flash.events.*;
public class GraphicsChangedEvent extends Event {
public var loop:Boolean;
public var frameDelay:int;
public var graph:Class;
public function GraphicsChangedEvent(type:String, newGraph:Class, frameDelay:int=0, loop:Boolean=false, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
graph = newGraph;
this.loop = loop;
this.frameDelay = frameDelay;
}
}
}//package game
Section 9
//Jumper (game.Jumper)
package game {
import flash.events.*;
public class Jumper extends GameObject {
private var theGame:Game;
public var overGoingPhase:int;// = 0
public static var rightJumpImageClass:Class = Jumper_rightJumpImageClass;
public static var leftJumpImageClass:Class = Jumper_leftJumpImageClass;
public static var jumpImageClass:Class = Jumper_jumpImageClass;
public static var imageClass:Class = Jumper_imageClass;
public function Jumper(theGame:Game, x:int, y:int, w:int, h:int){
super(x, y, w, h);
this.theGame = theGame;
ay = 0.18;
Game.timer.addEventListener("timer", move);
}
override public function move(event:TimerEvent):void{
vx = (vx + ax);
vy = (vy + ay);
x = (x + vx);
y = (y + vy);
theGame.checkHit();
if (x < 0){
x = 0;
};
if ((x + w) > 640){
x = (640 - w);
};
if (overGoingPhase == 0){
if (((((y + (h / 2)) < 230)) && ((vy < 0)))){
if ((x + (w / 2)) < 330){
overGoingPhase = 1;
};
if ((x + (w / 2)) > 330){
overGoingPhase = 2;
};
};
};
if (((!((overGoingPhase == 0))) && (!((overGoingPhase == 3))))){
if (((((((y + (h / 2)) > 240)) && (((y + (h / 2)) < 250)))) && ((vy > 0)))){
if ((((((overGoingPhase == 1)) && (((x + (w / 2)) > 330)))) || ((((overGoingPhase == 2)) && (((x + (w / 2)) < 330)))))){
overGoingPhase = 4;
theGame.wentOver();
};
};
};
dispatchEvent(new Event("objectChanged"));
}
public function jump():void{
if (Game.powerup == 1){
vy = -9;
} else {
vy = -7.5;
};
if (vx < 0){
dispatchEvent(new GraphicsChangedEvent("graphicsChanged", leftJumpImageClass, 32));
} else {
if (vx > 0){
dispatchEvent(new GraphicsChangedEvent("graphicsChanged", rightJumpImageClass, 32));
} else {
dispatchEvent(new GraphicsChangedEvent("graphicsChanged", jumpImageClass, 32));
};
};
}
}
}//package game
Section 10
//Jumper_imageClass (game.Jumper_imageClass)
package game {
import mx.core.*;
public class Jumper_imageClass extends BitmapAsset {
}
}//package game
Section 11
//Jumper_jumpImageClass (game.Jumper_jumpImageClass)
package game {
import mx.core.*;
public class Jumper_jumpImageClass extends BitmapAsset {
}
}//package game
Section 12
//Jumper_leftJumpImageClass (game.Jumper_leftJumpImageClass)
package game {
import mx.core.*;
public class Jumper_leftJumpImageClass extends BitmapAsset {
}
}//package game
Section 13
//Jumper_rightJumpImageClass (game.Jumper_rightJumpImageClass)
package game {
import mx.core.*;
public class Jumper_rightJumpImageClass extends BitmapAsset {
}
}//package game
Section 14
//ObjectChangedEvent (game.ObjectChangedEvent)
package game {
import flash.events.*;
public class ObjectChangedEvent extends Event {
public var w:int;
public var x:int;
public var y:int;
public var h:int;
public function ObjectChangedEvent(obj:GameObject, type:String, bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
x = obj.getX();
y = obj.getY();
w = obj.getW();
h = obj.getH();
}
}
}//package game
Section 15
//ObjectCreatedEvent (game.ObjectCreatedEvent)
package game {
import flash.events.*;
public class ObjectCreatedEvent extends Event {
public var objClass:Class;
public var objName:String;
public var animated:Boolean;
public var loop:Boolean;
public var overWidth:int;
public var frameDelay:int;
private var obj:GameObject;
public var overHeight:int;
public function ObjectCreatedEvent(obj:GameObject, objClass:Class, frameDelay:int=0, loop:Boolean=false, overWidth:int=0, overHeight:int=0, type:String="objectCreated", bubbles:Boolean=false, cancelable:Boolean=false){
super(type, bubbles, cancelable);
this.obj = obj;
this.objName = objName;
this.objClass = objClass;
this.animated = animated;
this.frameDelay = frameDelay;
this.loop = loop;
this.overWidth = overWidth;
this.overHeight = overHeight;
}
public function getObjectName():String{
return (objName);
}
public function setObject(obj:GameObject):void{
this.obj = obj;
}
public function getObject():GameObject{
return (obj);
}
}
}//package game
Section 16
//Obstacle (game.Obstacle)
package game {
public class Obstacle extends GameObject {
public static var imageClass:Class = Obstacle_imageClass;
public function Obstacle(x:int, y:int){
super(x, y, 46, 34);
}
}
}//package game
Section 17
//Obstacle_imageClass (game.Obstacle_imageClass)
package game {
import mx.core.*;
public class Obstacle_imageClass extends BitmapAsset {
}
}//package game
Section 18
//GameGraphics (gamegraphics.GameGraphics)
package gamegraphics {
import flash.events.*;
import flash.display.*;
import game.*;
public class GameGraphics extends EventDispatcher {
private var theGame:Game;
private var bgImage:GameImage;
private var imagesToLoad:int;
private var objectArray:Array;
private var imageArray:Object;
public static var sprite:Sprite;
public function GameGraphics(fathersprite:Sprite, theGame:Game){
objectArray = new Array();
imageArray = new Object();
super();
sprite = fathersprite;
this.theGame = theGame;
theGame.addEventListener("objectCreated", addObject);
}
public function addObject(event:ObjectCreatedEvent):void{
new GraphicsObject(event.getObject(), event.objClass, event.frameDelay, event.loop, event.overWidth, event.overHeight);
}
public function addImage(obj:GameObject, imageClass:Class, frameDelay:int=0, loop:Boolean=false):void{
new GraphicsObject(obj, imageClass, frameDelay, loop);
}
public function loadImages(images:Object):void{
var image:String;
var newImage:GameImage;
for (image in images) {
imagesToLoad++;
newImage = new GameImage(images[image]);
newImage.addEventListener(Event.COMPLETE, imageReady);
imageArray[image] = newImage;
};
}
public function imageReady(event:Event):void{
imagesToLoad--;
if (imagesToLoad <= 0){
dispatchEvent(new Event(Event.COMPLETE));
};
}
public function setBackGroundImage(imageClass:Class):void{
bgImage = new GameImage(imageClass);
addBG(null);
}
public function addBG(event:Event):void{
var image:Bitmap = new Bitmap(bgImage.imageData);
sprite.addChild(image);
sprite.setChildIndex(image, 0);
}
}
}//package gamegraphics
Section 19
//GameImage (gamegraphics.GameImage)
package gamegraphics {
import flash.events.*;
import flash.display.*;
public class GameImage extends EventDispatcher {
public var ready:Boolean;// = false
public var imageData:BitmapData;
public function GameImage(imageClass:Class){
super();
var image:Bitmap = new (imageClass);
imageData = image.bitmapData;
}
}
}//package gamegraphics
Section 20
//GameText (gamegraphics.GameText)
package gamegraphics {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.text.*;
public class GameText extends Sprite {
private var timer:Timer;
private var textField:TextField;
public function GameText(text:String, x:int, y:int, format:TextFormat, fadeTime:int=0){
super();
textField = new TextField();
textField.text = text;
if (fadeTime != 0){
timer = new Timer(fadeTime);
timer.addEventListener("timer", destroy);
timer.start();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
};
textField.x = x;
textField.y = y;
GameGraphics.sprite.addChild(textField);
textField.setTextFormat(format);
}
public function onEnterFrame(event:Event):void{
textField.y = (textField.y - 0.5);
}
public function destroy(event:Event):void{
timer.removeEventListener("timer", destroy);
timer.stop();
GameGraphics.sprite.removeChild(textField);
}
}
}//package gamegraphics
Section 21
//GraphicsObject (gamegraphics.GraphicsObject)
package gamegraphics {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import game.*;
import flash.utils.*;
public class GraphicsObject {
private var sprite:Sprite;
private var w:int;
private var overWidth:int;
private var defaultLoop:Boolean;
private var image:Bitmap;
private var timer:Timer;
private var defaultImage:Bitmap;
private var mainImage:BitmapData;
private var loop:Boolean;
private var frames:int;// = 1
private var h:int;
private var overHeight:int;
private var frame:int;// = 0
private var obj:GameObject;
private var defaultFrameDelay:int;
public function GraphicsObject(obj:GameObject, imageClass:Class, frameDelay:int=0, loop:Boolean=false, overWidth:int=0, overHeight:int=0){
super();
this.obj = obj;
this.overWidth = overWidth;
this.overHeight = overHeight;
defaultImage = new (imageClass);
defaultFrameDelay = frameDelay;
defaultLoop = loop;
image = new Bitmap();
initImage(defaultImage, frameDelay, loop);
updateImage();
refresh(null);
GameGraphics.sprite.addChild(image);
obj.addEventListener("objectChanged", refresh);
obj.addEventListener("objectDestroyed", destroy);
obj.addEventListener("graphicsChanged", changeGraphics);
}
public function move(event:ObjectChangedEvent):void{
image.x = event.x;
image.y = event.y;
}
public function refresh(event:Event):void{
image.width = (obj.w + overWidth);
image.height = (obj.h + overHeight);
image.x = (obj.x - (overWidth / 2));
image.y = (obj.y - (overHeight / 2));
}
private function changeFrame(event:Event):void{
frame++;
if (frame >= frames){
if (loop == true){
frame = 0;
} else {
mainImage.dispose();
mainImage = defaultImage.bitmapData;
w = defaultImage.width;
h = defaultImage.height;
frames = (w / h);
initImage(defaultImage, defaultFrameDelay, defaultLoop);
};
};
updateImage();
}
public function parseImage(img:Bitmap, array:Array):void{
}
private function changeGraphics(event:GraphicsChangedEvent):void{
var bm:Bitmap = new event.graph();
if (timer != null){
timer.removeEventListener("timer", changeFrame);
timer.stop();
};
initImage(bm, event.frameDelay, event.loop);
updateImage();
}
private function initImage(bm:Bitmap, frameDelay:int, loop:Boolean=false):void{
h = bm.height;
w = bm.width;
this.loop = loop;
frames = 1;
frame = 0;
mainImage = bm.bitmapData;
if (timer != null){
timer.removeEventListener("timer", changeFrame);
timer.stop();
};
if (frameDelay > 0){
w = bm.height;
timer = new Timer(frameDelay);
timer.addEventListener("timer", changeFrame);
timer.start();
frames = (bm.width / h);
};
}
public function destroy(event:Event):void{
obj.removeEventListener("objectMoved", move);
obj.removeEventListener("objectDestroyed", destroy);
if (timer != null){
timer.removeEventListener("timer", changeFrame);
timer.stop();
};
defaultImage.bitmapData.dispose();
mainImage.dispose();
GameGraphics.sprite.removeChild(image);
}
public function updateImage():void{
image.bitmapData = new BitmapData(w, h);
image.bitmapData.copyPixels(mainImage, new Rectangle((frame * w), 0, w, h), new Point(0, 0));
}
}
}//package gamegraphics
Section 22
//TimeBar (gamegraphics.TimeBar)
package gamegraphics {
import flash.events.*;
import flash.display.*;
import game.*;
import flash.utils.*;
public class TimeBar extends Sprite {
private var start:int;
private var theGame:Game;
private var timer:Timer;
private var h:int;
private var roundsLeft:int;
private var roundsAtStart:int;
private var bar:Sprite;
private var w:int;
private var obj:GameObject;
public function TimeBar(x:int, y:int, w:int, h:int, timer:Timer, roundsLeft:int, theGame:Game, obj:GameObject){
super();
bar = new Sprite();
bar.x = x;
bar.y = y;
bar.graphics.beginFill(657930, 0.5);
bar.graphics.drawRect(0, 0, w, h);
bar.graphics.endFill();
GameGraphics.sprite.addChild(bar);
this.theGame = theGame;
this.timer = timer;
this.roundsLeft = roundsLeft;
this.roundsAtStart = roundsLeft;
this.w = w;
this.h = h;
this.obj = obj;
obj.addEventListener("objectChanged", updateLocation);
theGame.addEventListener("gameover", destroy);
timer.addEventListener("timer", update);
}
private function destroy(event:Event):void{
timer.removeEventListener("timer", update);
theGame.removeEventListener("gameover", destroy);
GameGraphics.sprite.removeChild(bar);
}
private function update(event:Event):void{
roundsLeft = (roundsLeft - 1);
if (roundsLeft < 0){
destroy(null);
return;
};
bar.graphics.clear();
bar.graphics.beginFill(328965, 0.5);
bar.graphics.drawRect(0, 0, (w * (roundsLeft / roundsAtStart)), h);
bar.graphics.endFill();
}
private function updateLocation(event:Event):void{
bar.x = obj.x;
bar.y = (obj.y - 13);
}
}
}//package gamegraphics
Section 23
//MochiScores (mochi.MochiScores)
package mochi {
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(options:Object=null):void{
var options = options;
if (options != null){
if (options.clip != null){
if ((options.clip is Sprite)){
MochiServices.setContainer(options.clip);
};
delete options.clip;
} else {
MochiServices.setContainer();
};
MochiServices.stayOnTop();
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;
};
};
};
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 (_slot1.boardID != null){
options.boardID = _slot1.boardID;
};
};
MochiServices.send("scores_showLeaderboard", {options:options}, null, onClose);
}
public static function closeLeaderboard():void{
MochiServices.send("scores_closeLeaderboard");
}
public static function getPlayerInfo(callbackObj:Object, callbackMethod:Object=null):void{
MochiServices.send("scores_getPlayerInfo", null, callbackObj, callbackMethod);
}
public static function requestList(callbackObj:Object, callbackMethod:Object=null):void{
MochiServices.send("scores_requestList", null, callbackObj, callbackMethod);
}
public static function scoresArrayToObjects(scores:Object):Object{
var i:Number;
var j:Number;
var o:Object;
var row_obj:Object;
var item:String;
var param:String;
var so:Object = {};
for (item in scores) {
if (typeof(scores[item]) == "object"){
if (((!((scores[item].cols == null))) && (!((scores[item].rows == null))))){
so[item] = [];
o = scores[item];
j = 0;
while (j < o.rows.length) {
row_obj = {};
i = 0;
while (i < o.cols.length) {
row_obj[o.cols[i]] = o.rows[j][i];
i++;
};
so[item].push(row_obj);
j++;
};
} else {
so[item] = {};
for (param in scores[item]) {
so[item][param] = scores[item][param];
};
};
} else {
so[item] = scores[item];
};
};
return (so);
}
public static function submit(score:Number, name:String, callbackObj:Object=null, callbackMethod:Object=null):void{
MochiServices.send("scores_submit", {score:score, name:name}, callbackObj, callbackMethod);
}
public static function onClose(args:Object=null):void{
if (args != null){
if (args.error != null){
if (args.error == true){
if (onErrorHandler != null){
if (args.errorCode == null){
args.errorCode = "IOError";
};
onErrorHandler(args.errorCode);
MochiServices.doClose();
return;
};
};
};
};
onCloseHandler();
MochiServices.doClose();
}
public static function setBoardID(boardID:String):void{
_slot1.boardID = boardID;
MochiServices.send("scores_setBoardID", {boardID:boardID});
}
}
}//package mochi
Section 24
//MochiServices (mochi.MochiServices)
package mochi {
import flash.events.*;
import flash.display.*;
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 _sendChannel:LocalConnection;
private static var _rcvChannelName:String;
private static var _gatewayURL:String = "http://www.mochiads.com/static/lib/services/services.swf";
private static var _clip:MovieClip;
private static var _loader:Loader;
private static var _id:String;
private static var _listenChannel:LocalConnection;
private static var _timer:Timer;
private static var _sendChannelName:String;
private static var _startTime:Number;
private static var _connecting:Boolean = false;
public static var onError:Object;
private static var _listenChannelName:String = "__mochiservices";
private static var _rcvChannel:LocalConnection;
public static function isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
public static function send(methodName:String, args:Object=null, callbackObject:Object=null, callbackMethod:Object=null):void{
if (_connected){
_sendChannel.send(_sendChannelName, "onReceive", {methodName:methodName, args:args, callbackID:_clip._nextcallbackID});
} else {
if ((((_clip == null)) || (!(_connecting)))){
onError("NotConnected");
handleError(args, callbackObject, callbackMethod);
flush(true);
return;
};
_clip._queue.push({methodName:methodName, args:args, callbackID:_clip._nextcallbackID});
};
if (_clip != null){
if (((!((_clip._callbacks == null))) && (!((_clip._nextcallbackID == null))))){
_clip._callbacks[_clip._nextcallbackID] = {callbackObject:callbackObject, callbackMethod:callbackMethod};
_clip._nextcallbackID++;
};
};
}
public static function get connected():Boolean{
return (_connected);
}
private static function flush(error:Boolean):void{
var request:Object;
var callback:Object;
if (_clip != null){
if (_clip._queue != null){
while (_clip._queue.length > 0) {
request = _clip._queue.shift();
callback = null;
if (request != null){
if (request.callbackID != null){
callback = _clip._callbacks[request.callbackID];
};
delete _clip._callbacks[request.callbackID];
if (((error) && (!((callback == null))))){
handleError(request.args, callback.callbackObject, callback.callbackMethod);
};
};
};
};
};
}
private static function init(id:String, clip:Object):void{
_id = id;
if (clip != null){
_container = clip;
loadCommunicator(id, _container);
};
}
public static function get childClip():Object{
return (_clip);
}
public static function get id():String{
return (_id);
}
public static function stayOnTop():void{
_container.addEventListener(Event.ENTER_FRAME, MochiServices.bringToTop, false, 0, true);
if (_clip != null){
_clip.visible = true;
};
}
public static function getVersion():String{
return ("1.32");
}
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);
_listenChannel.close();
_rcvChannel.close();
//unresolved jump
var _slot1 = error;
};
if (_timer != null){
_timer.stop();
//unresolved jump
var _slot1 = error;
};
}
public static function allowDomains(server:String):String{
var hostname:String;
Security.allowDomain("*");
Security.allowInsecureDomain("*");
if (server.indexOf("http://") != -1){
hostname = server.split("/")[2].split(":")[0];
Security.allowDomain(hostname);
Security.allowInsecureDomain(hostname);
};
return (hostname);
}
public static function doClose():void{
_container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop);
if (_clip.parent != null){
Sprite(_clip.parent).removeChild(_clip);
};
}
public static function setContainer(container:Object=null, doAdd:Boolean=true):void{
if (container != null){
if ((container is Sprite)){
_container = container;
};
};
if (doAdd){
if ((_container is Sprite)){
Sprite(_container).addChild(_clip);
};
};
}
private static function onStatus(event:StatusEvent):void{
switch (event.level){
case "error":
_connected = false;
_listenChannel.connect(_listenChannelName);
break;
};
}
private static function initComChannels():void{
if (!_connected){
_sendChannel.addEventListener(StatusEvent.STATUS, MochiServices.onStatus);
_sendChannel.send(_sendChannelName, "onReceive", {methodName:"handshakeDone"});
_sendChannel.send(_sendChannelName, "onReceive", {methodName:"registerGame", id:_id, clip:_container, version:getVersion()});
_rcvChannel.addEventListener(StatusEvent.STATUS, MochiServices.onStatus);
_clip.onReceive = function (pkg:Object):void{
var methodName:String;
var pkg = pkg;
var cb:String = pkg.callbackID;
var cblst:Object = this.client._callbacks[cb];
if (!cblst){
return;
};
var method:* = cblst.callbackMethod;
methodName = "";
var obj:Object = cblst.callbackObject;
if (((obj) && ((typeof(method) == "string")))){
methodName = method;
if (obj[method] != null){
method = obj[method];
} else {
trace((("Error: Method " + method) + " does not exist."));
};
};
if (method != undefined){
method.apply(obj, pkg.args);
//unresolved jump
var _slot1 = error;
trace(((("Error invoking callback method '" + methodName) + "': ") + pkg.toString()));
} else {
if (obj != null){
obj(pkg.args);
//unresolved jump
var _slot1 = error;
trace(("Error invoking method on object: " + pkg.toString()));
};
};
delete this.client._callbacks[cb];
};
_clip.onError = function ():void{
MochiServices.onError("IOError");
};
_rcvChannel.connect(_rcvChannelName);
trace("connected!");
_connecting = false;
_connected = true;
_listenChannel.close();
while (_clip._queue.length > 0) {
_sendChannel.send(_sendChannelName, "onReceive", _clip._queue.shift());
};
};
}
private static function listen():void{
_listenChannel = new LocalConnection();
_listenChannel.client = _clip;
_clip.handshake = function (args:Object):void{
MochiServices.comChannelName = args.newChannel;
};
_listenChannel.allowDomain("*", "localhost");
_listenChannel.allowInsecureDomain("*", "localhost");
_listenChannel.connect(_listenChannelName);
trace("Waiting for MochiAds services to connect...");
}
private static function handleError(args:Object, callbackObject:Object, callbackMethod:Object):void{
var args = args;
var callbackObject = callbackObject;
var callbackMethod = callbackMethod;
if (args != null){
if (args.onError != null){
args.onError.apply(null, ["NotConnected"]);
};
if (((!((args.options == null))) && (!((args.options.onError == null))))){
args.options.onError.apply(null, ["NotConnected"]);
};
};
if (callbackMethod != null){
args = {};
args.error = true;
args.errorCode = "NotConnected";
if (((!((callbackObject == null))) && ((callbackMethod is String)))){
var _local5 = callbackObject;
_local5[callbackMethod](args);
//unresolved jump
var _slot1 = error;
} else {
if (callbackMethod != null){
callbackMethod.apply(args);
//unresolved jump
var _slot1 = error;
};
};
};
}
public static function get clip():Object{
return (_container);
}
public static function set comChannelName(val:String):void{
if (val != null){
if (val.length > 3){
_sendChannelName = (val + "_fromgame");
_rcvChannelName = val;
initComChannels();
};
};
}
private static function loadCommunicator(id:String, clip:Object):MovieClip{
var id = id;
var clip = clip;
var clipname:String = ("_mochiservices_com_" + id);
if (_clip != null){
return (_clip);
};
if (!MochiServices.isNetworkAvailable()){
return (null);
};
MochiServices.allowDomains(_gatewayURL);
_clip = createEmptyMovieClip(clip, clipname, 10336, false);
_loader = new Loader();
_timer = new Timer(1000, 0);
_startTime = getTimer();
_timer.addEventListener(TimerEvent.TIMER, connectWait);
_timer.start();
var f:Function = function (ev:Object):void{
_clip._mochiad_ctr_failed = true;
trace("MochiServices could not load.");
MochiServices.disconnect();
MochiServices.onError("IOError");
};
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, f);
var req:URLRequest = new URLRequest(_gatewayURL);
_loader.load(req);
_clip.addChild(_loader);
_clip._mochiservices_com = _loader;
_sendChannel = new LocalConnection();
_clip._queue = [];
_rcvChannel = new LocalConnection();
_rcvChannel.allowDomain("*", "localhost");
_rcvChannel.allowInsecureDomain("*", "localhost");
_rcvChannel.client = _clip;
_clip._nextcallbackID = 0;
_clip._callbacks = {};
listen();
return (_clip);
}
public static function bringToTop(e:Event):void{
var e = e;
if (MochiServices.clip != null){
if (MochiServices.childClip != null){
if (MochiServices.clip.numChildren > 1){
MochiServices.clip.setChildIndex(MochiServices.childClip, (MochiServices.clip.numChildren - 1));
};
//unresolved jump
var _slot1 = errorObject;
trace("Warning: Depth sort error.");
_container.removeEventListener(Event.ENTER_FRAME, MochiServices.bringToTop);
};
};
}
public static function connect(id:String, clip:Object, onError:Object=null):void{
var id = id;
var clip = clip;
var onError = onError;
if ((clip is DisplayObject)){
if (((!(_connected)) && ((_clip == null)))){
trace("MochiServices Connecting...");
_connecting = true;
init(id, clip);
};
} else {
trace("Error, MochiServices requires a Sprite, Movieclip or instance of the stage.");
};
if (onError != null){
MochiServices.onError = onError;
} else {
if (MochiServices.onError == null){
MochiServices.onError = function (errorCode:String):void{
trace(errorCode);
};
};
};
}
public static function createEmptyMovieClip(parent:Object, name:String, depth:Number, doAdd:Boolean=true):MovieClip{
var parent = parent;
var name = name;
var depth = depth;
var doAdd = doAdd;
var mc:MovieClip = new MovieClip();
if (doAdd){
if (((false) && (depth))){
parent.addChildAt(mc, depth);
} else {
parent.addChild(mc);
};
};
parent[name] = mc;
//unresolved jump
var _slot1 = e;
throw (new Error("MochiServices requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic."));
mc["_name"] = name;
return (mc);
}
public static function connectWait(e:TimerEvent):void{
if ((getTimer() - _startTime) > 10000){
if (!_connected){
_clip._mochiad_ctr_failed = true;
trace("MochiServices could not load.");
MochiServices.disconnect();
MochiServices.onError("IOError");
};
_timer.stop();
};
}
}
}//package mochi
Section 25
//BitmapAsset (mx.core.BitmapAsset)
package mx.core {
import flash.display.*;
public class BitmapAsset extends FlexBitmap implements IFlexAsset, IFlexDisplayObject {
mx_internal static const VERSION:String = "3.0.0.0";
public function BitmapAsset(bitmapData:BitmapData=null, pixelSnapping:String="auto", smoothing:Boolean=false){
super(bitmapData, pixelSnapping, smoothing);
}
public function get measuredWidth():Number{
if (bitmapData){
return (bitmapData.width);
};
return (0);
}
public function get measuredHeight():Number{
if (bitmapData){
return (bitmapData.height);
};
return (0);
}
public function setActualSize(newWidth:Number, newHeight:Number):void{
width = newWidth;
height = newHeight;
}
public function move(x:Number, y:Number):void{
this.x = x;
this.y = y;
}
}
}//package mx.core
Section 26
//ByteArrayAsset (mx.core.ByteArrayAsset)
package mx.core {
import flash.utils.*;
public class ByteArrayAsset extends ByteArray implements IFlexAsset {
mx_internal static const VERSION:String = "3.0.0.0";
public function ByteArrayAsset(){
super();
}
}
}//package mx.core
Section 27
//EdgeMetrics (mx.core.EdgeMetrics)
package mx.core {
public class EdgeMetrics {
public var top:Number;
public var left:Number;
public var bottom:Number;
public var right:Number;
mx_internal static const VERSION:String = "3.0.0.0";
public static const EMPTY:EdgeMetrics = new EdgeMetrics(0, 0, 0, 0);
;
public function EdgeMetrics(left:Number=0, top:Number=0, right:Number=0, bottom:Number=0){
super();
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public function clone():EdgeMetrics{
return (new EdgeMetrics(left, top, right, bottom));
}
}
}//package mx.core
Section 28
//FlexBitmap (mx.core.FlexBitmap)
package mx.core {
import flash.display.*;
import mx.utils.*;
public class FlexBitmap extends Bitmap {
mx_internal static const VERSION:String = "3.0.0.0";
public function FlexBitmap(bitmapData:BitmapData=null, pixelSnapping:String="auto", smoothing:Boolean=false){
var bitmapData = bitmapData;
var pixelSnapping = pixelSnapping;
var smoothing = smoothing;
super(bitmapData, pixelSnapping, smoothing);
name = NameUtil.createUniqueName(this);
//unresolved jump
var _slot1 = e;
}
override public function toString():String{
return (NameUtil.displayObjectToString(this));
}
}
}//package mx.core
Section 29
//FlexMovieClip (mx.core.FlexMovieClip)
package mx.core {
import flash.display.*;
import mx.utils.*;
public class FlexMovieClip extends MovieClip {
mx_internal static const VERSION:String = "3.0.0.0";
public function FlexMovieClip(){
super();
name = NameUtil.createUniqueName(this);
//unresolved jump
var _slot1 = e;
}
override public function toString():String{
return (NameUtil.displayObjectToString(this));
}
}
}//package mx.core
Section 30
//IBorder (mx.core.IBorder)
package mx.core {
public interface IBorder {
function get borderMetrics():EdgeMetrics;
}
}//package mx.core
Section 31
//IFlexAsset (mx.core.IFlexAsset)
package mx.core {
public interface IFlexAsset {
}
}//package mx.core
Section 32
//IFlexDisplayObject (mx.core.IFlexDisplayObject)
package mx.core {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import flash.accessibility.*;
public interface IFlexDisplayObject extends IBitmapDrawable, IEventDispatcher {
function get visible():Boolean;
function get rotation():Number;
function localToGlobal(void:Point):Point;
function get name():String;
function set width(flash.display:Number):void;
function get measuredHeight():Number;
function get blendMode():String;
function get scale9Grid():Rectangle;
function set name(flash.display:String):void;
function set scaleX(flash.display:Number):void;
function set scaleY(flash.display:Number):void;
function get measuredWidth():Number;
function get accessibilityProperties():AccessibilityProperties;
function set scrollRect(flash.display:Rectangle):void;
function get cacheAsBitmap():Boolean;
function globalToLocal(void:Point):Point;
function get height():Number;
function set blendMode(flash.display:String):void;
function get parent():DisplayObjectContainer;
function getBounds(String:DisplayObject):Rectangle;
function get opaqueBackground():Object;
function set scale9Grid(flash.display:Rectangle):void;
function setActualSize(_arg1:Number, _arg2:Number):void;
function set alpha(flash.display:Number):void;
function set accessibilityProperties(flash.display:AccessibilityProperties):void;
function get width():Number;
function hitTestPoint(_arg1:Number, _arg2:Number, _arg3:Boolean=false):Boolean;
function set cacheAsBitmap(flash.display:Boolean):void;
function get scaleX():Number;
function get scaleY():Number;
function get scrollRect():Rectangle;
function get mouseX():Number;
function get mouseY():Number;
function set height(flash.display:Number):void;
function set mask(flash.display:DisplayObject):void;
function getRect(String:DisplayObject):Rectangle;
function get alpha():Number;
function set transform(flash.display:Transform):void;
function move(_arg1:Number, _arg2:Number):void;
function get loaderInfo():LoaderInfo;
function get root():DisplayObject;
function hitTestObject(mx.core:IFlexDisplayObject/mx.core:IFlexDisplayObject:stage/get:DisplayObject):Boolean;
function set opaqueBackground(flash.display:Object):void;
function set visible(flash.display:Boolean):void;
function get mask():DisplayObject;
function set x(flash.display:Number):void;
function set y(flash.display:Number):void;
function get transform():Transform;
function set filters(flash.display:Array):void;
function get x():Number;
function get y():Number;
function get filters():Array;
function set rotation(flash.display:Number):void;
function get stage():Stage;
}
}//package mx.core
Section 33
//IRepeaterClient (mx.core.IRepeaterClient)
package mx.core {
public interface IRepeaterClient {
function get instanceIndices():Array;
function set instanceIndices(E:\dev\3.0.3\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get isDocument():Boolean;
function set repeaters(E:\dev\3.0.3\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function initializeRepeaterArrays(E:\dev\3.0.3\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:IRepeaterClient):void;
function get repeaters():Array;
function set repeaterIndices(E:\dev\3.0.3\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get repeaterIndices():Array;
}
}//package mx.core
Section 34
//MovieClipAsset (mx.core.MovieClipAsset)
package mx.core {
public class MovieClipAsset extends FlexMovieClip implements IFlexAsset, IFlexDisplayObject, IBorder {
private var _measuredHeight:Number;
private var _measuredWidth:Number;
mx_internal static const VERSION:String = "3.0.0.0";
public function MovieClipAsset(){
super();
_measuredWidth = width;
_measuredHeight = height;
}
public function get measuredWidth():Number{
return (_measuredWidth);
}
public function get measuredHeight():Number{
return (_measuredHeight);
}
public function setActualSize(newWidth:Number, newHeight:Number):void{
width = newWidth;
height = newHeight;
}
public function move(x:Number, y:Number):void{
this.x = x;
this.y = y;
}
public function get borderMetrics():EdgeMetrics{
if (scale9Grid == null){
return (EdgeMetrics.EMPTY);
};
return (new EdgeMetrics(scale9Grid.left, scale9Grid.top, Math.ceil((measuredWidth - scale9Grid.right)), Math.ceil((measuredHeight - scale9Grid.bottom))));
}
}
}//package mx.core
Section 35
//MovieClipLoaderAsset (mx.core.MovieClipLoaderAsset)
package mx.core {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.system.*;
public class MovieClipLoaderAsset extends MovieClipAsset implements IFlexAsset, IFlexDisplayObject {
protected var initialHeight:Number;// = 0
private var loader:Loader;// = null
private var initialized:Boolean;// = false
protected var initialWidth:Number;// = 0
private var requestedHeight:Number;
private var requestedWidth:Number;
mx_internal static const VERSION:String = "3.0.0.0";
public function MovieClipLoaderAsset(){
super();
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
if (("allowLoadBytesCodeExecution" in loaderContext)){
loaderContext["allowLoadBytesCodeExecution"] = true;
};
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.loadBytes(movieClipData, loaderContext);
addChild(loader);
}
override public function get width():Number{
if (!initialized){
return (initialWidth);
};
return (super.width);
}
override public function set width(value:Number):void{
if (!initialized){
requestedWidth = value;
} else {
loader.width = value;
};
}
override public function get measuredHeight():Number{
return (initialHeight);
}
private function completeHandler(event:Event):void{
initialized = true;
initialWidth = loader.width;
initialHeight = loader.height;
if (!isNaN(requestedWidth)){
loader.width = requestedWidth;
};
if (!isNaN(requestedHeight)){
loader.height = requestedHeight;
};
dispatchEvent(event);
}
override public function set height(value:Number):void{
if (!initialized){
requestedHeight = value;
} else {
loader.height = value;
};
}
override public function get measuredWidth():Number{
return (initialWidth);
}
override public function get height():Number{
if (!initialized){
return (initialHeight);
};
return (super.height);
}
public function get movieClipData():ByteArray{
return (null);
}
}
}//package mx.core
Section 36
//mx_internal (mx.core.mx_internal)
package mx.core {
public namespace mx_internal = "http://www.adobe.com/2006/flex/mx/internal";
}//package mx.core
Section 37
//SoundAsset (mx.core.SoundAsset)
package mx.core {
import flash.media.*;
public class SoundAsset extends Sound implements IFlexAsset {
mx_internal static const VERSION:String = "3.0.0.0";
public function SoundAsset(){
super();
}
}
}//package mx.core
Section 38
//NameUtil (mx.utils.NameUtil)
package mx.utils {
import flash.display.*;
import mx.core.*;
import flash.utils.*;
public class NameUtil {
mx_internal static const VERSION:String = "3.0.0.0";
private static var counter:int = 0;
public static function displayObjectToString(displayObject:DisplayObject):String{
var result:String;
var s:String;
var indices:Array;
var o:DisplayObject = displayObject;
while (o != null) {
if (((((o.parent) && (o.stage))) && ((o.parent == o.stage)))){
break;
};
s = o.name;
if ((o is IRepeaterClient)){
indices = IRepeaterClient(o).instanceIndices;
if (indices){
s = (s + (("[" + indices.join("][")) + "]"));
};
};
result = ((result == null)) ? s : ((s + ".") + result);
o = o.parent;
};
return (result);
}
public static function createUniqueName(object:Object):String{
if (!object){
return (null);
};
var name:String = getQualifiedClassName(object);
var index:int = name.indexOf("::");
if (index != -1){
name = name.substr((index + 2));
};
var charCode:int = name.charCodeAt((name.length - 1));
if ((((charCode >= 48)) && ((charCode <= 57)))){
name = (name + "_");
};
return ((name + counter++));
}
}
}//package mx.utils
Section 39
//Main (Main)
package {
import flash.events.*;
import flash.display.*;
import game.*;
import flash.utils.*;
import flash.text.*;
import flash.media.*;
import gamegraphics.*;
import mochi.*;
import flash.net.*;
import flash.ui.*;
public dynamic class Main extends MovieClip {
private var theGame:Game;
public var textForm:TextFormat;
private var cloud1ImageClass:Class;
private var cloud3ImageClass:Class;
private var hsButton:SimpleButton;
private var scores:TextField;
private var music:Sound;
private var maxgamesLogo:Class;
private var muteButton:SimpleButton;
private var paused:Boolean;// = false
private var maxgameButton:SimpleButton;
private var soundON:Class;
private var sprite:Sprite;
private var maxgameClip:MovieClip;
private var sunImageClass:Class;
private var bgClass:Class;
private var musicClass:Class;
private var cloud2ImageClass:Class;
private var swampImageClass:Class;
private var menu:Sprite;
private var soundOFF:Class;
private var maxgames:Class;
private var graphs:GameGraphics;
private var muted:Boolean;// = false
private var soundChannel:SoundChannel;
public function Main():void{
musicClass = Main_musicClass;
bgClass = Main_bgClass;
sunImageClass = Main_sunImageClass;
swampImageClass = Main_swampImageClass;
cloud1ImageClass = Main_cloud1ImageClass;
cloud2ImageClass = Main_cloud2ImageClass;
cloud3ImageClass = Main_cloud3ImageClass;
soundON = Main_soundON;
soundOFF = Main_soundOFF;
maxgames = Main_maxgames;
maxgamesLogo = Main_maxgamesLogo;
super();
MochiServices.connect("bba288c2da590682", this);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.tabChildren = false;
playAdd(null);
}
private function onKeyUp(event:KeyboardEvent):void{
if (event.keyCode == 39){
theGame.stopMoveRight();
};
if (event.keyCode == 37){
theGame.stopMoveLeft();
};
}
override public function stop():void{
super.stop();
stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.removeEventListener(KeyboardEvent.KEY_UP, onKeyUp);
}
private function setBorders():void{
var border:Sprite = new Sprite();
border.graphics.lineStyle(1);
border.graphics.drawRect(0, 0, 640, 480);
addChild(border);
scores = new TextField();
scores.autoSize = TextFieldAutoSize.LEFT;
scores.text = ("Scores: " + theGame.scores);
scores.x = 30;
scores.y = 95;
addChild(scores);
scores.setTextFormat(textForm);
var muteImage:Bitmap = new soundOFF();
var muteImage2:Bitmap = new soundON();
muteButton = new SimpleButton(muteImage, muteImage, muteImage, muteImage2);
muteButton.addEventListener("click", mute);
muteButton.x = 30;
muteButton.y = 120;
addChild(muteButton);
}
private function onKeyDown(event:KeyboardEvent):void{
if (paused == false){
if (event.keyCode == 39){
theGame.moveRight();
};
if (event.keyCode == 37){
theGame.moveLeft();
};
};
if (event.keyCode == Keyboard.SPACE){
if (paused == true){
resume();
} else {
pause();
};
};
}
private function makeHSButton():SimpleButton{
var text:TextField = new TextField();
text.text = "Highscores";
text.textColor = 14483970;
text.autoSize = TextFieldAutoSize.CENTER;
textForm.underline = true;
text.setTextFormat(textForm);
textForm.underline = false;
var hs:SimpleButton = new SimpleButton(text, text, text, text);
return (hs);
}
public function playMain(event:Event):void{
if (event != null){
event.target.removeEventListener("timer", playAdd);
event.target.stop();
maxgameClip.gotoAndStop(0);
removeChild(maxgameClip);
stage.frameRate = 70;
};
super.play();
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
if (paused == true){
resume();
pause();
return;
};
music = new musicClass();
soundChannel = music.play(0, 999);
textForm = new TextFormat();
textForm.size = 14;
textForm.bold = true;
textForm.font = "comic sans ms";
theGame = new Game();
graphs = new GameGraphics(this, theGame);
startGame(null);
addSun(470, -50);
addSwamps();
addCloud(10, 10, 0.2, 0, cloud1ImageClass);
addCloud(200, 40, -0.5, 0, cloud2ImageClass);
addCloud(400, 30, -0.3, 0, cloud3ImageClass);
setBorders();
var text:TextField = new TextField();
text.text = "Play Games to the Max\nat MaxGames.com";
text.textColor = 1052927;
text.setTextFormat(textForm);
text.autoSize = TextFieldAutoSize.CENTER;
maxgameButton.hitTestState = text;
maxgameButton.downState = text;
maxgameButton.upState = text;
maxgameButton.overState = text;
maxgameButton.x = 250;
maxgameButton.y = 200;
}
private function addSwamps():void{
graphs.addImage(new GameObject(0, 388, 640, 92), swampImageClass);
}
private function mute(event:Event):void{
var muteImage:Bitmap = new soundOFF();
var muteImage2:Bitmap = new soundON();
if (muted == false){
muted = true;
muteButton.upState = muteImage2;
muteButton.overState = muteImage2;
muteButton.downState = muteImage2;
soundChannel.stop();
} else {
muted = false;
muteButton.upState = muteImage;
muteButton.overState = muteImage;
muteButton.downState = muteImage;
soundChannel = music.play(0, 999);
};
}
private function addCloud(x:Number, y:Number, vx:Number, vy:Number, imageClass:Class):void{
var obj:GameObject = new GameObject(x, y, 100, 50, vx, vy);
Game.timer.addEventListener("timer", obj.move);
graphs.addObject(new ObjectCreatedEvent(obj, imageClass));
}
private function openMaxGames(event:Event):void{
var event = event;
var url = "http://www.maxgames.com";
var request:URLRequest = new URLRequest(url);
navigateToURL(request, "_blank");
//unresolved jump
var _slot1 = e;
trace("Error occurred!");
}
private function setScores(event:Event):void{
var format:TextFormat;
if (theGame.scores > 0){
format = new TextFormat();
format.font = "comic sans ms";
format.size = 13;
format.color = 0xAA00;
format.bold = true;
new GameText(("+" + String(theGame.lastScores)), theGame.jumper.x, (theGame.jumper.y - 50), format, 1000);
};
scores.text = ("Scores: " + theGame.scores);
scores.setTextFormat(textForm);
}
private function resume(event:Event=null):void{
removeChild(menu);
theGame.resume();
paused = false;
stage.focus = stage;
}
private function overObstacle(event:Event):void{
var format:TextFormat = new TextFormat();
format.font = "comic sans ms";
format.size = 13;
format.color = 0xAA00;
format.bold = true;
new GameText("Over!\nBonus +1", theGame.jumper.x, (theGame.jumper.y - 50), format, 1000);
}
override public function play():void{
if (paused == true){
playMain(null);
return;
};
stage.frameRate = 24;
maxgameClip = new maxgames();
addChild(maxgameClip);
maxgameClip.soundTransform.volume = 0;
maxgameClip.play();
var timer:Timer = new Timer(10000);
timer.addEventListener("timer", playMain);
timer.start();
}
private function showHighScores(event:Event):void{
paused = true;
MochiScores.showLeaderboard({boardID:"d3871afe93a41f3b"});
}
public function playAdd(event:Event):void{
var img:Bitmap = new maxgamesLogo();
maxgameButton = new SimpleButton(img, img, img, img);
maxgameButton.addEventListener("click", openMaxGames);
addChild(maxgameButton);
MochiAd.showPreGameAd({clip:root, id:"d812496d70c65425", res:"640x480", background:0, color:0xFF0000, outline:0xA5A5A5, no_bg:true});
}
private function openHighScores(event:Event):void{
paused = true;
MochiScores.showLeaderboard({boardID:"d3871afe93a41f3b", score:theGame.lastGameScores});
}
private function powerup(event:Event):void{
var format:TextFormat = new TextFormat();
format.font = "comic sans ms";
format.size = 13;
format.color = 0xAA00;
format.bold = true;
if (Game.powerup == 1){
new GameText("Double Jump!", theGame.jumper.x, (theGame.jumper.y - 50), format, 1000);
};
if (Game.powerup == 2){
new GameText("Slow Boards!", theGame.jumper.x, (theGame.jumper.y - 50), format, 1000);
};
if (Game.powerup == 3){
new GameText("Double Boards!", theGame.jumper.x, (theGame.jumper.y - 50), format, 1000);
};
}
private function gameOver(event:Event):void{
menu = new Sprite();
var text:TextField = new TextField();
text.textColor = 0;
text.text = (("Game Over!\n\nScores: " + theGame.lastGameScores) + "\nSubmit:\n\nPress space to restart.");
text.y = 40;
text.width = 345;
text.autoSize = TextFieldAutoSize.CENTER;
menu.x = 100;
menu.y = 100;
menu.addChild(text);
text.setTextFormat(textForm);
menu.graphics.beginFill(0xDDDDDD, 0.9);
menu.graphics.drawRoundRect(0, 0, 440, 200, 50, 50);
menu.graphics.endFill();
menu.addChild(maxgameButton);
if (hsButton == null){
hsButton = makeHSButton();
};
hsButton.x = 135;
hsButton.y = 97;
hsButton.removeEventListener("click", showHighScores);
hsButton.addEventListener("click", openHighScores);
menu.addChild(hsButton);
addChild(menu);
paused = true;
}
private function hitObstacle(event:Event):void{
var format:TextFormat = new TextFormat();
format.font = "comic sans ms";
format.size = 13;
format.color = 0xBB0000;
format.bold = true;
new GameText("Hit :(\nBonus -1", theGame.jumper.x, (theGame.jumper.y - 50), format, 1000);
}
private function addSun(x:int, y:int):void{
graphs.addImage(new GameObject(x, y, 200, 200), sunImageClass, 150, true);
}
private function pause(event:Event=null):void{
if (event == null){
theGame.pause();
};
menu = new Sprite();
var text:TextField = new TextField();
text.textColor = 0;
text.y = 20;
text.text = "Controls:\nUse the arrow keys to move.\n\nTry to jump over the ball\nin the middle to increase your scores.\nThe birds give you powerups\n\nPress space to continue.";
text.width = 440;
text.autoSize = TextFieldAutoSize.CENTER;
menu.x = 100;
menu.y = 100;
menu.addChild(text);
text.setTextFormat(textForm);
menu.graphics.beginFill(0xDDDDDD, 0.9);
menu.graphics.drawRoundRect(0, 0, 440, 200, 50, 50);
menu.graphics.endFill();
menu.addChild(maxgameButton);
if (hsButton == null){
hsButton = makeHSButton();
};
hsButton.x = 275;
hsButton.y = 10;
hsButton.removeEventListener("click", openHighScores);
hsButton.addEventListener("click", showHighScores);
menu.addChild(hsButton);
addChild(menu);
paused = true;
}
private function onMouseMove(event:MouseEvent):void{
}
public function startGame(event:Event):void{
theGame.addEventListener("pause", pause);
theGame.addEventListener("gameover", gameOver);
theGame.addEventListener("continue", resume);
theGame.addEventListener("scoresChanged", setScores);
theGame.addEventListener("obstacleTouched", hitObstacle);
theGame.addEventListener("wentOver", overObstacle);
theGame.addEventListener("powerupped", powerup);
theGame.start();
pause();
}
}
}//package
Section 40
//Main_bgClass (Main_bgClass)
package {
import mx.core.*;
public class Main_bgClass extends BitmapAsset {
}
}//package
Section 41
//Main_cloud1ImageClass (Main_cloud1ImageClass)
package {
import mx.core.*;
public class Main_cloud1ImageClass extends BitmapAsset {
}
}//package
Section 42
//Main_cloud2ImageClass (Main_cloud2ImageClass)
package {
import mx.core.*;
public class Main_cloud2ImageClass extends BitmapAsset {
}
}//package
Section 43
//Main_cloud3ImageClass (Main_cloud3ImageClass)
package {
import mx.core.*;
public class Main_cloud3ImageClass extends BitmapAsset {
}
}//package
Section 44
//Main_maxgames (Main_maxgames)
package {
import mx.core.*;
import flash.utils.*;
public class Main_maxgames extends MovieClipLoaderAsset {
public var dataClass:Class;
private static var bytes:ByteArray = null;
public function Main_maxgames(){
dataClass = Main_maxgames_dataClass;
super();
initialWidth = (11000 / 20);
initialHeight = (8000 / 20);
}
override public function get movieClipData():ByteArray{
if (bytes == null){
bytes = ByteArray(new dataClass());
};
return (bytes);
}
}
}//package
Section 45
//Main_maxgames_dataClass (Main_maxgames_dataClass)
package {
import mx.core.*;
public class Main_maxgames_dataClass extends ByteArrayAsset {
}
}//package
Section 46
//Main_maxgamesLogo (Main_maxgamesLogo)
package {
import mx.core.*;
public class Main_maxgamesLogo extends BitmapAsset {
}
}//package
Section 47
//Main_musicClass (Main_musicClass)
package {
import mx.core.*;
public class Main_musicClass extends SoundAsset {
}
}//package
Section 48
//Main_soundOFF (Main_soundOFF)
package {
import mx.core.*;
public class Main_soundOFF extends BitmapAsset {
}
}//package
Section 49
//Main_soundON (Main_soundON)
package {
import mx.core.*;
public class Main_soundON extends BitmapAsset {
}
}//package
Section 50
//Main_sunImageClass (Main_sunImageClass)
package {
import mx.core.*;
public class Main_sunImageClass extends BitmapAsset {
}
}//package
Section 51
//Main_swampImageClass (Main_swampImageClass)
package {
import mx.core.*;
public class Main_swampImageClass extends BitmapAsset {
}
}//package
Section 52
//MochiAd (MochiAd)
package {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
public class MochiAd {
public static function getVersion():String{
return ("2.5");
}
public static function showClickAwayAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:2000, regpt:"o", method:"showClickAwayAd", res:"300x250", no_bg:true, ad_started:function ():void{
}, ad_finished:function ():void{
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
clip = options.clip;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
options.ad_finished();
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
mc.unloadAd = function ():void{
MochiAd.unload(clip);
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
var sendHostProgress:Boolean;
mc.regContLC = function (lc_name:String):void{
mc._containerLCName = lc_name;
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (!this.parent){
delete this.onEnterFrame;
return;
};
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
finished = true;
chk.started = getTimer();
} else {
if (elapsed > chk.ad_timeout){
options.ad_failed();
finished = true;
};
};
};
if (this.root == null){
finished = true;
};
if (finished){
delete this.onEnterFrame;
};
};
doOnEnterFrame(chk);
}
public static function _isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
public static function _allowDomains(server:String):String{
var hostname:String = server.split("/")[2].split(":")[0];
Security.allowDomain("*");
Security.allowDomain(hostname);
Security.allowInsecureDomain("*");
Security.allowInsecureDomain(hostname);
return (hostname);
}
public static function unload(clip:Object):Boolean{
if (((clip.clip) && (clip.clip._mochiad))){
clip = clip.clip;
};
if (clip.origFrameRate != undefined){
clip.stage.frameRate = clip.origFrameRate;
};
if (!clip._mochiad){
return (false);
};
if (clip._mochiad._containerLCName != undefined){
clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"unload"});
};
if (clip._mochiad.onUnload){
clip._mochiad.onUnload();
};
delete clip._mochiad_loaded;
delete clip._mochiad;
return (true);
}
public static function showInterLevelAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:2000, fadeout_time:250, regpt:"o", method:"showTimedAd", ad_started:function ():void{
if ((this.clip is MovieClip)){
this.clip.stop();
} else {
throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_finished:function ():void{
if ((this.clip is MovieClip)){
this.clip.play();
} else {
throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
clip = options.clip;
var ad_msec:Number = 11000;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time:Number = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
options.ad_finished();
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.ad_msec = ad_msec;
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function ():void{
if (!this.parent){
delete this.onEnterFrame;
delete this.fadeFunction;
return;
};
var p:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time)));
if (p > 0){
this.parent.alpha = (p * 0.01);
} else {
MochiAd.unload(clip);
delete this["onEnterFrame"];
};
};
mc.unloadAd = function ():void{
MochiAd.unload(clip);
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.adjustProgress = function (msec:Number):void{
var _chk:Object = mc._mochiad_wait;
_chk.server_control = true;
_chk.showing = true;
_chk.started = getTimer();
_chk.ad_msec = (msec - 250);
};
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (!this.parent){
delete this.onEnterFrame;
delete this.fadeFunction;
return;
};
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
chk.started = getTimer();
MochiAd.adShowing(clip);
} else {
if (elapsed > chk.ad_timeout){
options.ad_failed();
finished = true;
};
};
};
if (elapsed > chk.ad_msec){
finished = true;
};
if (finished){
if (this.server_control){
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = this.fadeFunction;
};
};
};
doOnEnterFrame(chk);
}
public static function _parseOptions(options:Object, defaults:Object):Object{
var k:String;
var pairs:Array;
var i:Number;
var kv:Array;
var optcopy:Object = {};
for (k in defaults) {
optcopy[k] = defaults[k];
};
if (options){
for (k in options) {
optcopy[k] = options[k];
};
};
if (optcopy.clip == undefined){
throw (new Error("MochiAd is missing the 'clip' parameter. This should be a MovieClip, Sprite or an instance of a class that extends MovieClip or Sprite."));
};
options = optcopy.clip.loaderInfo.parameters.mochiad_options;
if (options){
pairs = options.split("&");
i = 0;
while (i < pairs.length) {
kv = pairs[i].split("=");
optcopy[unescape(kv[0])] = unescape(kv[1]);
i++;
};
};
if (optcopy.id == "test"){
trace("[MochiAd] WARNING: Using the MochiAds test identifier, make sure to use the code from your dashboard, not this example!");
};
return (optcopy);
}
public static function _cleanup(mc:Object):void{
var k:String;
var lc:LocalConnection;
var f:Function;
var mc = mc;
if (("lc" in mc)){
lc = mc.lc;
f = function ():void{
lc.client = null;
lc.close();
//unresolved jump
var _slot1 = e;
};
setTimeout(f, 0);
};
var idx:Number = DisplayObjectContainer(mc).numChildren;
while (idx > 0) {
idx = (idx - 1);
DisplayObjectContainer(mc).removeChildAt(idx);
};
for (k in mc) {
delete mc[k];
};
}
public static function load(options:Object):MovieClip{
var clip:Object;
var k:String;
var server:String;
var hostname:String;
var lc:LocalConnection;
var name:String;
var loader:Loader;
var g:Function;
var req:URLRequest;
var v:Object;
var options = options;
var DEFAULTS:Object = {server:"http://x.mochiads.com/srv/1/", method:"load", depth:10333, id:"_UNKNOWN_"};
options = MochiAd._parseOptions(options, DEFAULTS);
options.swfv = 9;
options.mav = MochiAd.getVersion();
clip = options.clip;
if (!MochiAd._isNetworkAvailable()){
return (null);
};
if (clip._mochiad_loaded){
return (null);
};
//unresolved jump
var _slot1 = e;
throw (new Error("MochiAd requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic."));
var depth:Number = options.depth;
delete options.depth;
var mc:MovieClip = createEmptyMovieClip(clip, "_mochiad", depth);
var wh:Array = MochiAd._getRes(options, clip);
options.res = ((wh[0] + "x") + wh[1]);
options.server = (options.server + options.id);
delete options.id;
clip._mochiad_loaded = true;
if (clip.loaderInfo.loaderURL.indexOf("http") == 0){
options.as3_swf = clip.loaderInfo.loaderURL;
};
var lv:URLVariables = new URLVariables();
for (k in options) {
v = options[k];
if (!(v is Function)){
lv[k] = v;
};
};
server = lv.server;
delete lv.server;
hostname = _allowDomains(server);
lc = new LocalConnection();
lc.client = mc;
name = ["", Math.floor(new Date().getTime()), Math.floor((Math.random() * 999999))].join("_");
lc.allowDomain("*", "localhost");
lc.allowInsecureDomain("*", "localhost");
lc.connect(name);
mc.lc = lc;
mc.lcName = name;
lv.lc = name;
lv.st = getTimer();
loader = new Loader();
g = function (ev:Object):void{
ev.target.removeEventListener(ev.type, arguments.callee);
MochiAd.unload(clip);
};
loader.contentLoaderInfo.addEventListener(Event.UNLOAD, g);
req = new URLRequest((server + ".swf"));
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
loader.load(req);
mc.addChild(loader);
mc._mochiad_ctr = loader;
return (mc);
}
public static function runMethod(base:Object, methodName:String, argsArray:Array):Object{
var nameArray:Array = methodName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return (undefined);
};
base = base[nameArray[i]];
i++;
};
if (typeof(base[nameArray[i]]) == "function"){
return (base[nameArray[i]].apply(base, argsArray));
};
return (undefined);
}
public static function createEmptyMovieClip(parent:Object, name:String, depth:Number):MovieClip{
var mc:MovieClip = new MovieClip();
if (((false) && (depth))){
parent.addChildAt(mc, depth);
} else {
parent.addChild(mc);
};
parent[name] = mc;
mc["_name"] = name;
return (mc);
}
public static function _getRes(options:Object, clip:Object):Array{
var xy:Array;
var b:Object = clip.getBounds(clip.root);
var w:Number = 0;
var h:Number = 0;
if (typeof(options.res) != "undefined"){
xy = options.res.split("x");
w = parseFloat(xy[0]);
h = parseFloat(xy[1]);
} else {
w = (b.xMax - b.xMin);
h = (b.yMax - b.yMin);
};
if ((((w == 0)) || ((h == 0)))){
w = clip.stage.stageWidth;
h = clip.stage.stageHeight;
};
return ([w, h]);
}
public static function adShowing(mc:Object):void{
mc.origFrameRate = mc.stage.frameRate;
mc.stage.frameRate = 30;
}
public static function getValue(base:Object, objectName:String):Object{
var nameArray:Array = objectName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return (undefined);
};
base = base[nameArray[i]];
i++;
};
return (base[nameArray[i]]);
}
public static function rpc(clip:Object, callbackID:Number, arg:Object):void{
var _local4:Object;
var _local5:Object;
switch (arg.id){
case "setValue":
MochiAd.setValue(clip, arg.objectName, arg.value);
break;
case "getValue":
_local4 = MochiAd.getValue(clip, arg.objectName);
clip._mochiad.lc.send(clip._mochiad._containerLCName, "rpcResult", callbackID, _local4);
break;
case "runMethod":
_local5 = MochiAd.runMethod(clip, arg.method, arg.args);
clip._mochiad.lc.send(clip._mochiad._containerLCName, "rpcResult", callbackID, _local5);
break;
default:
trace(("[mochiads rpc] unknown rpc id: " + arg.id));
};
}
public static function setValue(base:Object, objectName:String, value:Object):void{
var nameArray:Array = objectName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return;
};
base = base[nameArray[i]];
i++;
};
base[nameArray[i]] = value;
}
public static function showPreGameAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var complete:Boolean;
var unloaded:Boolean;
var sendHostProgress:Boolean;
var r:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:3000, fadeout_time:250, regpt:"o", method:"showPreloaderAd", color:0xFF8A00, background:16777161, outline:13994812, no_progress_bar:false, ad_started:function ():void{
if ((this.clip is MovieClip)){
this.clip.stop();
} else {
throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_finished:function ():void{
if ((this.clip is MovieClip)){
this.clip.play();
} else {
throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}, ad_progress:function (percent:Number):void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
if ("c862232051e0a94e1c3609b3916ddb17".substr(0) == "dfeada81ac97cde83665f81c12da7def"){
options.ad_started();
setTimeout(options.ad_finished, 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;
bar.y = (h - 20);
};
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((w - 20), 0);
backing.lineTo((w - 20), 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((w - 20), 0);
inside.lineTo((w - 20), 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((w - 20), 0);
outline.lineTo((w - 20), 10);
outline.lineTo(0, 10);
outline.lineTo(0, 0);
chk.ad_msec = ad_msec;
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
chk.last_pcnt = 0;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function ():void{
var p:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time)));
if (p > 0){
this.parent.alpha = (p * 0.01);
} else {
MochiAd.unload(clip);
delete this["onEnterFrame"];
};
};
complete = false;
unloaded = false;
var f:Function = function (ev:Event):void{
ev.target.removeEventListener(ev.type, arguments.callee);
complete = true;
if (unloaded){
MochiAd.unload(clip);
};
};
clip.loaderInfo.addEventListener(Event.COMPLETE, f);
if ((clip.root is MovieClip)){
r = (clip.root as MovieClip);
if (r.framesLoaded >= r.totalFrames){
complete = true;
};
};
mc.unloadAd = function ():void{
unloaded = true;
if (complete){
MochiAd.unload(clip);
};
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.adjustProgress = function (msec:Number):void{
var _chk:Object = mc._mochiad_wait;
_chk.server_control = true;
_chk.showing = true;
_chk.started = getTimer();
_chk.ad_msec = msec;
};
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
mc.rpcTestFn = function (s:String):Object{
trace(("[MOCHIAD rpcTestFn] " + s));
return (s);
};
mc.regContLC = function (lc_name:String):void{
mc._containerLCName = lc_name;
};
sendHostProgress = false;
mc.sendHostLoadProgress = function (lc_name:String):void{
sendHostProgress = true;
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (((!(this.parent)) || (!(this.parent.parent)))){
delete this["onEnterFrame"];
return;
};
var _clip:Object = this.parent.parent.root;
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
var clip_total:Number = _clip.loaderInfo.bytesTotal;
var clip_loaded:Number = _clip.loaderInfo.bytesLoaded;
if (complete){
clip_loaded = Math.max(1, clip_loaded);
clip_total = clip_loaded;
};
var clip_pcnt:Number = ((100 * clip_loaded) / clip_total);
var ad_pcnt:Number = ((100 * elapsed) / chk.ad_msec);
var _inside:Object = this._mochiad_bar._inside;
var pcnt:Number = Math.min(100, Math.min(((clip_pcnt) || (0)), ad_pcnt));
pcnt = Math.max(this.last_pcnt, pcnt);
this.last_pcnt = pcnt;
_inside.scaleX = (pcnt * 0.01);
options.ad_progress(pcnt);
if (sendHostProgress){
clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"hostLoadPcnt", pcnt:clip_pcnt});
if (clip_pcnt == 100){
sendHostProgress = false;
};
};
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
chk.started = getTimer();
MochiAd.adShowing(clip);
} else {
if ((((elapsed > chk.ad_timeout)) && ((clip_pcnt == 100)))){
options.ad_failed();
finished = true;
};
};
};
if (elapsed > chk.ad_msec){
finished = true;
};
if (((complete) && (finished))){
if (this.server_control){
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = chk.fadeFunction;
};
};
};
doOnEnterFrame(chk);
}
public static function showPreloaderAd(options:Object):void{
trace("[MochiAd] DEPRECATED: showPreloaderAd was renamed to showPreGameAd in 2.0");
MochiAd.showPreGameAd(options);
}
public static function showTimedAd(options:Object):void{
trace("[MochiAd] DEPRECATED: showTimedAd was renamed to showInterLevelAd in 2.0");
MochiAd.showInterLevelAd(options);
}
public static function doOnEnterFrame(mc:MovieClip):void{
var mc = mc;
var f:Function = function (ev:Object):void{
if (((("onEnterFrame" in mc)) && (mc.onEnterFrame))){
mc.onEnterFrame();
} else {
ev.target.removeEventListener(ev.type, arguments.callee);
};
};
mc.addEventListener(Event.ENTER_FRAME, f);
}
}
}//package