home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mobiclic 145
/
MOBICLIC145.ISO
/
pc
/
DATA
/
DSS145
/
DSS145_10
/
DSS145_10.swf
/
scripts
/
dss145_10
/
AttenteJeu.as
next >
Wrap
Text File
|
2012-07-18
|
17KB
|
484 lines
package dss145_10
{
import com.milanpresse.engineaddons.facades.EngineExt;
import com.milanpresse.engineaddons.initdisplayobject.ExtendedClip;
import com.milanpresse.engineaddons.labelstypes.AttenteLabel;
import com.milanpresse.tools.*;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
public class AttenteJeu extends AttenteLabel
{
public var config:AttenteJeuConfig;
public var CONTAINER:DisplayObjectContainer;
public var mainAlgo:CapsuleAlgo;
public var BT_REJOUER:ExtendedClip;
public var BT_AIDE:ExtendedClip;
public var CLIP_AIDE:ExtendedClip;
public var GERYON:ExtendedClip;
public var HERAKLES:ExtendedClip;
public var BT_FLECHE_DO:ExtendedClip;
public var BT_FLECHE_UP:ExtendedClip;
public var JAUGE:ExtendedClip;
public var BLOC_QUESTIONS:ExtendedClip;
public var BLOC_QUESTIONS_DRAG:ExtendedClip;
public var CURSEUR:Cursor;
private var _questionsJeuManager:Questions;
private var _questionOriginalList:Vector.<Question>;
private var jaugeValue:Number = 0;
private var GeryonTouche:Boolean = false;
private var _temp_point:Point;
private var _zoneLimit:Rectangle;
public function AttenteJeu(param1:EngineExt, param2:Function = null)
{
this.config = new AttenteJeuConfig();
this._questionOriginalList = new Vector.<Question>();
this._temp_point = new Point();
this._zoneLimit = new Rectangle(0,0,800,600);
super(param1,param2);
}
public function init() : void
{
this.CONTAINER = this.config.CONTAINER;
this.CLIP_AIDE_Init();
this.BT_REJOUER_Init();
this.BT_AIDE_Init();
this.GERYON_Init();
this.HERAKLES_Init();
this.BT_FLECHE_DO_Init();
this.BT_FLECHE_UP_Init();
this.JAUGE_Init();
this.jaugeChange(0);
this.createQuestionsListe();
this._questionsJeuManager.melanger();
this._questionsJeuManager.next();
this.BLOC_QUESTION_Init();
}
private function CLIP_AIDE_Init() : void
{
var clip:ExtendedClip = this.CLIP_AIDE = new ExtendedClip(this.config.CLIP_AIDE as MovieClip,_e);
clip.onPress = function():void
{
CLIP_AIDE.visible = false;
_e.commentStop();
};
clip.enabled = false;
clip.visible = false;
clip.init();
}
private function BT_REJOUER_Init() : void
{
var clip:ExtendedClip = this.BT_REJOUER = new ExtendedClip(this.config.BT_REJOUER as MovieClip,_e);
clip.onPressState = {"label":"E1"};
clip.onRollOverState = {
"label":"E2",
"noiseCode":"B_REJ"
};
clip.onRollOutState = {"label":"E1"};
clip.onPress = function():void
{
rejouer();
};
clip.enabled = false;
clip.visible = false;
clip.init();
}
private function BT_AIDE_Init() : void
{
var clip:ExtendedClip = this.BT_AIDE = new ExtendedClip(this.config.BT_AIDE as MovieClip,_e);
clip.onPressState = {"label":"E1"};
clip.onRollOverState = {
"label":"E2",
"noiseCode":"B_AIDE"
};
clip.onRollOutState = {"label":"E1"};
clip.onPress = function():void
{
CLIP_AIDE.visible = true;
CLIP_AIDE.enabled = true;
_e.commentPlay({
"code":"AIDE",
"zapBlock":"NOZAP_NOBLOCK"
});
};
clip.enabled = true;
clip.init();
}
private function BT_FLECHE_DO_Init() : void
{
var clip:ExtendedClip = this.BT_FLECHE_DO = new ExtendedClip(this.config.BT_FLECHE_DO as MovieClip,_e);
clip.onPressState = {"label":"E1"};
clip.onRollOverState = {
"label":"E2",
"noiseCode":"B_FLECHE"
};
clip.onRollOutState = {"label":"E1"};
clip.onPress = function():void
{
_questionsJeuManager.next();
BLOC_QUESTION_Refresh();
};
clip.enabled = true;
clip.init();
}
private function BT_FLECHE_UP_Init() : void
{
var clip:ExtendedClip = this.BT_FLECHE_UP = new ExtendedClip(this.config.BT_FLECHE_UP as MovieClip,_e);
clip.onPressState = {"label":"E1"};
clip.onRollOverState = {
"label":"E2",
"noiseCode":"B_FLECHE"
};
clip.onRollOutState = {"label":"E1"};
clip.onPress = function():void
{
_questionsJeuManager.previous();
BLOC_QUESTION_Refresh();
};
clip.enabled = true;
clip.init();
}
private function GERYON_Init() : void
{
var _loc1_:ExtendedClip = this.GERYON = new ExtendedClip(this.config.GERYON as MovieClip,_e);
_loc1_.init();
}
private function HERAKLES_Init() : void
{
var _loc1_:ExtendedClip = this.HERAKLES = new ExtendedClip(this.config.HERAKLES as MovieClip,_e);
_loc1_.init();
}
private function JAUGE_Init() : void
{
var _loc1_:ExtendedClip = this.JAUGE = new ExtendedClip(this.config.JAUGE as MovieClip,_e);
_loc1_.init();
}
private function jaugeChange(param1:Number) : void
{
this.jaugeValue += param1;
if(this.jaugeValue > 100)
{
this.jaugeValue = 100;
}
if(this.jaugeValue < 0)
{
this.jaugeValue = 0;
}
this.JAUGE.gotoAndStop(this.jaugeValue);
}
private function BLOC_QUESTION_Init() : void
{
this.BLOC_QUESTIONS = new ExtendedClip(this.config.BLOC_QUESTIONS as MovieClip,_e);
this.BLOC_QUESTIONS.modelText = this.BLOC_QUESTIONS.getChildByName("TEXT");
this.BLOC_QUESTIONS.onPressState = {"label":"E1"};
this.BLOC_QUESTIONS.onRollOverState = {
"label":"E1",
"noiseCode":"B_FLECHE"
};
this.BLOC_QUESTIONS.onRollOutState = {"label":"E1"};
this.BLOC_QUESTIONS.onPress = function():void
{
BLOC_QUESTIONS.visible = false;
BT_FLECHE_DO.visible = false;
BT_FLECHE_UP.visible = false;
CURSEUR.lock = true;
CURSEUR.cursor = "mainF";
BLOC_QUESTIONS_DRAG.TEXTBLOC.text = _questionsJeuManager.question.text;
BLOC_QUESTIONS_DRAG.TEXTBLOC.x = BLOC_QUESTIONS_DRAG.modelText.x + BLOC_QUESTIONS_DRAG.modelText.width / 2 - BLOC_QUESTIONS_DRAG.TEXTBLOC.width / 2;
BLOC_QUESTIONS.TEXTBLOC.y = BLOC_QUESTIONS_DRAG.modelText.y + BLOC_QUESTIONS_DRAG.modelText.height / 2 - BLOC_QUESTIONS_DRAG.TEXTBLOC.height / 2;
BLOC_QUESTIONS_DRAG.width = BLOC_QUESTIONS.width;
BLOC_QUESTIONS_DRAG.height = BLOC_QUESTIONS.height;
BLOC_QUESTIONS_DRAG.x = CONTAINER.mouseX;
BLOC_QUESTIONS_DRAG.y = CONTAINER.mouseY;
CONTAINER.stage.addEventListener(Event.ENTER_FRAME,onDrag);
CONTAINER.stage.addEventListener(MouseEvent.MOUSE_UP,stopDrag);
BLOC_QUESTIONS_DRAG.addToParent(CONTAINER);
BLOC_QUESTIONS_DRAG.visible = true;
};
this.BLOC_QUESTIONS.onRollOver = function():void
{
CURSEUR.cursor = "mainO";
};
this.BLOC_QUESTIONS.onRollOut = function():void
{
CURSEUR.cursor = "fleche";
};
this.BLOC_QUESTIONS.enabled = true;
this.BLOC_QUESTIONS.init();
this.BLOC_QUESTIONS.TEXTBLOC = _e.textShow({
"id":this._questionsJeuManager.question.idLM,
"model":this.BLOC_QUESTIONS.modelText,
"idStyle":"LM.LM_Q"
});
this.BLOC_QUESTION_Refresh();
this.BLOC_QUESTIONS_DRAG = new ExtendedClip(this.config.BLOC_QUESTIONS_DRAG as MovieClip,_e);
this.BLOC_QUESTIONS_DRAG.modelText = this.BLOC_QUESTIONS_DRAG.getChildByName("TEXT");
this.BLOC_QUESTIONS_DRAG.init();
this.BLOC_QUESTIONS_DRAG.visible = false;
this.BLOC_QUESTIONS_DRAG.TEXTBLOC = _e.textShow({
"id":this._questionsJeuManager.question.idLM,
"model":this.BLOC_QUESTIONS_DRAG.modelText,
"idStyle":"LM.LM_Q"
});
}
private function BLOC_QUESTION_Refresh() : void
{
this.BLOC_QUESTIONS.TEXTBLOC.text = this._questionsJeuManager.question.text;
this.BLOC_QUESTIONS.TEXTBLOC.x = this.BLOC_QUESTIONS.modelText.x + this.BLOC_QUESTIONS.modelText.width / 2 - this.BLOC_QUESTIONS.TEXTBLOC.width / 2;
this.BLOC_QUESTIONS.TEXTBLOC.y = this.BLOC_QUESTIONS.modelText.y + this.BLOC_QUESTIONS.modelText.height / 2 - this.BLOC_QUESTIONS.TEXTBLOC.height / 2;
}
private function createQuestionsListe() : void
{
var xmllist:XMLList = null;
var question:Question = null;
var node:XML = null;
this._questionsJeuManager = new Questions();
var questions:Vector.<Question> = new Vector.<Question>();
var i:int = 1;
while(i <= 20)
{
xmllist = _e.config.XmlConfig.Module[_e.config.lang].LegendesMedias.*.(hasOwnProperty("@id") && @id.search("LM_Q_" + GlobalesFunctions.gimme2digits(i)) != -1);
if(xmllist.length() <= 0)
{
break;
}
node = xmllist[0];
question = new Question();
question.no = i;
question.idLM = node.@id;
question.text = node.toString();
question.enerve = i <= 10 ? true : false;
this._questionsJeuManager.addQuestion(question);
i++;
}
this._questionOriginalList = this._questionsJeuManager.questions.slice();
}
private function onDrag(param1:Event) : void
{
this.CURSEUR.cursor = "mainF";
this._temp_point.x = this.CONTAINER.mouseX;
this._temp_point.y = this.CONTAINER.mouseY;
if(this._temp_point.x < this._zoneLimit.x + this.BLOC_QUESTIONS_DRAG.width / 2)
{
this._temp_point.x = this._zoneLimit.x + this.BLOC_QUESTIONS_DRAG.width / 2;
}
if(this._temp_point.x > this._zoneLimit.x + this._zoneLimit.width - this.BLOC_QUESTIONS_DRAG.width / 2)
{
this._temp_point.x = this._zoneLimit.x + this._zoneLimit.width - this.BLOC_QUESTIONS_DRAG.width / 2;
}
if(this._temp_point.y < this._zoneLimit.y + this.BLOC_QUESTIONS_DRAG.height / 2)
{
this._temp_point.y = this._zoneLimit.y + this.BLOC_QUESTIONS_DRAG.height / 2;
}
if(this._temp_point.y > this._zoneLimit.y + this._zoneLimit.height - this.BLOC_QUESTIONS_DRAG.height / 2)
{
this._temp_point.y = this._zoneLimit.y + this._zoneLimit.height - this.BLOC_QUESTIONS_DRAG.height / 2;
}
this.BLOC_QUESTIONS_DRAG.x = this.CURSEUR.x = this._temp_point.x;
this.BLOC_QUESTIONS_DRAG.y = this.CURSEUR.y = this._temp_point.y;
this.GeryonTouche = !!this.GERYON.hitTestPoint(this.CONTAINER.stage.mouseX,this.CONTAINER.stage.mouseY,true) ? true : false;
}
private function stopDrag(param1:Event) : void
{
this.CURSEUR.lock = false;
this.CURSEUR.cursor = "fleche";
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.onDrag);
this.CONTAINER.stage.removeEventListener(MouseEvent.MOUSE_UP,this.stopDrag);
this.BLOC_QUESTIONS_DRAG.removeFromParent(this.CONTAINER);
if(this.GeryonTouche)
{
if(this._questionsJeuManager.question.enerve)
{
this.jaugeChange(100 / 5);
this.commentSuccesA();
}
else
{
this.jaugeChange(-100 / 5);
this.commentEchecA();
}
}
else
{
_e.noisePlay({"code":"B_BACK"});
this.BT_FLECHE_DO.visible = true;
this.BT_FLECHE_UP.visible = true;
this.BLOC_QUESTIONS.visible = true;
}
}
private function commentSuccesA() : void
{
this.HERAKLES.gotoAndStop("E3");
this.GERYON.gotoAndStop("E5");
_e.commentPlay({
"code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_A",
"callback":this.commentSuccesB
});
}
private function commentSuccesB() : void
{
this.HERAKLES.gotoAndStop("E1");
this.GERYON.gotoAndStop("E6");
_e.commentPlay({
"code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_B",
"callback":this.commentSuccesC
});
}
private function commentSuccesC() : void
{
_e.commentPlay({
"code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_C",
"callback":this.commentFin
});
this.GERYON.gotoAndStop("E7");
this._questionsJeuManager.removeQuestion(this._questionsJeuManager.question);
}
private function commentEchecA() : void
{
this.GERYON.gotoAndStop("E2");
this.HERAKLES.gotoAndStop("E2");
_e.commentPlay({
"code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_A",
"callback":this.commentEchecB
});
}
private function commentEchecB() : void
{
this.GERYON.gotoAndStop("E3");
this.HERAKLES.gotoAndStop("E1");
_e.commentPlay({
"code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_B",
"callback":this.commentEchecC
});
}
private function commentEchecC() : void
{
this.GERYON.gotoAndStop("E4");
_e.commentPlay({
"code":"Q_" + GlobalesFunctions.gimme2digits(this._questionsJeuManager.question.no) + "_C",
"callback":this.commentFin
});
}
private function commentFin() : void
{
this.BLOC_QUESTION_Refresh();
this.GERYON.gotoAndStop("E1");
this.HERAKLES.gotoAndStop("E1");
if(this.jaugeValue >= 100)
{
this.end();
}
else if(this.nbBonnesReponsesRestantes() < (100 - this.jaugeValue) / 20)
{
this.echecJeu();
}
else
{
this.BT_FLECHE_DO.visible = true;
this.BT_FLECHE_UP.visible = true;
this.BLOC_QUESTIONS.visible = true;
}
}
private function echecJeu() : void
{
_e.commentPlay({
"code":"REJOUER",
"callback":function():void
{
BT_REJOUER.visible = true;
BT_REJOUER.enabled = true;
jaugeValue = 0;
jaugeChange(0);
}
});
}
private function nbBonnesReponsesRestantes() : int
{
var _loc1_:int = 0;
var _loc2_:int = 0;
while(_loc2_ < this._questionsJeuManager.questions.length)
{
if(this._questionsJeuManager.questions[_loc2_].enerve)
{
_loc1_++;
}
_loc2_++;
}
return _loc1_;
}
private function rejouer() : void
{
this.BT_REJOUER.visible = false;
this._questionsJeuManager.questions = this._questionOriginalList.slice();
this._questionsJeuManager.index = 0;
this._questionsJeuManager.melanger();
this.BLOC_QUESTION_Refresh();
this.BLOC_QUESTIONS.visible = true;
}
private function end() : void
{
this.destroy();
_e.instanceToDestroyRemove(this);
_callbackEnd();
}
public function destroy() : void
{
this.CONTAINER.stage.removeEventListener(Event.ENTER_FRAME,this.onDrag);
this.CONTAINER.stage.removeEventListener(MouseEvent.MOUSE_UP,this.stopDrag);
}
}
}