home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / Clusterz / Clusterz.swf / scripts / ENGINE / INTERFACE / OApplication.as < prev    next >
Encoding:
Text File  |  2008-09-12  |  4.1 KB  |  146 lines

  1. package ENGINE.INTERFACE
  2. {
  3.    import ENGINE.CORE.OGlobal;
  4.    import flash.display.Stage;
  5.    import flash.display.StageAlign;
  6.    import flash.display.StageQuality;
  7.    import flash.display.StageScaleMode;
  8.    import flash.events.Event;
  9.    import flash.external.ExternalInterface;
  10.    
  11.    public class OApplication extends OWindow
  12.    {
  13.        
  14.       
  15.       private var iStaged:Boolean = false;
  16.       
  17.       protected var iBackground:OBackground;
  18.       
  19.       protected var iMenuItem:Array;
  20.       
  21.       public function OApplication(param1:String)
  22.       {
  23.          iStaged = false;
  24.          OGlobal.AppName = param1;
  25.          if(this.stage)
  26.          {
  27.             OGlobal.SetDomain();
  28.             this.InitStage();
  29.          }
  30.          super(null);
  31.          if(!this.iStaged)
  32.          {
  33.             this.addEventListener(Event.ENTER_FRAME,NotStagedEnterFrame);
  34.          }
  35.       }
  36.       
  37.       override public function Init() : void
  38.       {
  39.          if(!this.stage)
  40.          {
  41.             return;
  42.          }
  43.          super.Init();
  44.          this.iMenuItem = new Array();
  45.          this.iStaged = true;
  46.          this.visible = true;
  47.       }
  48.       
  49.       protected function OnMenuItem() : void
  50.       {
  51.       }
  52.       
  53.       public function get prMenuItem() : int
  54.       {
  55.          return !!this.iMenuItem.length ? this.iMenuItem.pop() : -1;
  56.       }
  57.       
  58.       private function NotStagedEnterFrame(param1:Event) : void
  59.       {
  60.          if(!iStaged)
  61.          {
  62.             if(!this.stage)
  63.             {
  64.                return;
  65.             }
  66.             OGlobal.SetDomain();
  67.             this.InitStage();
  68.             this.Init();
  69.             this.removeEventListener(Event.ENTER_FRAME,NotStagedEnterFrame);
  70.             this.iStaged = true;
  71.          }
  72.       }
  73.       
  74.       public function set prMenuItem(param1:int) : void
  75.       {
  76.          this.iMenuItem.push(param1);
  77.       }
  78.       
  79.       override public function Free() : void
  80.       {
  81.          OGlobal.prStage.removeEventListener(Event.DEACTIVATE,OnDeactivate);
  82.          OGlobal.prStage.removeEventListener(Event.RESIZE,OnResize);
  83.          this.iMenuItem = null;
  84.          super.Free();
  85.       }
  86.       
  87.       public function InitStage(param1:Stage = null) : void
  88.       {
  89.          var s:String = null;
  90.          var b:int = 0;
  91.          var aStage:Stage = param1;
  92.          if(Boolean(aStage) || Boolean(this.stage))
  93.          {
  94.             OGlobal.prStage = !!aStage ? aStage : this.stage;
  95.          }
  96.          if(!OGlobal.prStage)
  97.          {
  98.             return;
  99.          }
  100.          OGlobal.prStage.scaleMode = StageScaleMode.NO_SCALE;
  101.          OGlobal.prStage.align = StageAlign.TOP_LEFT;
  102.          OGlobal.prStage.quality = StageQuality.BEST;
  103.          OGlobal.prStage.stageFocusRect = false;
  104.          OGlobal.Rescale(this);
  105.          OGlobal.FPS = 60;
  106.          if(ExternalInterface.available)
  107.          {
  108.             s = "function getInternetExplorerVersion() { var rv = -1; if (navigator.appName == \"Microsoft Internet Explorer\") { var ua = navigator.userAgent;" + "var re  = new RegExp(\"MSIE ([0-9]{1,}[.0-9]{0,})\"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; }";
  109.             b = 0;
  110.             try
  111.             {
  112.                b = ExternalInterface.call(s);
  113.             }
  114.             catch(e:Error)
  115.             {
  116.                OGlobal.prStage.frameRate = OGlobal.FPS;
  117.             }
  118.             if(b > 0)
  119.             {
  120.                OGlobal.FPS *= 2;
  121.             }
  122.          }
  123.          OGlobal.prStage.frameRate = OGlobal.FPS;
  124.          OGlobal.prStage.addEventListener(Event.RESIZE,OnResize);
  125.          OGlobal.prStage.addEventListener(Event.DEACTIVATE,OnDeactivate);
  126.       }
  127.       
  128.       public function OnResize(param1:Event) : void
  129.       {
  130.          this.Free();
  131.          this.InitStage();
  132.          this.Init();
  133.       }
  134.       
  135.       public function InitBackground(param1:Array, param2:int = 0) : void
  136.       {
  137.          this.iBackground = new OBackground(param1,param2);
  138.          this.addChildAt(this.iBackground,0);
  139.       }
  140.       
  141.       protected function OnDeactivate(param1:Event) : void
  142.       {
  143.       }
  144.    }
  145. }
  146.