チェンジセット 1470: as3/WindowResize
- コミット日時:
- 2008/10/02 01:05:50 (4 年前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
as3/WindowResize/net/tkis/utils/WindowResize.as
r1469 r1470 5 5 * 6 6 * @authorTAKEISHI Shun-ichi (T-kis.net) 7 * @version1.1 07 * @version1.11 8 8 9 9 * 変更履歴 … … 12 12 * 1.02 08.09.27 アニメーションをTween クラスに変更。 13 13 * 1.10 08.09.29 センタリング対応・対象オブジェをMovieClipからDisplayObjectへ。 14 * 1.1 01 08.10.01 綴り間違え修正14 * 1.11 08.10.01 重複したコードを削除 15 15 16 16 … … 28 28 29 29 /*初期設定値 */ 30 var stagemin_w:int = 600;//コンテンツ最小サイズ横幅31 var stagemin_h:int = 480;//コンテンツ最小サイズ縦幅32 var speed:Number = 0.7;//移動完了までの時間33 var tweeneasing:Function = Regular.easeOut;//イージングのタイプ30 var stagemin_w:int=600;//コンテンツ最小サイズ横幅 31 var stagemin_h:int=480;//コンテンツ最小サイズ縦幅 32 var speed:Number=2;//移動完了までの時間 33 var tweeneasing:Function=Regular.easeOut;//イージングのタイプ 34 34 35 35 /*その他変数*/ 36 36 private var move_mc:DisplayObject; 37 37 private var position_st:String; 38 private var for_x:uint =0;39 private var for_y:uint =0;38 private var for_x:uint=0; 39 private var for_y:uint=0; 40 40 var mc_TweenX:Tween; 41 41 var mc_TweenY:Tween; … … 46 46 /*コンストラクタ*/ 47 47 function WindowResize(movemc:DisplayObject,position:String):void { 48 position_st =position;49 move_mc =movemc;50 move_mc.stage.scaleMode =StageScaleMode.NO_SCALE;48 position_st=position; 49 move_mc=movemc; 50 move_mc.stage.scaleMode=StageScaleMode.NO_SCALE; 51 51 fixPosition(); 52 move_mc.stage.addEventListener(Event.RESIZE,onWindowResize); 53 } 54 function onWindowResize(evnet:Event):void { 55 move_mc.stage.addEventListener(Event.ENTER_FRAME,setPosition); 52 move_mc.stage.addEventListener(Event.RESIZE,setPosition); 56 53 } 57 54 function setPosition(evnet:Event):void { 58 w =move_mc.stage.stageWidth;59 h =move_mc.stage.stageHeight;55 w=move_mc.stage.stageWidth; 56 h=move_mc.stage.stageHeight; 60 57 switch (position_st) { 61 58 case "right_top" : 62 for_x= Math.max(stagemin_w-move_mc.width,w-move_mc.width); 63 mc_TweenX = new Tween(move_mc, "x", tweeneasing, move_mc.x,for_x ,speed, true); 59 for_x=Math.max(stagemin_w - move_mc.width,w - move_mc.width); 64 60 break; 65 61 case "right_center" : 66 for_x =Math.max(stagemin_w-move_mc.width,w-move_mc.width); 67 for_y =Math.max(stagemin_h/2-move_mc.height/2,h/2-move_mc.height/2); 68 mc_TweenX = new Tween(move_mc, "x", tweeneasing, move_mc.x,for_x ,speed, true); 69 mc_TweenY = new Tween(move_mc, "y", tweeneasing, move_mc.y,for_y ,speed, true); 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 70 65 break; 71 66 case "right_bottom" : 72 for_x =Math.max(stagemin_w-move_mc.width,w-move_mc.width); 73 for_y =Math.max(stagemin_h-move_mc.height,h-move_mc.height); 74 mc_TweenX = new Tween(move_mc, "x", tweeneasing, move_mc.x,for_x ,speed, true); 75 mc_TweenY = new Tween(move_mc, "y", tweeneasing, move_mc.y,for_y ,speed, true); 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); 76 69 break; 77 70 case "center_top" : 78 for_x =Math.max(stagemin_w/2-move_mc.width/2,w/2-move_mc.width/2); 79 mc_TweenX = new Tween(move_mc, "x", tweeneasing, move_mc.x,for_x ,speed, true); 71 for_x=Math.max(stagemin_w / 2 - move_mc.width / 2,w / 2 - move_mc.width / 2); 80 72 break; 81 73 case "center_center" : 82 for_x =Math.max(stagemin_w/2-move_mc.width/2,w/2-move_mc.width/2); 83 for_y =Math.max(stagemin_h/2-move_mc.height/2,h/2-move_mc.height/2); 84 mc_TweenX = new Tween(move_mc, "x", tweeneasing, move_mc.x,for_x ,speed, true); 85 mc_TweenY = new Tween(move_mc, "y", tweeneasing, move_mc.y,for_y ,speed, true); 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); 86 76 break; 87 77 case "center_bottom" : 88 for_x =Math.max(stagemin_w/2-move_mc.width/2,w/2-move_mc.width/2); 89 for_y =Math.max(stagemin_h-move_mc.height,h-move_mc.height); 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); 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); 92 80 break; 93 81 case "left_top" : 94 82 break; 95 83 case "left_center" : 96 for_y =Math.max(stagemin_h/2-move_mc.height/2,h/2-move_mc.height/2); 97 mc_TweenY = new Tween(move_mc, "y", tweeneasing, move_mc.y,for_y ,speed, true); 84 for_y=Math.max(stagemin_h / 2 - move_mc.height / 2,h / 2 - move_mc.height / 2); 98 85 break; 99 86 case "left_bottom" : 100 for_y = Math.max(stagemin_h-move_mc.height,h-move_mc.height); 101 mc_TweenY = new Tween(move_mc, "y", tweeneasing, move_mc.y,for_y ,speed, true); 87 for_y=Math.max(stagemin_h - move_mc.height,h - move_mc.height); 102 88 break; 103 89 } 104 if (Math.abs(for_y-move_mc.y) < 1 && Math.abs(for_x-move_mc.x) < 1 ) { 105 move_mc.stage.removeEventListener(Event.ENTER_FRAME,setPosition); 106 fixPosition(); 107 } 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); 108 92 } 109 93 function fixPosition():void { 110 w =move_mc.stage.stageWidth;111 h =move_mc.stage.stageHeight;94 w=move_mc.stage.stageWidth; 95 h=move_mc.stage.stageHeight; 112 96 switch (position_st) { 113 97 case "right_top" : 114 move_mc.x =Math.max(stagemin_w-move_mc.width,w-move_mc.width);115 move_mc.y =0;98 move_mc.x=Math.max(stagemin_w - move_mc.width,w - move_mc.width); 99 move_mc.y=0; 116 100 break; 117 101 case "right_center" : 118 move_mc.x =Math.max(stagemin_w-move_mc.width,w-move_mc.width);119 move_mc.y =Math.max(stagemin_h/2-move_mc.height/2,h/2-move_mc.height/2);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); 120 104 break; 121 105 case "right_bottom" : 122 move_mc.x =Math.max(stagemin_w-move_mc.width,w-move_mc.width);123 move_mc.y =Math.max(stagemin_h-move_mc.height,h-move_mc.height);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); 124 108 break; 125 109 case "center_top" : 126 move_mc.x =Math.max(stagemin_w/2-move_mc.width/2,w/2-move_mc.width/2);127 move_mc.y =0;110 move_mc.x=Math.max(stagemin_w / 2 - move_mc.width / 2,w / 2 - move_mc.width / 2); 111 move_mc.y=0; 128 112 break; 129 113 case "center_center" : 130 move_mc.x =Math.max(stagemin_w/2-move_mc.width/2,w/2-move_mc.width/2);131 move_mc.y =Math.max(stagemin_h/2-move_mc.height/2,h/2-move_mc.height/2);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); 132 116 break; 133 117 case "center_bottom" : 134 move_mc.x =Math.max(stagemin_w/2-move_mc.width/2,w/2-move_mc.width/2);135 move_mc.y =Math.max(stagemin_h-move_mc.height,h-move_mc.height);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); 136 120 break; 137 121 case "left_top" : 138 move_mc.x =0;139 move_mc.y =0;122 move_mc.x=0; 123 move_mc.y=0; 140 124 break; 141 125 case "left_center" : 142 move_mc.x =0;143 move_mc.y =Math.max(stagemin_h/2-move_mc.height/2,h/2-move_mc.height/2);126 move_mc.x=0; 127 move_mc.y=Math.max(stagemin_h / 2 - move_mc.height / 2,h / 2 - move_mc.height / 2); 144 128 break; 145 129 case "left_bottom" : 146 move_mc.x =0;147 move_mc.y =Math.max(stagemin_h-move_mc.height,h-move_mc.height);130 move_mc.x=0; 131 move_mc.y=Math.max(stagemin_h - move_mc.height,h - move_mc.height); 148 132 break; 149 133 }

