home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 145 / MOBICLIC145.ISO / pc / DATA / BLA145 / BLA145_01 / BLA145_01.swf / scripts / bla145_01 / CapsuleAlgo.as
Text File  |  2012-07-18  |  10KB  |  279 lines

  1. package bla145_01
  2. {
  3.    import com.milanpresse.engine.Engine;
  4.    import com.milanpresse.engine.initmovieclip.InteractiveMovie;
  5.    import com.milanpresse.engine.managers.PauseManager;
  6.    import com.milanpresse.engine.managers.TimelineManager;
  7.    import com.milanpresse.engine.medias.MediaSwf;
  8.    import com.milanpresse.engine.timelines.Timeline;
  9.    import com.milanpresse.engine.typeargument.NoiseObject;
  10.    import com.milanpresse.tools.GlobalesFunctions;
  11.    import flash.display.MovieClip;
  12.    import flash.events.Event;
  13.    import flash.geom.Point;
  14.    import flash.ui.Mouse;
  15.    
  16.    public class CapsuleAlgo
  17.    {
  18.        
  19.       
  20.       private var menu:MediaSwf;
  21.       
  22.       private var menuTimeline:MovieClip;
  23.       
  24.       private var menuTL:Timeline;
  25.       
  26.       private var mainClip:MediaSwf;
  27.       
  28.       private var mainTimeline:MovieClip;
  29.       
  30.       private var _engine:Engine;
  31.       
  32.       private var labelList:Array;
  33.       
  34.       private var _timeline_:Timeline;
  35.       
  36.       private var _timelineManager:TimelineManager;
  37.       
  38.       private var _pauseManager:PauseManager;
  39.       
  40.       private var firstLabel:String = "_01";
  41.       
  42.       private var gSon:int = 1;
  43.       
  44.       private var gOutilBLA:int;
  45.       
  46.       private var gTypeINTER:int;
  47.       
  48.       private var outil:MovieClip;
  49.       
  50.       public function CapsuleAlgo(engine:Engine)
  51.       {
  52.          super();
  53.          this._engine = engine;
  54.          trace("   ",this._engine.host.subtitlesOn);
  55.          this._engine.setSubtitles(this._engine.host.subtitlesOn);
  56.          this._engine.setFrameRate(12);
  57.          this.mainClip = this._engine.showSwf({
  58.             "code":"A_" + this._engine.config.moduleName,
  59.             "parent":this._engine.config.layers["content"]
  60.          });
  61.          this.mainTimeline = this.mainClip.swfContent;
  62.          this._timelineManager = new TimelineManager();
  63.          this._timeline_ = new Timeline(this.mainTimeline,this._timelineManager);
  64.          this._engine.levelCZ = this._engine.config.layers["content"];
  65.          this.gOutilBLA = Number(this._engine.config.XmlConfig.Module.Config.OUTIL.toString());
  66.          this.gTypeINTER = Number(this._engine.config.XmlConfig.Module.Config.INTERACTIVITE.toString());
  67.          this._timeline_.GotoAndPlay(2);
  68.          this.mainTimeline.addEventListener(Event.FRAME_CONSTRUCTED,this.frameContructedListener);
  69.          trace("gOutilBLA",this.gOutilBLA);
  70.          var BT_FERMER:InteractiveMovie = new InteractiveMovie(this.mainTimeline.BT_FERMER,this._timelineManager);
  71.          BT_FERMER.mc.onPress = function():void
  72.          {
  73.             endMODULE();
  74.          };
  75.          BT_FERMER.activeMC();
  76.       }
  77.       
  78.       public function frameContructedListener(evt:Event) : void
  79.       {
  80.          if(this.mainTimeline.currentFrameLabel !== null)
  81.          {
  82.             if(this.mainTimeline.currentFrameLabel == "ATTENTE")
  83.             {
  84.                this.labelATTENTE();
  85.             }
  86.             else if(this.mainTimeline.currentFrameLabel.substr(3,3) == "fin")
  87.             {
  88.                this.masqueST();
  89.             }
  90.             else
  91.             {
  92.                this.afficheST();
  93.             }
  94.          }
  95.       }
  96.       
  97.       public function afficheST() : void
  98.       {
  99.          this._engine.config.subtitlesBloc.showByCommentID(this._engine.config.commentName + this.mainTimeline.currentFrameLabel.substr(1,2));
  100.          this.gSon += 1;
  101.       }
  102.       
  103.       public function masqueST() : void
  104.       {
  105.          this._engine.config.subtitlesBloc.hide();
  106.          var pNextLabel:int = this.getNextLabel();
  107.          if(pNextLabel == -1)
  108.          {
  109.             this.mainTimeline.removeEventListener(Event.FRAME_CONSTRUCTED,this.frameContructedListener);
  110.             this._timeline_.GotoAndPlayUntilTheEnd(this.mainTimeline.currentFrame + 1,this.endMODULE);
  111.          }
  112.       }
  113.       
  114.       public function getNextLabel() : int
  115.       {
  116.          var pos:int = this._timeline_.getPosFrameLabelByName(this.mainTimeline,this.mainTimeline.currentLabel);
  117.          if(pos < this.mainTimeline.currentLabels.length - 1)
  118.          {
  119.             return this.mainTimeline.currentLabels[pos + 1].frame;
  120.          }
  121.          return -1;
  122.       }
  123.       
  124.       public function labelATTENTE() : void
  125.       {
  126.          trace("labelATTENTE");
  127.          this.mainTimeline.removeEventListener(Event.FRAME_CONSTRUCTED,this.frameContructedListener);
  128.          this._timeline_.Stop();
  129.          this._engine.playNoise(new NoiseObject({"code":"B_ZONE"}));
  130.          var myMc:InteractiveMovie = new InteractiveMovie(this.mainTimeline.zone,this._timelineManager);
  131.          this.outil = this._engine.showSwf({
  132.             "code":"OUTIL_" + this.G2D(this.gOutilBLA),
  133.             "parent":this._engine.config.layers["content"]
  134.          }).swfContent;
  135.          this.outil.mouseEnabled = false;
  136.          this.outil.mouseChildren = false;
  137.          this.outil.visible = false;
  138.          myMc.mc.pNoiseRoll = "B_Z_" + this.G2D(this.gOutilBLA);
  139.          this.initMC(myMc);
  140.       }
  141.       
  142.       public function initMC(myMc:InteractiveMovie) : void
  143.       {
  144.          myMc.mc.onRollOver = function():void
  145.          {
  146.             _engine.playNoise(new NoiseObject({"code":this.pNoiseRoll}));
  147.             Mouse.hide();
  148.             var point:Point = new Point(this.parent.mouseX + 400,this.parent.mouseY + 300);
  149.             outil.ref = this;
  150.             outil.x = point.x;
  151.             outil.y = point.y;
  152.             outil.enterFrame = function(evt:Event):void
  153.             {
  154.                var point:Point = null;
  155.                if(evt.target.visible == true)
  156.                {
  157.                   point = new Point(outil.ref.parent.mouseX + 400,outil.ref.parent.mouseY + 300);
  158.                   outil.x = point.x;
  159.                   outil.y = point.y;
  160.                }
  161.             };
  162.             outil.addEventListener(Event.ENTER_FRAME,outil.enterFrame);
  163.             outil.visible = true;
  164.          };
  165.          myMc.mc.onRollOut = function():void
  166.          {
  167.             Mouse.show();
  168.             outil.visible = false;
  169.             _engine.stopNoise(new NoiseObject({"code":"B_Z_" + G2D(gOutilBLA)}));
  170.          };
  171.          myMc.mc.onMouseDown = function():void
  172.          {
  173.             this.gDownXY = new Point(this.parent.mouseX + 400,this.parent.mouseY + 300);
  174.          };
  175.          myMc.mc.onMouseUp = function():void
  176.          {
  177.             _engine.stopNoise(new NoiseObject({"code":"B_Z_" + G2D(gOutilBLA)}));
  178.             var point:Point = new Point(this.parent.mouseX + 400,this.parent.mouseY + 300);
  179.             switch(gTypeINTER)
  180.             {
  181.                case 1:
  182.                   this.onValide();
  183.                   break;
  184.                case 2:
  185.                   if(point.y > this.gDownXY.y)
  186.                   {
  187.                      this.onValide();
  188.                   }
  189.                   else
  190.                   {
  191.                      this.returnOrigPoint();
  192.                   }
  193.                   break;
  194.                case 3:
  195.                   if(point.y < this.gDownXY.y)
  196.                   {
  197.                      this.onValide();
  198.                   }
  199.                   else
  200.                   {
  201.                      this.returnOrigPoint();
  202.                   }
  203.                   break;
  204.                case 4:
  205.                   if(point.x > this.gDownXY.x)
  206.                   {
  207.                      this.onValide();
  208.                   }
  209.                   else
  210.                   {
  211.                      this.returnOrigPoint();
  212.                   }
  213.                   break;
  214.                case 5:
  215.                   if(point.x < this.gDownXY.x)
  216.                   {
  217.                      this.onValide();
  218.                   }
  219.                   else
  220.                   {
  221.                      this.returnOrigPoint();
  222.                   }
  223.                   break;
  224.                case 6:
  225.                   if(point.x !== this.gDownXY.x && point.y !== this.gDownXY.y)
  226.                   {
  227.                      this.onValide();
  228.                   }
  229.                   else
  230.                   {
  231.                      this.returnOrigPoint();
  232.                   }
  233.             }
  234.             this.gDown = undefined;
  235.          };
  236.          myMc.mc.onValide = function():void
  237.          {
  238.             Mouse.show();
  239.             outil.visible = false;
  240.             outil.removeEventListener(Event.ENTER_FRAME,outil.enterFrame);
  241.             this.useHandCursor = false;
  242.             myMc.kill();
  243.             mainTimeline.addEventListener(Event.FRAME_CONSTRUCTED,frameContructedListener);
  244.             _timeline_.GotoAndPlay(mainTimeline.currentFrame + 1);
  245.          };
  246.          myMc.activeDragAndDropMC();
  247.       }
  248.       
  249.       public function G2D(value:int) : String
  250.       {
  251.          return GlobalesFunctions.gimme2digits(value);
  252.       }
  253.       
  254.       public function endMODULE() : void
  255.       {
  256.          trace("fin du module");
  257.          this._engine.host.changeModule({"numMod":0});
  258.       }
  259.       
  260.       public function sleep() : void
  261.       {
  262.          this._pauseManager = new PauseManager(this._engine,this._timelineManager);
  263.          this._pauseManager.sleepMovie(this.mainTimeline);
  264.       }
  265.       
  266.       public function wake() : void
  267.       {
  268.          this._pauseManager.wakeMovie(this.mainTimeline);
  269.       }
  270.       
  271.       public function destroy() : void
  272.       {
  273.          this.mainTimeline.removeEventListener(Event.FRAME_CONSTRUCTED,this.frameContructedListener);
  274.          this._engine.stopAllSounds();
  275.          this._timeline_.kilListeners();
  276.       }
  277.    }
  278. }
  279.