- コミット日時:
- 2009/04/10 12:08:14 (3 年前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/Eseclock/branches/alumican/src/org/libspark/eseclock/object/ClockSprite.as
r2430 r2440 35 35 import flash.text.TextFormat; 36 36 import flash.utils.getDefinitionByName; 37 import org.libspark.eseclock.textfield.EseclockDefaultTextField; 37 38 import org.libspark.eseclock.textfield.EseclockDefaultClockTextField; 39 import org.libspark.eseclock.textfield.EseclockDefaultDescriptionTextField; 38 40 import org.libspark.eseclock.textfield.IEseclockTextField; 39 41 … … 62 64 private var _leading:Number; 63 65 66 //テキストが空文字列以外の場合はtrue 67 private var _hasDescription:Boolean; 68 69 64 70 65 71 … … 69 75 //------------------------------------- 70 76 71 //時計の下に表示するテキスト72 public function get description():String { return _sub.description; }73 public function set description(value:String):void { updateDescription(value); }74 75 77 //テキスト色 76 public function get textColor():uint { return _field.defaultTextFormat.color as uint; }77 78 public function set textColor(value:uint):void { 78 79 _changeTextColor(_field, value); … … 81 82 82 83 //背景色 83 public function get backgroundColor():uint { return _backgroundColor; }84 84 public function set backgroundColor(value:uint):void { _drawBackground(value); } 85 85 … … 128 128 private function _createFields(color:uint, clockAsset:String = "", subAsset:String = ""):void 129 129 { 130 var fmt:TextFormat; 131 132 fmt = (clockAsset == "") ? new TextFormat("Arial Black", 96, color, true) : new TextFormat(null, null, color); 133 _field = _createField(clockAsset, fmt); 134 _field.update(99, 99, 99); 135 136 fmt = (subAsset == "") ? new TextFormat("Arial Black", 36, color, true) : new TextFormat(null, null, color); 137 _sub = _createField(subAsset, fmt); 138 description = "TOKYO / JAPAN"; 130 _field = _createField(clockAsset, EseclockDefaultClockTextField); 131 _field.setColor(color); 132 _field.updateClock(99, 99, 99); 133 134 _masked.addChild(_field as DisplayObject); 135 136 137 _sub = _createField(subAsset, EseclockDefaultDescriptionTextField); 138 _sub.setColor(color); 139 _sub.updateDescription("TOKYO / JAPAN"); 140 141 _masked.addChild(_sub as DisplayObject); 142 139 143 140 144 //中央揃え … … 144 148 /** 145 149 * 各テキストフィールドを生成する関数 146 * @param tf147 150 * @param asset 148 * @param fmt149 */ 150 private function _createField(asset:String, fmt:TextFormat):IEseclockTextField {151 * @param defaultClass 152 */ 153 private function _createField(asset:String, defaultClass:Class):IEseclockTextField { 151 154 var tf:IEseclockTextField; 152 155 153 156 if (asset == "") { 154 tf = new EseclockDefaultTextField();157 tf = new defaultClass() as IEseclockTextField; 155 158 } else { 156 159 var fieldClass:Class = getDefinitionByName(asset) as Class; … … 158 161 } 159 162 160 tf.defaultTextFormat = fmt;161 tf.selectable = false;162 tf.autoSize = TextFieldAutoSize.LEFT;163 _masked.addChild(tf as DisplayObject);164 165 163 return tf; 166 164 } … … 172 170 public function updateDescription(description:String):void 173 171 { 174 _sub.description = description; 172 _hasDescription = (description != "") ? true : false; 173 174 _sub.updateDescription(description); 175 175 176 176 //中央揃え … … 186 186 public function updateField(h:uint, m:uint, s:uint):void 187 187 { 188 _field.update (h, m, s);188 _field.updateClock(h, m, s); 189 189 } 190 190 191 191 /** 192 192 * テキストフィールドの色を変更する関数 193 * @param t extFieldターゲット193 * @param tf ターゲット 194 194 * @param color 色 195 195 */ 196 private function _changeTextColor(textField:IEseclockTextField, color:uint):void 197 { 198 var fmt:TextFormat = textField.defaultTextFormat; 199 fmt.color = color; 200 textField.defaultTextFormat = fmt; 201 textField.setTextFormat(fmt); 196 private function _changeTextColor(tf:IEseclockTextField, color:uint):void 197 { 198 tf.setColor(color); 202 199 } 203 200 … … 212 209 213 210 //テキストフィールドの中央揃え 214 var margin:int = ( description.length > 0) ? _leading : 0;215 var totalHeight:uint = _field. textHeight + _sub.textHeight;216 217 _field.x = (_w - _field. textWidth) / 2;218 _field.y = (_h - totalHeight ) / 2;219 220 _sub.x = (_w - _sub. textWidth) / 2;221 _sub.y = (_h - totalHeight ) / 2 + _field.textHeight + margin;211 var margin:int = (_hasDescription) ? _leading : 0; 212 var totalHeight:uint = _field.objectHeight + _sub.objectHeight; 213 214 _field.x = (_w - _field.objectWidth) / 2; 215 _field.y = (_h - totalHeight ) / 2; 216 217 _sub.x = (_w - _sub.objectWidth) / 2; 218 _sub.y = (_h - totalHeight ) / 2 + _field.objectHeight + margin; 222 219 } 223 220 }

