root/as3/WindowResize/net/tkis/utils/WindowResize.as

リビジョン 1470, 4.5 kB (コミッタ: t-kis, コミット時期: 1 年 前)

重複定義の削除

  • svn:executable 属性の設定値: *
Line 
1 /*
2
3  * WindowResizeクラス
4  * ウインドウがリサイズされた時に、指定した位置をキープします。
5  *
6  * @authorTAKEISHI Shun-ichi (T-kis.net)
7  * @version1.11
8
9  * 変更履歴
10  * 1.00 08.09.22 リリース
11  * 1.01 08.09.23 余計な変数を削除
12  * 1.02 08.09.27 アニメーションをTween クラスに変更。
13  * 1.10 08.09.29 センタリング対応・対象オブジェをMovieClipからDisplayObjectへ。
14  * 1.11  08.10.01 重複したコードを削除
15
16  
17 Licensed under the MIT License
18 Copyright (c) 2008 TAKEISHI Syun-ichi And the Spark project.
19    
20 */
21
22 package {
23         import flash.events.Event;
24         import flash.display.*;
25         import fl.transitions.*;
26         import fl.transitions.easing.*;
27         public class WindowResize {
28
29                 /*初期設定値 */
30                 var stagemin_w:int=600;//コンテンツ最小サイズ横幅
31                 var stagemin_h:int=480;//コンテンツ最小サイズ縦幅
32                 var speed:Number=2;//移動完了までの時間
33                 var tweeneasing:Function=Regular.easeOut;//イージングのタイプ
34
35                 /*その他変数*/
36                 private var move_mc:DisplayObject;
37                 private var position_st:String;
38                 private var for_x:uint=0;
39                 private var for_y:uint=0;
40                 var mc_TweenX:Tween;
41                 var mc_TweenY:Tween;
42                 private var w:uint;
43                 private var h:uint;
44
45
46                 /*コンストラクタ*/
47                 function WindowResize(movemc:DisplayObject,position:String):void {
48                         position_st=position;
49                         move_mc=movemc;
50                         move_mc.stage.scaleMode=StageScaleMode.NO_SCALE;
51                         fixPosition();
52                         move_mc.stage.addEventListener(Event.RESIZE,setPosition);
53                 }
54                 function setPosition(evnet:Event):void {
55                         w=move_mc.stage.stageWidth;
56                         h=move_mc.stage.stageHeight;
57                         switch (position_st) {
58                                 case "right_top" :
59                                         for_x=Math.max(stagemin_w - move_mc.width,w - move_mc.width);
60                                         break;
61                                 case "right_center" :
62                                         for_x=Math.max(stagemin_w - move_mc.width,w - move_mc.width);
63                                         for_y=Math.max(stagemin_h / 2 - move_mc.height / 2,h / 2 - move_mc.height / 2);
64
65                                         break;
66                                 case "right_bottom" :
67                                         for_x=Math.max(stagemin_w - move_mc.width,w - move_mc.width);
68                                         for_y=Math.max(stagemin_h - move_mc.height,h - move_mc.height);
69                                         break;
70                                 case "center_top" :
71                                         for_x=Math.max(stagemin_w / 2 - move_mc.width / 2,w / 2 - move_mc.width / 2);
72                                         break;
73                                 case "center_center" :
74                                         for_x=Math.max(stagemin_w / 2 - move_mc.width / 2,w / 2 - move_mc.width / 2);
75                                         for_y=Math.max(stagemin_h / 2 - move_mc.height / 2,h / 2 - move_mc.height / 2);
76                                         break;
77                                 case "center_bottom" :
78                                         for_x=Math.max(stagemin_w / 2 - move_mc.width / 2,w / 2 - move_mc.width / 2);
79                                         for_y=Math.max(stagemin_h - move_mc.height,h - move_mc.height);
80                                         break;
81                                 case "left_top" :
82                                         break;
83                                 case "left_center" :
84                                         for_y=Math.max(stagemin_h / 2 - move_mc.height / 2,h / 2 - move_mc.height / 2);
85                                         break;
86                                 case "left_bottom" :
87                                         for_y=Math.max(stagemin_h - move_mc.height,h - move_mc.height);
88                                         break;
89                         }
90                         mc_TweenX=new Tween(move_mc,"x",tweeneasing,move_mc.x,for_x,speed,true);
91                         mc_TweenY=new Tween(move_mc,"y",tweeneasing,move_mc.y,for_y,speed,true);
92                 }
93                 function fixPosition():void {
94                         w=move_mc.stage.stageWidth;
95                         h=move_mc.stage.stageHeight;
96                         switch (position_st) {
97                                 case "right_top" :
98                                         move_mc.x=Math.max(stagemin_w - move_mc.width,w - move_mc.width);
99                                         move_mc.y=0;
100                                         break;
101                                 case "right_center" :
102                                         move_mc.x=Math.max(stagemin_w - move_mc.width,w - move_mc.width);
103                                         move_mc.y=Math.max(stagemin_h / 2 - move_mc.height / 2,h / 2 - move_mc.height / 2);
104                                         break;
105                                 case "right_bottom" :
106                                         move_mc.x=Math.max(stagemin_w - move_mc.width,w - move_mc.width);
107                                         move_mc.y=Math.max(stagemin_h - move_mc.height,h - move_mc.height);
108                                         break;
109                                 case "center_top" :
110                                         move_mc.x=Math.max(stagemin_w / 2 - move_mc.width / 2,w / 2 - move_mc.width / 2);
111                                         move_mc.y=0;
112                                         break;
113                                 case "center_center" :
114                                         move_mc.x=Math.max(stagemin_w / 2 - move_mc.width / 2,w / 2 - move_mc.width / 2);
115                                         move_mc.y=Math.max(stagemin_h / 2 - move_mc.height / 2,h / 2 - move_mc.height / 2);
116                                         break;
117                                 case "center_bottom" :
118                                         move_mc.x=Math.max(stagemin_w / 2 - move_mc.width / 2,w / 2 - move_mc.width / 2);
119                                         move_mc.y=Math.max(stagemin_h - move_mc.height,h - move_mc.height);
120                                         break;
121                                 case "left_top" :
122                                         move_mc.x=0;
123                                         move_mc.y=0;
124                                         break;
125                                 case "left_center" :
126                                         move_mc.x=0;
127                                         move_mc.y=Math.max(stagemin_h / 2 - move_mc.height / 2,h / 2 - move_mc.height / 2);
128                                         break;
129                                 case "left_bottom" :
130                                         move_mc.x=0;
131                                         move_mc.y=Math.max(stagemin_h - move_mc.height,h - move_mc.height);
132                                         break;
133                         }
134                 }
135         }
136 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。