home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / Clusterz / Clusterz.swf / scripts / RES / WINDOWS / OWEnterName.as < prev    next >
Encoding:
Text File  |  2008-09-12  |  3.7 KB  |  142 lines

  1. package RES.WINDOWS
  2. {
  3.    import ENGINE.CORE.OUtils;
  4.    import ENGINE.INTERFACE.OButton;
  5.    import ENGINE.INTERFACE.ODialog;
  6.    import ENGINE.INTERFACE.OInput;
  7.    import flash.events.Event;
  8.    import flash.events.KeyboardEvent;
  9.    
  10.    public class OWEnterName extends ODialog
  11.    {
  12.        
  13.       
  14.       public var iCancel:OButton;
  15.       
  16.       private var iHasCancel:Boolean;
  17.       
  18.       public var iName:OInput;
  19.       
  20.       public var iAccept:OButton;
  21.       
  22.       public function OWEnterName(param1:Boolean = true)
  23.       {
  24.          this.iHasCancel = param1;
  25.          super(ClusterzL.OWEnterName);
  26.       }
  27.       
  28.       private function SetNameFocus() : void
  29.       {
  30.          if(!this.stage)
  31.          {
  32.             return;
  33.          }
  34.          if(this.stage.focus == this.iName.iText)
  35.          {
  36.             return;
  37.          }
  38.          this.iName.iText.setSelection(this.iName.iText.length,this.iName.iText.length);
  39.          this.stage.focus = this.iName.iText;
  40.       }
  41.       
  42.       override public function Init() : void
  43.       {
  44.          super.Init();
  45.          this.iName.prText = !!ClusterzL.iGAME.prPlayerName ? ClusterzL.iGAME.prPlayerName : "";
  46.          if(!this.iHasCancel)
  47.          {
  48.             this.iCancel.visible = false;
  49.             this.iAccept.prX = 155;
  50.          }
  51.          this.iName.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
  52.       }
  53.       
  54.       public function set prName(param1:String) : void
  55.       {
  56.          this.iName.prText = param1;
  57.       }
  58.       
  59.       override public function OnPress(param1:Event, param2:*) : void
  60.       {
  61.          var _loc3_:String = null;
  62.          var _loc4_:String = null;
  63.          if(!this.prMouseEnabled)
  64.          {
  65.             return;
  66.          }
  67.          if(param2 == this.iCancel)
  68.          {
  69.             if(!this.iCancel.visible)
  70.             {
  71.                return;
  72.             }
  73.             this.prVisible = false;
  74.             return;
  75.          }
  76.          if(param2 == this.iAccept)
  77.          {
  78.             _loc3_ = OUtils.ClearString(this.iName.prText.toUpperCase());
  79.             if((_loc4_ = removeSpaces(_loc3_)).length > 0)
  80.             {
  81.                ClusterzL.iGAME.prPlayerName = _loc4_;
  82.                this.prVisible = false;
  83.             }
  84.             else
  85.             {
  86.                this.iName.prText = "";
  87.             }
  88.          }
  89.       }
  90.       
  91.       override public function Free() : void
  92.       {
  93.          super.Free();
  94.          this.iName.removeEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
  95.          this.iName = null;
  96.          this.iAccept = null;
  97.          this.iCancel = null;
  98.       }
  99.       
  100.       public function get prName() : String
  101.       {
  102.          return this.iName.prText;
  103.       }
  104.       
  105.       override public function OnEnterFrame(param1:Event) : void
  106.       {
  107.          super.OnEnterFrame(param1);
  108.          SetNameFocus();
  109.       }
  110.       
  111.       private function removeSpaces(param1:String) : String
  112.       {
  113.          var _loc2_:String = null;
  114.          var _loc3_:int = 0;
  115.          _loc2_ = "";
  116.          _loc3_ = 0;
  117.          while(_loc3_ < param1.length)
  118.          {
  119.             if(param1.charAt(_loc3_) != " ")
  120.             {
  121.                _loc2_ += param1.charAt(_loc3_);
  122.             }
  123.             _loc3_++;
  124.          }
  125.          return _loc2_;
  126.       }
  127.       
  128.       private function keyHandler(param1:KeyboardEvent) : void
  129.       {
  130.          switch(param1.keyCode)
  131.          {
  132.             case 13:
  133.                OnPress(param1,this.iAccept);
  134.                break;
  135.             case 27:
  136.                OnPress(param1,this.iCancel);
  137.          }
  138.          trace(param1.target + "(" + param1.currentTarget + "): " + param1.keyCode + "/" + param1.charCode);
  139.       }
  140.    }
  141. }
  142.