home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 151
/
MOBICLIC151.ISO
/
mac
/
DATA
/
SCI151
/
SCI151_00
/
SCI151_00.swf
/
scripts
/
sci150_00
/
CapsuleAlgo.as
Wrap
Text File
|
2013-01-17
|
12KB
|
358 lines
package sci150_00
{
import com.milanpresse.engine.text.TextBloc;
import com.milanpresse.engineaddons.facades.GameEngine;
import com.milanpresse.engineaddons.gamesprotos.actors.actorClip.IActorClip;
import com.milanpresse.tools.GlobalesFunctions;
import com.milanpresse.tools.debug.TestBox;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.utils.Timer;
public class CapsuleAlgo
{
protected var game:GameEngine;
protected var generique:IActorClip;
protected var mainTimeline:IActorClip;
protected var testBox:TestBox;
protected var rect:IActorClip = null;
protected var timer:Timer;
protected var pos:Point;
protected var tb:TextBloc;
protected var nuage:IActorClip;
protected var strarr:Array;
protected var strarrIndex:int = -1;
protected var tbs:Vector.<TextBloc>;
public var isSleeping:Boolean = false;
public var isTimerSleeping:Boolean = false;
public function CapsuleAlgo(param1:GameEngine)
{
this.timer = new Timer(100);
this.pos = new Point();
this.tbs = new Vector.<TextBloc>();
super();
this.game = param1;
this.init();
}
protected function init() : void
{
var tab:Vector.<DisplayObject> = null;
var tab2:Vector.<DisplayObject> = null;
this.game.framerate = 24;
this.generique = this.game.addActor({
"code":"GENERIQUE",
"parent":this.game.config.layers.content
});
this.generique.getChildByName("TITRE_GENERIQUE").visible = false;
this.mainTimeline = this.game.addActor({
"code":"A_" + this.game.config.moduleName,
"parent":this.game.config.layers.content
});
this.mainTimeline.visible = false;
tab = new Vector.<DisplayObject>();
tab2 = new Vector.<DisplayObject>();
this.mainTimeline.onLabelExit = function(param1:*):void
{
tab = GlobalesFunctions.getChildrenByTypeRecursive(mainTimeline.clip,MovieClip,false,4);
};
this.mainTimeline.onLabelEnter = function(param1:*):void
{
tab2 = GlobalesFunctions.getChildrenByTypeRecursive(mainTimeline.clip,MovieClip,false,4);
var _loc2_:int = 0;
while(_loc2_ < tab.length)
{
if(tab2.indexOf(tab[_loc2_]) == -1)
{
(tab[_loc2_] as MovieClip).stop();
}
_loc2_++;
}
};
this.mainTimeline["labelATTENTE"] = function():void
{
var btn:IActorClip = game.addActor({
"mc":mainTimeline.getChildByName("BT_REVOIR") as MovieClip,
"onRollOverState":{
"ibId":"IB_REVOIR",
"noiseCode":"B_REVOIR"
}
});
btn.initAs();
btn.onClick = function(param1:IActorClip):void
{
mainTimeline.gotoAndPlay(mainTimeline.currentLabels[0].name);
};
btn.enabled = true;
};
this.testBox = new TestBox(this.game.engine);
this.testBox.buttons = [{
"name":"BTN_PAUSE",
"label":"PAUSE"
},{
"name":"BTN_WAKE",
"label":"WAKE"
}];
this.testBox.onClick = function(param1:String):void
{
switch(param1)
{
case "BTN_PAUSE":
game.sleep();
break;
case "BTN_WAKE":
game.wake();
}
};
this.testBox.visible = false;
}
public function start() : void
{
this.generiqueStart();
}
public function createRectangle(param1:Object) : MovieClip
{
var _loc2_:MovieClip = new MovieClip();
_loc2_.visible = false;
_loc2_.graphics.beginFill(param1.color == undefined ? uint(0) : uint(param1.color),param1.alpha == undefined ? Number(1) : Number(param1.alpha));
_loc2_.graphics.drawRect(param1.x == undefined ? Number(0) : Number(param1.x),param1.y == undefined ? Number(0) : Number(param1.y),param1.w == undefined ? Number(800) : Number(param1.w),param1.h == undefined ? Number(600) : Number(param1.h));
_loc2_.graphics.endFill();
return _loc2_;
}
protected function generiqueStart() : void
{
this.generique.onLabelEnter = this.generiqueOnLabelEnter;
this.rect = this.game.addActor({
"mc":this.createRectangle({}),
"parent":this.game.config.layers.content
});
this.rect.visible = true;
this.rect.alpha = 0;
this.rect.onClick = function(param1:IActorClip):void
{
rect.enabled = false;
timer.stop();
generique.stop();
generique.destroy();
mainTimeline.visible = true;
mainTimeline.gotoAndPlay(mainTimeline.currentLabels[0].name);
game.playMusic({"code":"MU"});
rect.destroy();
rect = null;
};
this.rect.initAs();
this.generique.play("START");
}
protected function generiqueOnLabelEnter(param1:*) : void
{
switch(param1.label)
{
case "PLAY":
this.generiqueTexteStart();
break;
case "PLAY_JINGLE":
this.game.commentPlay({
"code":"JINGLE",
"zapBlock":"NOZAP_NOBLOCK"
});
break;
case "FIN":
if(this.rect != null)
{
this.rect.destroy();
}
this.generique.stop();
this.generique.destroy();
this.mainTimeline.visible = true;
this.game.playMusic({"code":"MU"});
this.mainTimeline.gotoAndPlay(this.mainTimeline.currentLabels[0].name);
}
}
public function generiqueTexteStart() : void
{
var _loc5_:int = 0;
var _loc9_:int = 0;
var _loc10_:int = 0;
var _loc1_:MovieClip = this.generique.getChildByName("TITRE_GENERIQUE") as MovieClip;
_loc1_.visible = false;
this.pos.y = _loc1_.y;
this.pos.x = _loc1_.x;
var _loc2_:int = 1;
var _loc3_:Boolean = false;
this.strarr = this.game.getMediaText({"id":"LM_TITRE"}).text.split(" ");
var _loc4_:int = 0;
while(_loc4_ < this.strarr.length)
{
_loc3_ = false;
if(this.strarr[_loc4_].search(/§$/) != -1)
{
_loc3_ = true;
this.strarr[_loc4_] = (this.strarr[_loc4_] as String).slice(0,-1);
}
this.tb = this.game.showTextBloc({
"text":this.strarr[_loc4_],
"idStyle":"LM.LM_TITRE",
"parent":_loc1_.parent
});
this.generique.clip.addChildAt(this.tb,this.generique.clip.getChildIndex(_loc1_));
this.tb.visible = false;
this.tb.x = this.pos.x;
this.tb.y = this.pos.y;
this.tb["row"] = _loc2_;
this.pos.x += this.tb.width + 5;
if(this.pos.x > _loc1_.x + _loc1_.width)
{
this.pos.x = _loc1_.x + this.tb.width + 5;
this.pos.y += this.tb.height + 5;
this.tb.x = _loc1_.x;
this.tb.y = this.pos.y;
_loc2_++;
this.tb["row"] = _loc2_;
}
if(_loc3_ == true)
{
this.pos.x = _loc1_.x;
this.pos.y += this.tb.height + 5;
_loc2_++;
}
this.tbs.push(this.tb);
_loc4_++;
}
_loc5_ = 0;
while(_loc5_ < this.tbs.length)
{
_loc5_++;
}
var _loc6_:Number = 0;
var _loc7_:Number = 0;
var _loc8_:int = 1;
while(_loc8_ <= _loc2_)
{
_loc6_ = 0;
_loc7_ = 0;
_loc9_ = 0;
while(_loc9_ < this.tbs.length)
{
if(this.tbs[_loc9_]["row"] == _loc8_)
{
_loc6_ += this.tbs[_loc9_].width + 5;
}
_loc9_++;
}
_loc7_ = (_loc1_.width - _loc6_) / 2;
_loc10_ = 0;
while(_loc10_ < this.tbs.length)
{
if(this.tbs[_loc10_]["row"] == _loc8_)
{
this.tbs[_loc10_].x += _loc7_;
}
_loc10_++;
}
_loc8_++;
}
_loc5_ = 0;
while(_loc5_ < this.tbs.length)
{
_loc5_++;
}
this.timer.addEventListener(TimerEvent.TIMER,this.onTimer);
this.timer.start();
}
public function onTimer(param1:TimerEvent) : void
{
var nuage:IActorClip = null;
var event:TimerEvent = param1;
++this.strarrIndex;
if(this.strarrIndex > this.strarr.length - 1)
{
this.timer.stop();
this.timer.removeEventListener(TimerEvent.TIMER,this.onTimer);
}
else
{
nuage = this.game.addActor({
"mc":new NUAGE_PETIT(),
"parent":this.generique.clip
});
nuage["tb"] = this.tbs[this.strarrIndex];
nuage.onFrameExit = function(param1:* = null):void
{
if(this.currentFrame == 8)
{
nuage["tb"].visible = true;
}
if(this.currentFrame == this.totalFrames)
{
this.destroy();
}
};
nuage.x = this.tbs[this.strarrIndex].x + this.tbs[this.strarrIndex].width / 2;
nuage.y = this.tbs[this.strarrIndex].y + this.tbs[this.strarrIndex].height / 2;
nuage.play(1);
}
}
public function sleep() : void
{
if(this.isSleeping)
{
return;
}
this.isSleeping = true;
if(this.timer.running)
{
this.isTimerSleeping = true;
this.timer.stop();
}
}
public function wake() : void
{
if(this.isSleeping == false)
{
return;
}
this.isSleeping = false;
if(this.isTimerSleeping)
{
this.isTimerSleeping = false;
this.timer.start();
}
}
public function destroy() : void
{
if(this.timer != null)
{
this.timer.stop();
this.timer.removeEventListener(TimerEvent.TIMER,this.onTimer);
}
}
}
}