home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Adobe AIR 1.5.1 / AdobeAIRInstaller.exe / setup.swf / scripts / components / LocalizedButton.as < prev    next >
Encoding:
Text File  |  2009-02-12  |  5.0 KB  |  175 lines

  1. package components
  2. {
  3.    import flash.text.Font;
  4.    import mx.controls.Button;
  5.    import mx.events.PropertyChangeEvent;
  6.    import mx.styles.StyleManager;
  7.    
  8.    public class LocalizedButton extends Button
  9.    {
  10.       private static var fontArray:Array = Font.enumerateFonts(false);
  11.       
  12.       private var isFontRetrieved:Boolean = false;
  13.       
  14.       private var defaultAppFontFamily:String;
  15.       
  16.       private var _resourceName:String;
  17.       
  18.       private var _resourceParams:Array;
  19.       
  20.       private var _bundleName:String;
  21.       
  22.       private var _useHTML:Boolean = false;
  23.       
  24.       private var cachedEmbeddedFont:Font;
  25.       
  26.       public function LocalizedButton()
  27.       {
  28.          super();
  29.       }
  30.       
  31.       private function set _143661260resourceParams(param1:Array) : void
  32.       {
  33.          trace(this.id + " set resourceName: " + this.resourceName);
  34.          this._resourceParams = param1;
  35.          invalidateProperties();
  36.       }
  37.       
  38.       [Bindable(event="propertyChange")]
  39.       public function set resourceName(param1:String) : void
  40.       {
  41.          var _loc2_:Object = this.resourceName;
  42.          if(_loc2_ !== param1)
  43.          {
  44.             this._384566343resourceName = param1;
  45.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"resourceName",_loc2_,param1));
  46.          }
  47.       }
  48.       
  49.       override protected function commitProperties() : void
  50.       {
  51.          if(this.resourceName)
  52.          {
  53.             label = this.localizeText();
  54.          }
  55.          super.commitProperties();
  56.       }
  57.       
  58.       private function set _384566343resourceName(param1:String) : void
  59.       {
  60.          this._resourceName = param1;
  61.          invalidateProperties();
  62.       }
  63.       
  64.       private function set _1377046061bundleName(param1:String) : void
  65.       {
  66.          this._bundleName = param1;
  67.          invalidateProperties();
  68.       }
  69.       
  70.       protected function localizeText() : String
  71.       {
  72.          return LocalizationManager.getInstance().getString(this.resourceName,this.bundleName,this.resourceParams);
  73.       }
  74.       
  75.       override public function initialize() : void
  76.       {
  77.          super.initialize();
  78.       }
  79.       
  80.       [Bindable(event="propertyChange")]
  81.       public function set bundleName(param1:String) : void
  82.       {
  83.          var _loc2_:Object = this.bundleName;
  84.          if(_loc2_ !== param1)
  85.          {
  86.             this._1377046061bundleName = param1;
  87.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"bundleName",_loc2_,param1));
  88.          }
  89.       }
  90.       
  91.       [Bindable(event="propertyChange")]
  92.       public function set useHTML(param1:Boolean) : void
  93.       {
  94.          var _loc2_:Object = this.useHTML;
  95.          if(_loc2_ !== param1)
  96.          {
  97.             this._148395598useHTML = param1;
  98.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"useHTML",_loc2_,param1));
  99.          }
  100.       }
  101.       
  102.       protected function ensureGlyphs(param1:String) : void
  103.       {
  104.          var _loc2_:String = null;
  105.          var _loc3_:Font = null;
  106.          if(!this.isFontRetrieved)
  107.          {
  108.             this.isFontRetrieved = true;
  109.             _loc2_ = getStyle("fontFamily");
  110.             if(_loc2_.match(/,/))
  111.             {
  112.                return;
  113.             }
  114.             for each(_loc3_ in fontArray)
  115.             {
  116.                if(_loc3_.fontName == _loc2_)
  117.                {
  118.                   this.cachedEmbeddedFont = _loc3_;
  119.                   this.defaultAppFontFamily = StyleManager.getStyleDeclaration("Application").getStyle("fontFamily");
  120.                }
  121.             }
  122.          }
  123.          if(this.cachedEmbeddedFont)
  124.          {
  125.             if(!this.cachedEmbeddedFont.hasGlyphs(param1))
  126.             {
  127.                setStyle("fontFamily",this.defaultAppFontFamily);
  128.             }
  129.             else
  130.             {
  131.                setStyle("fontFamily",this.cachedEmbeddedFont.fontName);
  132.             }
  133.          }
  134.       }
  135.       
  136.       [Bindable(event="propertyChange")]
  137.       public function set resourceParams(param1:Array) : void
  138.       {
  139.          var _loc2_:Object = this.resourceParams;
  140.          if(_loc2_ !== param1)
  141.          {
  142.             this._143661260resourceParams = param1;
  143.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"resourceParams",_loc2_,param1));
  144.          }
  145.       }
  146.       
  147.       private function set _148395598useHTML(param1:Boolean) : void
  148.       {
  149.          this._useHTML = param1;
  150.          invalidateProperties();
  151.       }
  152.       
  153.       public function get useHTML() : Boolean
  154.       {
  155.          return this._useHTML;
  156.       }
  157.       
  158.       public function get resourceParams() : Array
  159.       {
  160.          return this._resourceParams;
  161.       }
  162.       
  163.       public function get resourceName() : String
  164.       {
  165.          return this._resourceName;
  166.       }
  167.       
  168.       public function get bundleName() : String
  169.       {
  170.          return this._bundleName;
  171.       }
  172.    }
  173. }
  174.  
  175.