home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Puzzle
/
HexiomConnect.swf
/
scripts
/
Factory.as
< prev
next >
Wrap
Text File
|
2008-08-29
|
7KB
|
198 lines
package
{
import flash.display.DisplayObject;
import flash.display.FrameLabel;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.utils.getDefinitionByName;
public class Factory extends MovieClip
{
private static const Preloader:Class = Factory_Preloader;
public static var ON_BICLOPS:Boolean = false;
private static const Intro:Class = Factory_Intro;
public static var ON_KONG:Boolean = false;
private var intro:MovieClip;
private var bar:Sprite;
private var preloader:MovieClip;
private var antFinished:Boolean = false;
private var loadFinished:Boolean = false;
public function Factory()
{
var cMenuItem:ContextMenuItem = null;
var barHouse:Sprite = null;
var kongButton:SimpleButton = null;
var biclopsButton:SimpleButton = null;
var antAnim:MovieClip = null;
super();
stop();
graphics.beginFill(0);
graphics.drawRect(0,0,400,400);
graphics.endFill();
ON_KONG = stage.loaderInfo.loaderURL.indexOf("kongregate.com") >= 0;
ON_BICLOPS = stage.loaderInfo.loaderURL.indexOf("biclopsgames.com") >= 0;
Links.stage = stage;
stage.frameRate = 30;
stage.tabChildren = false;
var cMenu:ContextMenu = new ContextMenu();
cMenu.hideBuiltInItems();
cMenuItem = new ContextMenuItem("Created by Biclops Games");
cMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,Links.biclopsLink);
cMenu.customItems.push(cMenuItem);
cMenuItem = new ContextMenuItem("Sponsored by Kongregate.com");
cMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,Links.sponsorLink);
cMenu.customItems.push(cMenuItem);
this.contextMenu = cMenu;
if(ON_KONG)
{
preloader = new Preloader();
preloader.stop();
preloader.addFrameScript(preloader.totalFrames - 1,preloaderEnd);
addChild(preloader);
barHouse = preloader.getChildByName("barHouse") as Sprite;
bar = barHouse.getChildByName("bar") as Sprite;
kongButton = preloader.getChildByName("kongButton") as SimpleButton;
kongButton.addEventListener(MouseEvent.CLICK,Links.sponsorLink,false,0,true);
biclopsButton = preloader.getChildByName("biclopsButton") as SimpleButton;
biclopsButton.addEventListener(MouseEvent.CLICK,Links.biclopsLink,false,0,true);
antAnim = preloader.getChildByName("antAnim") as MovieClip;
antAnim.addFrameScript(antAnim.totalFrames - 1,function():void
{
antAnim.stop();
antAnimFinished();
});
addEventListener(Event.ENTER_FRAME,onEnterFrame,false,0,true);
}
else
{
preloader = new MovieClip();
addChild(preloader);
MochiAd.showPreGameAd({
"clip":preloader,
"id":"1b810d465c3e11d5",
"res":"400x400",
"ad_finished":adFinished
});
}
}
public function startGame() : void
{
var _loc2_:Object = null;
if(preloader && preloader.parent)
{
preloader.parent.removeChild(preloader);
}
preloader = null;
bar = null;
nextFrame();
var _loc1_:Class = getDefinitionByName("Game") as Class;
if(_loc1_)
{
_loc2_ = new _loc1_();
addChild(_loc2_ as DisplayObject);
}
}
private function playClick(param1:MouseEvent) : void
{
intro.play();
}
private function preloaderEnd() : void
{
preloader.stop();
startGame();
}
private function finishedLoading() : void
{
removeEventListener(Event.ENTER_FRAME,onEnterFrame);
loadFinished = true;
if(loadFinished && antFinished)
{
preloader.play();
}
}
private function antAnimFinished() : void
{
antFinished = true;
if(loadFinished && antFinished)
{
preloader.play();
}
}
private function onEnterFrame(param1:Event) : void
{
var _loc2_:Number = root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal;
bar.x = 300 * (_loc2_ - 1);
if(framesLoaded == totalFrames)
{
finishedLoading();
}
}
private function adFinished() : void
{
var antAnim:MovieClip = null;
var label:FrameLabel = null;
var playButton:SimpleButton = null;
intro = new Intro();
var kongButton:SimpleButton = intro.getChildByName("kongButton") as SimpleButton;
kongButton.addEventListener(MouseEvent.CLICK,Links.sponsorLink,false,0,true);
var biclopsButton:SimpleButton = intro.getChildByName("biclopsButton") as SimpleButton;
biclopsButton.addEventListener(MouseEvent.CLICK,Links.biclopsLink,false,0,true);
antAnim = intro.getChildByName("antAnim") as MovieClip;
antAnim.addFrameScript(antAnim.totalFrames - 1,function():void
{
antAnim.stop();
});
var playFrame:int = 100;
var labels:Array = intro.currentLabels;
for each(label in labels)
{
if(label.name == "Play Frame")
{
playFrame = label.frame;
break;
}
}
playButton = intro.getChildByName("playButton") as SimpleButton;
if(playButton)
{
playButton.addEventListener(MouseEvent.CLICK,playClick,false,0,true);
intro.addFrameScript(playFrame - 1,function():void
{
intro.stop();
});
}
intro.addFrameScript(intro.totalFrames - 1,function():void
{
intro.stop();
removeChild(intro);
startGame();
});
addChild(intro);
}
}
}