| 1 |
/** |
|---|
| 2 |
* Licensed under the MIT License |
|---|
| 3 |
* |
|---|
| 4 |
* Copyright (c) 2008 BeInteractive! (www.be-interactive.org) and |
|---|
| 5 |
* 2009 alumican.net (www.alumican.net) and |
|---|
| 6 |
* Spark project (www.libspark.org) |
|---|
| 7 |
* |
|---|
| 8 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 9 |
* of this software and associated documentation files (the "Software"), to deal |
|---|
| 10 |
* in the Software without restriction, including without limitation the rights |
|---|
| 11 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 12 |
* copies of the Software, and to permit persons to whom the Software is |
|---|
| 13 |
* furnished to do so, subject to the following conditions: |
|---|
| 14 |
* |
|---|
| 15 |
* The above copyright notice and this permission notice shall be included in |
|---|
| 16 |
* all copies or substantial portions of the Software. |
|---|
| 17 |
* |
|---|
| 18 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 19 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 20 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 21 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 22 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 23 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 24 |
* THE SOFTWARE. |
|---|
| 25 |
*/ |
|---|
| 26 |
package org.libspark.eseclock |
|---|
| 27 |
{ |
|---|
| 28 |
import flash.display.DisplayObject; |
|---|
| 29 |
import flash.display.Shape; |
|---|
| 30 |
import flash.display.Sprite; |
|---|
| 31 |
import flash.display.StageAlign; |
|---|
| 32 |
import flash.display.StageScaleMode; |
|---|
| 33 |
import flash.events.Event; |
|---|
| 34 |
import flash.text.TextField; |
|---|
| 35 |
import org.libspark.eseclock.object.ClockSprite; |
|---|
| 36 |
import org.libspark.eseclock.object.ContentSprite; |
|---|
| 37 |
import org.libspark.eseclock.object.TweenMaskSprite; |
|---|
| 38 |
|
|---|
| 39 |
/** |
|---|
| 40 |
* Eseclockアニメーション付きバージョン |
|---|
| 41 |
* |
|---|
| 42 |
****************************************** |
|---|
| 43 |
* |
|---|
| 44 |
* これはなに? |
|---|
| 45 |
* - UNIQLOCKっぽい何かが作れるライブラリです |
|---|
| 46 |
* - yossy:beinteractive氏によるオリジナルバージョンを改造しています |
|---|
| 47 |
* |
|---|
| 48 |
* @author yossy:beinteractive |
|---|
| 49 |
* @link http://www.libspark.org/wiki/Eseclock |
|---|
| 50 |
* @link http://www.libspark.org/ |
|---|
| 51 |
* |
|---|
| 52 |
****************************************** |
|---|
| 53 |
* |
|---|
| 54 |
* 改造してるひと |
|---|
| 55 |
* - alumican.net |
|---|
| 56 |
* |
|---|
| 57 |
* @author alumican.net |
|---|
| 58 |
* @link http://alumican.net |
|---|
| 59 |
* |
|---|
| 60 |
****************************************** |
|---|
| 61 |
* |
|---|
| 62 |
* つかいかた |
|---|
| 63 |
* - ステージにaddChildして使います |
|---|
| 64 |
* - コンストラクタには以下のパラメータを渡せます |
|---|
| 65 |
* 第1引数 color1:uint = 0x000000 色1 |
|---|
| 66 |
* 第2引数 color2:uint = 0xffffff 色2 |
|---|
| 67 |
* 第3引数 w:Number = 640 Eseclockの幅 |
|---|
| 68 |
* 第4引数 h:Number = 320 Eseclockの高さ |
|---|
| 69 |
* 第5引数 autoScaleToStage:Boolean = true trueの場合は自動でステージにフィットする |
|---|
| 70 |
* 第6引数 autoPlay:Boolean = true trueの場合はaddChildと同時にスタートする. falseの場合はstartメソッドを呼び出すことスタートする |
|---|
| 71 |
* 第7引数 leading:Number = 0 時計と下のテキストとの間隔 |
|---|
| 72 |
* 第7引数 leading:Number = 0 時計と下のテキストとの間隔 |
|---|
| 73 |
* 第8引数 textFieldAsset1:String = "" 時計表示用に用いるクラス名(IEseclockTextFieldを実装する必要がある) |
|---|
| 74 |
* 第9引数 textFieldAsset2:String = "" 時計の下のテキストに用いるクラス名(IEseclockTextFieldを実装する必要がある) |
|---|
| 75 |
* |
|---|
| 76 |
* - こんな感じのコードになります |
|---|
| 77 |
* - MyEseclockはEseclockを継承し, createContentメソッド及びresizeContentメソッドを適宜オーバーライドしています |
|---|
| 78 |
* |
|---|
| 79 |
* var clock:MyEseclock = new MyEseclock(); |
|---|
| 80 |
* addChild(clock); |
|---|
| 81 |
* |
|---|
| 82 |
* clock.w = 800; |
|---|
| 83 |
* clock.h = 600; |
|---|
| 84 |
* clock.description = "TOKYO / JAPAN"; |
|---|
| 85 |
* |
|---|
| 86 |
****************************************** |
|---|
| 87 |
* |
|---|
| 88 |
* ライセンス |
|---|
| 89 |
* - MITライセンスです |
|---|
| 90 |
*/ |
|---|
| 91 |
|
|---|
| 92 |
public class Eseclock extends Sprite |
|---|
| 93 |
{ |
|---|
| 94 |
//-------------------------------------------------------------------------- |
|---|
| 95 |
// COLORS |
|---|
| 96 |
// |
|---|
| 97 |
// 色を取得/設定します |
|---|
| 98 |
//-------------------------------------------------------------------------- |
|---|
| 99 |
|
|---|
| 100 |
private var _color1:uint; |
|---|
| 101 |
private var _color2:uint; |
|---|
| 102 |
|
|---|
| 103 |
public function get color1():uint { return _color1; } |
|---|
| 104 |
public function get color2():uint { return _color2; } |
|---|
| 105 |
public function set color1(value:uint):void { _color1 = value; _coloring1(); } |
|---|
| 106 |
public function set color2(value:uint):void { _color2 = value; _coloring2(); } |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
//-------------------------------------------------------------------------- |
|---|
| 113 |
// SIZE |
|---|
| 114 |
// |
|---|
| 115 |
// Eseclockのサイズを取得/設定します |
|---|
| 116 |
//-------------------------------------------------------------------------- |
|---|
| 117 |
|
|---|
| 118 |
private var _w:Number; |
|---|
| 119 |
private var _h:Number; |
|---|
| 120 |
|
|---|
| 121 |
public function get w():Number { return _w; } |
|---|
| 122 |
public function get h():Number { return _h; } |
|---|
| 123 |
public function set w(value:Number):void { if (value != _w) { _w = value; _resize(); } } |
|---|
| 124 |
public function set h(value:Number):void { if (value != _h) { _h = value; _resize(); } } |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
//-------------------------------------------------------------------------- |
|---|
| 131 |
// SCALE TO STAGE |
|---|
| 132 |
// |
|---|
| 133 |
// trueの場合, Eseclockのサイズをステージにフィットさせます |
|---|
| 134 |
//-------------------------------------------------------------------------- |
|---|
| 135 |
|
|---|
| 136 |
private var _autoScaleToStage:Boolean; |
|---|
| 137 |
|
|---|
| 138 |
public function get autoScaleToStage():Boolean { return _autoScaleToStage; } |
|---|
| 139 |
public function set autoScaleToStage(value:Boolean):void { |
|---|
| 140 |
if (value != _autoScaleToStage) { |
|---|
| 141 |
_autoScaleToStage = value; |
|---|
| 142 |
_resize(); |
|---|
| 143 |
} |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
//-------------------------------------------------------------------------- |
|---|
| 151 |
// CLOCK DESCRIPTION |
|---|
| 152 |
// |
|---|
| 153 |
// 時計の下に表示するテキストを取得/設定します |
|---|
| 154 |
//-------------------------------------------------------------------------- |
|---|
| 155 |
|
|---|
| 156 |
public function get description():String { return _description; } |
|---|
| 157 |
public function set description(value:String):void |
|---|
| 158 |
{ |
|---|
| 159 |
_description = value; |
|---|
| 160 |
_clock1.updateDescription(value); |
|---|
| 161 |
_clock2.updateDescription(value); |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
private var _description:String = "TOKYO / JAPAN"; |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
//-------------------------------------------------------------------------- |
|---|
| 171 |
// GET SHOWING CONTENT |
|---|
| 172 |
// |
|---|
| 173 |
// 表示中のコンテンツを取得します |
|---|
| 174 |
//-------------------------------------------------------------------------- |
|---|
| 175 |
|
|---|
| 176 |
public function get content():DisplayObject { return _contentContainer.content; } |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
//-------------------------------------------------------------------------- |
|---|
| 183 |
// CREATE CONTENT METHOD |
|---|
| 184 |
// |
|---|
| 185 |
// 時計の合間に表示するコンテンツを設定します |
|---|
| 186 |
// |
|---|
| 187 |
// _createContentメソッドをオーバーライドするか, createContentに関数を代入します. |
|---|
| 188 |
//-------------------------------------------------------------------------- |
|---|
| 189 |
|
|---|
| 190 |
private var __createContent:Function; |
|---|
| 191 |
|
|---|
| 192 |
//Setter経由で設定している場合は, オーバーライドされた関数を実行しません |
|---|
| 193 |
public function get createContent():Function { return __createContent || _createContent; } |
|---|
| 194 |
public function set createContent(value:Function):void { __createContent = value; } |
|---|
| 195 |
|
|---|
| 196 |
/** |
|---|
| 197 |
* 時計の合間に表示するコンテンツのインスタンスを生成する関数(オーバーライド用) |
|---|
| 198 |
* @param w Eseclockの幅 |
|---|
| 199 |
* @param h Eseclockの高さ |
|---|
| 200 |
* @return 時計の合間に表示するコンテンツ |
|---|
| 201 |
*/ |
|---|
| 202 |
protected function _createContent(w:Number, h:Number):DisplayObject |
|---|
| 203 |
{ |
|---|
| 204 |
var sprite:Sprite = new Sprite(); |
|---|
| 205 |
sprite.graphics.clear(); |
|---|
| 206 |
for (var i:uint = 0; i < 40; ++i) { |
|---|
| 207 |
sprite.graphics.beginFill(Math.floor(Math.random() * 256), Math.random() * 100); |
|---|
| 208 |
sprite.graphics.drawCircle(Math.random() * w, Math.random() * h, Math.random() * 20 + 30); |
|---|
| 209 |
sprite.graphics.endFill(); |
|---|
| 210 |
} |
|---|
| 211 |
return sprite; |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
//-------------------------------------------------------------------------- |
|---|
| 219 |
// REMOVE CONTENT METHOD |
|---|
| 220 |
// |
|---|
| 221 |
// 時計の合間に表示するコンテンツが削除される直前に呼び出されます |
|---|
| 222 |
// |
|---|
| 223 |
// _removeContentメソッドをオーバーライドするか, removeContentに関数を代入します. |
|---|
| 224 |
//-------------------------------------------------------------------------- |
|---|
| 225 |
|
|---|
| 226 |
private var __removeContent:Function; |
|---|
| 227 |
|
|---|
| 228 |
//Setter経由で設定している場合は, オーバーライドされた関数を実行しません |
|---|
| 229 |
public function get removeContent():Function { return __removeContent || _removeContent; } |
|---|
| 230 |
public function set removeContent(value:Function):void { __removeContent = value; } |
|---|
| 231 |
|
|---|
| 232 |
/** |
|---|
| 233 |
* 時計の合間に表示するコンテンツが削除される直前に呼び出される関数(オーバーライド用) |
|---|
| 234 |
* @param content 表示中のコンテンツ |
|---|
| 235 |
*/ |
|---|
| 236 |
protected function _removeContent(content:DisplayObject):void |
|---|
| 237 |
{ |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
//-------------------------------------------------------------------------- |
|---|
| 245 |
// RESIZE CONTENT METHOD |
|---|
| 246 |
// |
|---|
| 247 |
// Eseclockのリサイズに合わせてコンテンツをリサイズする関数を設定します |
|---|
| 248 |
// |
|---|
| 249 |
// _resizeContentメソッドをオーバーライドするか, resizeContentに関数を代入します. |
|---|
| 250 |
//-------------------------------------------------------------------------- |
|---|
| 251 |
|
|---|
| 252 |
private var __resizeContent:Function; |
|---|
| 253 |
|
|---|
| 254 |
//Setter経由で設定している場合は, オーバーライドされた関数を実行しません |
|---|
| 255 |
public function get resizeContent():Function { return __resizeContent || _resizeContent; } |
|---|
| 256 |
public function set resizeContent(value:Function):void { __resizeContent = value; } |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
/** |
|---|
| 260 |
* Eseclockのリサイズに合わせてコンテンツをリサイズする関数(オーバーライド用) |
|---|
| 261 |
* @param content コンテンツ |
|---|
| 262 |
* @param w Eseclockの幅 |
|---|
| 263 |
* @param h Eseclockの高さ |
|---|
| 264 |
*/ |
|---|
| 265 |
protected function _resizeContent(content:DisplayObject, w:Number, h:Number):void |
|---|
| 266 |
{ |
|---|
| 267 |
content.width = w; |
|---|
| 268 |
content.height = h; |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
//-------------------------------------------------------------------------- |
|---|
| 276 |
// TICK METHOD |
|---|
| 277 |
// |
|---|
| 278 |
// 毎秒呼び出されます |
|---|
| 279 |
// |
|---|
| 280 |
// _tickメソッドをオーバーライドするか, tickに関数を代入します. |
|---|
| 281 |
//-------------------------------------------------------------------------- |
|---|
| 282 |
|
|---|
| 283 |
private var __tick:Function; |
|---|
| 284 |
|
|---|
| 285 |
//Setter経由で設定している場合は, オーバーライドされた関数を実行しません |
|---|
| 286 |
public function get tick():Function { return __tick || _tick; } |
|---|
| 287 |
public function set tick(value:Function):void { __tick = value; } |
|---|
| 288 |
|
|---|
| 289 |
/** |
|---|
| 290 |
* 毎秒呼び出される関数(オーバーライド用) |
|---|
| 291 |
* @param h 時 |
|---|
| 292 |
* @param m 分 |
|---|
| 293 |
* @param s 秒 |
|---|
| 294 |
*/ |
|---|
| 295 |
protected function _tick(h:uint, m:uint, s:uint):void |
|---|
| 296 |
{ |
|---|
| 297 |
//trace(h + ":" + m + ":" + s); |
|---|
| 298 |
} |
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
//------------------------------------- |
|---|
| 305 |
// VARIABLES |
|---|
| 306 |
//------------------------------------- |
|---|
| 307 |
|
|---|
| 308 |
private var _autoPlay:Boolean; |
|---|
| 309 |
private var _isPlaying:Boolean; |
|---|
| 310 |
|
|---|
| 311 |
private var _leading:Number; |
|---|
| 312 |
|
|---|
| 313 |
private var _clock1:ClockSprite; |
|---|
| 314 |
private var _clock2:ClockSprite; |
|---|
| 315 |
private var _contentContainer:ContentSprite; |
|---|
| 316 |
|
|---|
| 317 |
private var _prevDate:Date; |
|---|
| 318 |
|
|---|
| 319 |
/* 時計/コンテンツの表示/非表示アニメーションの方向 |
|---|
| 320 |
* |
|---|
| 321 |
* (0, 1, 2, 3) = (↓, ←, ↑, →) |
|---|
| 322 |
* |
|---|
| 323 |
* 表示するとき ・・・ 矢印の方向へマスクが拡大する |
|---|
| 324 |
* 非表示にするとき ・・・ 矢印の方向へマスクが縮小する |
|---|
| 325 |
*/ |
|---|
| 326 |
private var _direction:uint; |
|---|
| 327 |
|
|---|
| 328 |
private var _textFieldAsset1:String; |
|---|
| 329 |
private var _textFieldAsset2:String; |
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
//------------------------------------- |
|---|
| 336 |
// CONSTRUCTOR |
|---|
| 337 |
//------------------------------------- |
|---|
| 338 |
|
|---|
| 339 |
/** |
|---|
| 340 |
* コンストラクタ |
|---|
| 341 |
* @param color1 色1 |
|---|
| 342 |
* @param color2 色2 |
|---|
| 343 |
* @param w Eseclockの幅 (0でステージにフィットする) |
|---|
| 344 |
* @param h Eseclockの高さ(0でステージにフィットする) |
|---|
| 345 |
* @param autoPlay 自動再生 |
|---|
| 346 |
* @param textField1 時計部分のTextField |
|---|
| 347 |
* @param textField2 文字部分のTextField |
|---|
| 348 |
*/ |
|---|
| 349 |
public function Eseclock(color1:uint = 0x000000, |
|---|
| 350 |
color2:uint = 0xffffff, |
|---|
| 351 |
w:Number = 640, |
|---|
| 352 |
h:Number = 320, |
|---|
| 353 |
autoScaleToStage:Boolean = true, |
|---|
| 354 |
autoPlay:Boolean = true, |
|---|
| 355 |
leading:Number = 0, |
|---|
| 356 |
textFieldAsset1:String = "", |
|---|
| 357 |
textFieldAsset2:String = "") |
|---|
| 358 |
{ |
|---|
| 359 |
_color1 = color1; |
|---|
| 360 |
_color2 = color2; |
|---|
| 361 |
|
|---|
| 362 |
_w = w; |
|---|
| 363 |
_h = h; |
|---|
| 364 |
|
|---|
| 365 |
_autoScaleToStage = autoScaleToStage; |
|---|
| 366 |
|
|---|
| 367 |
_autoPlay = autoPlay; |
|---|
| 368 |
_isPlaying = false; |
|---|
| 369 |
|
|---|
| 370 |
_leading = leading; |
|---|
| 371 |
|
|---|
| 372 |
_textFieldAsset1 = textFieldAsset1; |
|---|
| 373 |
_textFieldAsset2 = textFieldAsset2; |
|---|
| 374 |
|
|---|
| 375 |
addEventListener(Event.ADDED_TO_STAGE, _addedToStageHandler); |
|---|
| 376 |
} |
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
//------------------------------------- |
|---|
| 383 |
// METHODS |
|---|
| 384 |
//------------------------------------- |
|---|
| 385 |
|
|---|
| 386 |
/** |
|---|
| 387 |
* 現在の_wと_hに合わせてEseclockをリサイズする関数 |
|---|
| 388 |
* @param coercively 強制 |
|---|
| 389 |
*/ |
|---|
| 390 |
private function _resize(coercively:Boolean = false):void |
|---|
| 391 |
{ |
|---|
| 392 |
if (!coercively && _autoScaleToStage) return; |
|---|
| 393 |
|
|---|
| 394 |
var w:Number = (_autoScaleToStage) ? stage.stageWidth : _w; |
|---|
| 395 |
var h:Number = (_autoScaleToStage) ? stage.stageHeight : _h; |
|---|
| 396 |
|
|---|
| 397 |
_clock1.resize(w, h); |
|---|
| 398 |
_clock2.resize(w, h); |
|---|
| 399 |
_contentContainer.resize(w, h); |
|---|
| 400 |
|
|---|
| 401 |
if (_contentContainer.content != null) { |
|---|
| 402 |
resizeContent(_contentContainer.content, w, h); |
|---|
| 403 |
} |
|---|
| 404 |
} |
|---|
| 405 |
|
|---|
| 406 |
/** |
|---|
| 407 |
* 現在の_color1と_color2に合わせて色づけをおこなう関数 |
|---|
| 408 |
*/ |
|---|
| 409 |
private function _coloring1():void |
|---|
| 410 |
{ |
|---|
| 411 |
_clock1.textColor = _color1; |
|---|
| 412 |
_clock2.backgroundColor = _color1; |
|---|
| 413 |
} |
|---|
| 414 |
|
|---|
| 415 |
private function _coloring2():void |
|---|
| 416 |
{ |
|---|
| 417 |
_clock2.textColor = _color2; |
|---|
| 418 |
_clock1.backgroundColor = _color2; |
|---|
| 419 |
} |
|---|
| 420 |
|
|---|
| 421 |
/** |
|---|
| 422 |
* 数値を2桁に桁揃えするstaticな関数 |
|---|
| 423 |
* @param n 桁揃え前の数値 |
|---|
| 424 |
* @param digit 桁数 |
|---|
| 425 |
* @return 桁揃え後のString |
|---|
| 426 |
*/ |
|---|
| 427 |
public static function toDigitString(n:uint, digit:uint = 2):String |
|---|
| 428 |
{ |
|---|
| 429 |
var s:String = n.toString(); |
|---|
| 430 |
while (s.length < digit) s = "0" + n; |
|---|
| 431 |
return s; |
|---|
| 432 |
} |
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
//------------------------------------- |
|---|
| 439 |
// EVENT HANDLER |
|---|
| 440 |
//------------------------------------- |
|---|
| 441 |
|
|---|
| 442 |
/** |
|---|
| 443 |
* ステージに配置されたときに呼び出されるイベントハンドラ(初期化用) |
|---|
| 444 |
* @param e |
|---|
| 445 |
*/ |
|---|
| 446 |
private function _addedToStageHandler(e:Event):void |
|---|
| 447 |
{ |
|---|
| 448 |
removeEventListener(Event.ADDED_TO_STAGE, _addedToStageHandler); |
|---|
| 449 |
|
|---|
| 450 |
var w:Number = (_w == 0) ? stage.stageWidth : _w; |
|---|
| 451 |
var h:Number = (_h == 0) ? stage.stageHeight : _h; |
|---|
| 452 |
|
|---|
| 453 |
var clock1:ClockSprite = new ClockSprite(_color1, _color2, w, h, _leading, _textFieldAsset1, _textFieldAsset2); |
|---|
| 454 |
var clock2:ClockSprite = new ClockSprite(_color2, _color1, w, h, _leading, _textFieldAsset1, _textFieldAsset2); |
|---|
| 455 |
var contentContainer:ContentSprite = new ContentSprite(w, h); |
|---|
| 456 |
|
|---|
| 457 |
_clock1 = clock1; |
|---|
| 458 |
_clock2 = clock2; |
|---|
| 459 |
_contentContainer = contentContainer; |
|---|
| 460 |
|
|---|
| 461 |
addChild(clock1); |
|---|
| 462 |
addChild(clock2); |
|---|
| 463 |
addChild(contentContainer); |
|---|
| 464 |
|
|---|
| 465 |
//stageの設定 |
|---|
| 466 |
if (_autoScaleToStage) { |
|---|
| 467 |
stage.align = StageAlign.TOP_LEFT; |
|---|
| 468 |
stage.scaleMode = StageScaleMode.NO_SCALE; |
|---|
| 469 |
trace("INFO: autoScaleToStage=true : Eseclock has changed the Stage scale mode."); |
|---|
| 470 |
} |
|---|
| 471 |
|
|---|
| 472 |
//最初は左から右へアニメーションさせる |
|---|
| 473 |
_direction = 3; |
|---|
| 474 |
|
|---|
| 475 |
//最初に表示する時刻 |
|---|
| 476 |
var date:Date = new Date(); |
|---|
| 477 |
_clock1.updateField(date.hours, date.minutes, date.seconds); |
|---|
| 478 |
_clock2.updateField(date.hours, date.minutes, date.seconds); |
|---|
| 479 |
|
|---|
| 480 |
//最初に表示するテキスト |
|---|
| 481 |
_clock1.updateDescription(_description); |
|---|
| 482 |
_clock2.updateDescription(_description); |
|---|
| 483 |
|
|---|
| 484 |
//自動開始 |
|---|
| 485 |
if (_autoPlay) { |
|---|
| 486 |
start(); |
|---|
| 487 |
} |
|---|
| 488 |
|
|---|
| 489 |
_resize(true); |
|---|
| 490 |
stage.addEventListener(Event.RESIZE, _resizeHandler); |
|---|
| 491 |
} |
|---|
| 492 |
|
|---|
| 493 |
/** |
|---|
| 494 |
* 開始 |
|---|
| 495 |
*/ |
|---|
| 496 |
public function start():void { |
|---|
| 497 |
if (_isPlaying) return; |
|---|
| 498 |
_isPlaying = true; |
|---|
| 499 |
|
|---|
| 500 |
_prevDate = new Date(); |
|---|
| 501 |
_update(); |
|---|
| 502 |
addEventListener(Event.ENTER_FRAME, _update); |
|---|
| 503 |
} |
|---|
| 504 |
|
|---|
| 505 |
/** |
|---|
| 506 |
* 毎フレーム時計が切り替わるタイミングをチェックするイベントハンドラ関数 |
|---|
| 507 |
* @param e |
|---|
| 508 |
*/ |
|---|
| 509 |
private function _update(e:Event = null):void |
|---|
| 510 |
{ |
|---|
| 511 |
var date:Date = new Date(); |
|---|
| 512 |
|
|---|
| 513 |
var h:uint = date.hours; |
|---|
| 514 |
var m:uint = date.minutes; |
|---|
| 515 |
var s:uint = date.seconds; |
|---|
| 516 |
|
|---|
| 517 |
//前回の更新から1秒経っていれば |
|---|
| 518 |
if (s != _prevDate.seconds) { |
|---|
| 519 |
|
|---|
| 520 |
//1秒の時点でコンテンツを非表示にするアニメーションを開始する |
|---|
| 521 |
if (s % 10 == 1) { |
|---|
| 522 |
_contentContainer.hide(_direction, |
|---|
| 523 |
function():void { |
|---|
| 524 |
//アニメーション完了時にコンテンツを削除する |
|---|
| 525 |
if (_contentContainer.content != null) { |
|---|
| 526 |
removeContent(_contentContainer.content); |
|---|
| 527 |
_contentContainer.removeContent(); |
|---|
| 528 |
} |
|---|
| 529 |
} |
|---|
| 530 |
); |
|---|
| 531 |
} |
|---|
| 532 |
|
|---|
| 533 |
//6秒の時点でコンテンツをステージ上に配置し, 表示アニメーションを開始する |
|---|
| 534 |
if (s % 10 == 6) { |
|---|
| 535 |
_contentContainer.addContent( createContent(stage.stageWidth, stage.stageHeight) ); |
|---|
| 536 |
_contentContainer.show(_direction); |
|---|
| 537 |
} |
|---|
| 538 |
|
|---|
| 539 |
//コンテンツが表示されていない状態なら |
|---|
| 540 |
if (_contentContainer.content == null) { |
|---|
| 541 |
|
|---|
| 542 |
//1秒ごとに時計を入れ替える(アクティブな方を上に重ねていく) |
|---|
| 543 |
//if (s % 2 == 0) { |
|---|
| 544 |
if (_clock1.visible) { |
|---|
| 545 |
_clock2.visible = true; |
|---|
| 546 |
|
|---|
| 547 |
_clock2.show(_direction, |
|---|
| 548 |
function():void { |
|---|
| 549 |
_clock1.visible = false; |
|---|
| 550 |
} |
|---|
| 551 |
); |
|---|
| 552 |
|
|---|
| 553 |
addChildAt(_clock2, 1); |
|---|
| 554 |
} |
|---|
| 555 |
else { |
|---|
| 556 |
_clock1.visible = true; |
|---|
| 557 |
|
|---|
| 558 |
_clock1.show(_direction, |
|---|
| 559 |
function():void { |
|---|
| 560 |
_clock2.visible = false; |
|---|
| 561 |
} |
|---|
| 562 |
); |
|---|
| 563 |
|
|---|
| 564 |
addChildAt(_clock1, 1); |
|---|
| 565 |
} |
|---|
| 566 |
} |
|---|
| 567 |
|
|---|
| 568 |
//文字盤の更新 |
|---|
| 569 |
_clock1.updateField(h, m, s); |
|---|
| 570 |
_clock2.updateField(h, m, s); |
|---|
| 571 |
|
|---|
| 572 |
tick(h, m, s); |
|---|
| 573 |
|
|---|
| 574 |
//アニメーション方向の更新 |
|---|
| 575 |
_direction = (++_direction % 4 == 0) ? 0 : _direction; |
|---|
| 576 |
} |
|---|
| 577 |
|
|---|
| 578 |
_prevDate = date; |
|---|
| 579 |
} |
|---|
| 580 |
|
|---|
| 581 |
/** |
|---|
| 582 |
* ステージがリサイズされたときに呼び出されるイベントハンドラ |
|---|
| 583 |
* @param e |
|---|
| 584 |
*/ |
|---|
| 585 |
private function _resizeHandler(e:Event):void { |
|---|
| 586 |
if (_autoScaleToStage) _resize(true); |
|---|
| 587 |
} |
|---|
| 588 |
} |
|---|
| 589 |
} |
|---|