| 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.object |
|---|
| 27 |
{ |
|---|
| 28 |
import caurina.transitions.Tweener; |
|---|
| 29 |
import flash.display.DisplayObject; |
|---|
| 30 |
import flash.display.Graphics; |
|---|
| 31 |
import flash.display.Shape; |
|---|
| 32 |
import flash.display.Sprite; |
|---|
| 33 |
import flash.text.TextField; |
|---|
| 34 |
import flash.text.TextFieldAutoSize; |
|---|
| 35 |
import flash.text.TextFormat; |
|---|
| 36 |
import flash.utils.getDefinitionByName; |
|---|
| 37 |
|
|---|
| 38 |
/** |
|---|
| 39 |
* TweenMaskSprite.as |
|---|
| 40 |
* マスクアニメーション付きSpriteのための基本クラス |
|---|
| 41 |
* |
|---|
| 42 |
* @author alumican.net<Yukiya Okuda> |
|---|
| 43 |
* @link http://alumican.net/ |
|---|
| 44 |
* @link http://www.libspark.org/ |
|---|
| 45 |
*/ |
|---|
| 46 |
|
|---|
| 47 |
public class TweenMaskSprite extends Sprite |
|---|
| 48 |
{ |
|---|
| 49 |
//------------------------------------- |
|---|
| 50 |
// VARIABLES |
|---|
| 51 |
//------------------------------------- |
|---|
| 52 |
|
|---|
| 53 |
//マスクのサイズ |
|---|
| 54 |
protected var _w:Number; |
|---|
| 55 |
protected var _h:Number; |
|---|
| 56 |
|
|---|
| 57 |
//マスクされるコンテンツや時計をaddChildしていく |
|---|
| 58 |
protected var _masked:Sprite; |
|---|
| 59 |
|
|---|
| 60 |
//マスク(アニメーションの方向を制御) |
|---|
| 61 |
private var _maskContainer:Sprite; |
|---|
| 62 |
|
|---|
| 63 |
//マスク(アニメーションの伸縮を制御) |
|---|
| 64 |
private var _mask:Sprite; |
|---|
| 65 |
|
|---|
| 66 |
//背景 |
|---|
| 67 |
protected var _background:Shape; |
|---|
| 68 |
|
|---|
| 69 |
//背景色 |
|---|
| 70 |
protected var _backgroundColor:uint; |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
//------------------------------------- |
|---|
| 77 |
// CONSTRUCTOR |
|---|
| 78 |
//------------------------------------- |
|---|
| 79 |
|
|---|
| 80 |
/** |
|---|
| 81 |
* コンストラクタ |
|---|
| 82 |
* @param w 幅 |
|---|
| 83 |
* @param h 高さ |
|---|
| 84 |
*/ |
|---|
| 85 |
public function TweenMaskSprite(w:Number, h:Number, backgroundColor:uint) |
|---|
| 86 |
{ |
|---|
| 87 |
_w = w; |
|---|
| 88 |
_h = h; |
|---|
| 89 |
|
|---|
| 90 |
_masked = new Sprite(); |
|---|
| 91 |
addChild(_masked); |
|---|
| 92 |
|
|---|
| 93 |
_createMask(); |
|---|
| 94 |
|
|---|
| 95 |
//背景の生成 |
|---|
| 96 |
_createBackground(backgroundColor); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
//------------------------------------- |
|---|
| 104 |
// METHODS |
|---|
| 105 |
//------------------------------------- |
|---|
| 106 |
|
|---|
| 107 |
/** |
|---|
| 108 |
* マスクのインスタンスを生成する関数 |
|---|
| 109 |
*/ |
|---|
| 110 |
private function _createMask():void |
|---|
| 111 |
{ |
|---|
| 112 |
_maskContainer = new Sprite(); |
|---|
| 113 |
_mask = new Sprite(); |
|---|
| 114 |
|
|---|
| 115 |
addChild(_maskContainer); |
|---|
| 116 |
|
|---|
| 117 |
_maskContainer.addChild(_mask); |
|---|
| 118 |
|
|---|
| 119 |
_drawMask(); |
|---|
| 120 |
|
|---|
| 121 |
_masked.mask = _maskContainer; |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
/** |
|---|
| 125 |
* マスクを描画する関数 |
|---|
| 126 |
*/ |
|---|
| 127 |
private function _drawMask():void |
|---|
| 128 |
{ |
|---|
| 129 |
_maskContainer.x = _w / 2; |
|---|
| 130 |
_maskContainer.y = _h / 2; |
|---|
| 131 |
|
|---|
| 132 |
_mask.x = -_w / 2; |
|---|
| 133 |
_mask.y = -_h / 2; |
|---|
| 134 |
|
|---|
| 135 |
_mask.graphics.clear(); |
|---|
| 136 |
_mask.graphics.beginFill(0x0); |
|---|
| 137 |
_mask.graphics.drawRect(0, 0, _w, _h); |
|---|
| 138 |
_mask.graphics.endFill(); |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
/** |
|---|
| 142 |
* 背景ベタのシェイプを生成する関数 |
|---|
| 143 |
* @param color 背景色 |
|---|
| 144 |
*/ |
|---|
| 145 |
private function _createBackground(color:uint):void |
|---|
| 146 |
{ |
|---|
| 147 |
_background = new Shape(); |
|---|
| 148 |
|
|---|
| 149 |
_drawBackground(color); |
|---|
| 150 |
|
|---|
| 151 |
_masked.addChild(_background); |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
/** |
|---|
| 155 |
* 背景を描画する関数 |
|---|
| 156 |
* @param color 背景色 |
|---|
| 157 |
*/ |
|---|
| 158 |
protected function _drawBackground(color:uint):void |
|---|
| 159 |
{ |
|---|
| 160 |
_backgroundColor = color; |
|---|
| 161 |
|
|---|
| 162 |
var g:Graphics = _background.graphics; |
|---|
| 163 |
g.clear(); |
|---|
| 164 |
g.beginFill(color); |
|---|
| 165 |
g.drawRect(0, 0, _w, _h); |
|---|
| 166 |
g.endFill(); |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
/** |
|---|
| 170 |
* 表示アニメーションを開始する関数 |
|---|
| 171 |
* @param direction アニメーションの方向[0, 3] |
|---|
| 172 |
* @param onComplete アニメーション完了時に実行されるコールバック関数 |
|---|
| 173 |
*/ |
|---|
| 174 |
public function show(direction:uint, onComplete:Function = null):void |
|---|
| 175 |
{ |
|---|
| 176 |
switch(direction) { |
|---|
| 177 |
|
|---|
| 178 |
//↓ |
|---|
| 179 |
case 0: |
|---|
| 180 |
_maskContainer.scaleX = 1; |
|---|
| 181 |
_maskContainer.scaleY = 1; |
|---|
| 182 |
_mask.scaleX = 1; |
|---|
| 183 |
_mask.scaleY = 0; |
|---|
| 184 |
break; |
|---|
| 185 |
|
|---|
| 186 |
//← |
|---|
| 187 |
case 1: |
|---|
| 188 |
_maskContainer.scaleX = -1; |
|---|
| 189 |
_maskContainer.scaleY = 1; |
|---|
| 190 |
_mask.scaleX = 0; |
|---|
| 191 |
_mask.scaleY = 1; |
|---|
| 192 |
break; |
|---|
| 193 |
|
|---|
| 194 |
//↑ |
|---|
| 195 |
case 2: |
|---|
| 196 |
_maskContainer.scaleX = 1; |
|---|
| 197 |
_maskContainer.scaleY = -1; |
|---|
| 198 |
_mask.scaleX = 1; |
|---|
| 199 |
_mask.scaleY = 0; |
|---|
| 200 |
break; |
|---|
| 201 |
|
|---|
| 202 |
//→ |
|---|
| 203 |
case 3: |
|---|
| 204 |
_maskContainer.scaleX = 1; |
|---|
| 205 |
_maskContainer.scaleY = 1; |
|---|
| 206 |
_mask.scaleX = 0; |
|---|
| 207 |
_mask.scaleY = 1; |
|---|
| 208 |
break; |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
Tweener.removeTweens(_mask); |
|---|
| 212 |
Tweener.addTween(_mask, { |
|---|
| 213 |
scaleX:1, |
|---|
| 214 |
scaleY:1, |
|---|
| 215 |
time:.5, |
|---|
| 216 |
transition:"easeOutExpo", |
|---|
| 217 |
onComplete:function():void { |
|---|
| 218 |
if (onComplete != null) onComplete(); |
|---|
| 219 |
} |
|---|
| 220 |
}); |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
/** |
|---|
| 224 |
* 非表示アニメーションを開始する関数 |
|---|
| 225 |
* @param direction アニメーションの方向[0, 3] |
|---|
| 226 |
* @param onComplete アニメーション完了時に実行されるコールバック関数 |
|---|
| 227 |
*/ |
|---|
| 228 |
public function hide(direction:uint, onComplete:Function = null):void |
|---|
| 229 |
{ |
|---|
| 230 |
switch(direction) { |
|---|
| 231 |
|
|---|
| 232 |
//↓ |
|---|
| 233 |
case 0: |
|---|
| 234 |
_maskContainer.scaleX = 1; |
|---|
| 235 |
_maskContainer.scaleY = -1; |
|---|
| 236 |
break; |
|---|
| 237 |
|
|---|
| 238 |
//← |
|---|
| 239 |
case 1: |
|---|
| 240 |
_maskContainer.scaleX = 1; |
|---|
| 241 |
_maskContainer.scaleY = 1; |
|---|
| 242 |
break; |
|---|
| 243 |
|
|---|
| 244 |
//↑ |
|---|
| 245 |
case 2: |
|---|
| 246 |
_maskContainer.scaleX = 1; |
|---|
| 247 |
_maskContainer.scaleY = 1; |
|---|
| 248 |
break; |
|---|
| 249 |
|
|---|
| 250 |
//→ |
|---|
| 251 |
case 3: |
|---|
| 252 |
_maskContainer.scaleX = -1; |
|---|
| 253 |
_maskContainer.scaleY = 1; |
|---|
| 254 |
break; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
Tweener.removeTweens(_mask); |
|---|
| 258 |
Tweener.addTween(_mask, { |
|---|
| 259 |
scaleX:(direction % 2 == 0) ? 1 : 0, |
|---|
| 260 |
scaleY:(direction % 2 == 1) ? 1 : 0, |
|---|
| 261 |
time:.5, |
|---|
| 262 |
transition:"easeOutExpo", |
|---|
| 263 |
onComplete:function():void { |
|---|
| 264 |
if (onComplete != null) onComplete(); |
|---|
| 265 |
} |
|---|
| 266 |
}); |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
/** |
|---|
| 270 |
* 現在の_wと_hに合わせてEseclockをリサイズする関数 |
|---|
| 271 |
* @param w 幅 |
|---|
| 272 |
* @param h 高さ |
|---|
| 273 |
*/ |
|---|
| 274 |
public function resize(w:Number, h:Number):void |
|---|
| 275 |
{ |
|---|
| 276 |
_w = w; |
|---|
| 277 |
_h = h; |
|---|
| 278 |
|
|---|
| 279 |
//マスクの再描画 |
|---|
| 280 |
_drawMask(); |
|---|
| 281 |
|
|---|
| 282 |
//背景のリサイズ |
|---|
| 283 |
_background.width = _w; |
|---|
| 284 |
_background.height = _h; |
|---|
| 285 |
} |
|---|
| 286 |
} |
|---|
| 287 |
} |
|---|