新たな発見があったので「フルフラッシュサイト(2)」の追記。
画面サイズは300x100。シンボルはすべて左上基準。
【用意するもの】
背景MC「background_mc」(300x100、インスタンス名:background_mc)を_rootレイヤー1の座標(0,0)に配置。
円型のターゲットMC「target_mc」(60x60、インスタンス名:target_mc)を_rootレイヤー2の任意の座標に配置。
_rootレイヤー3の1フレーム目に以下のスクリプトを記述。
(「Stage.align="TL"」の場合)
Stage.align="TL";
Stage.scaleMode="noScale";
_root.background_mc._width=Stage.width;
_root.target_mc._x=(Stage.width-_root.target_mc._width)/2;
var lis:Object=new Object();
lis.onResize=function():Void{
_root.background_mc._width=Stage.width;
_root.target_mc._x=(Stage.width-_root.target_mc._width)/2;
}
Stage.addListener(lis);
(「Stage.align="T"」の場合)
Stage.align="T";
Stage.scaleMode="noScale";
var bg_half:Number=_root.background_mc._width/2;
_root.background_mc._x=-(Stage.width/2-bg_half);
_root.background_mc._width=Stage.width;
_root.target_mc._x=bg_half-_root.target_mc._width/2;
var lis:Object=new Object();
lis.onResize=function():Void{
_root.background_mc._x=-(Stage.width/2-bg_half);
_root.background_mc._width=Stage.width;
_root.target_mc._x=bg_half-_root.target_mc._width/2;
}
Stage.addListener(lis);
【まとめ】
左上基準のシンボルを、「Stage.align="T"」で、意図した通りに動かすためには、上記のように、背景に設定したインスタンスのハーフサイズをあらかじめ取得しておき、それを正しくインスタンスの座標に適用していく必要がある。
これは、たとえば、リサイズ前と後の「target_mc._x」に対して「0」を代入して実験をしてみると分かりやすい。元の背景の半分ほど左にずれたところにx値「0」がある。
そのため、スクリプトでは、中央の座標から背景の半分の幅を引いたり、場合によっては足したりしなければ、意図した通りにターゲットは中央にこない。
これらの特性から鑑みるに、前回「フルフラッシュサイト(2)」で示した通り、「TL」なら左上基準で、「T」なら中央基準でMCを製作しないと、コードは非常に複雑になる。
ちなみに、パブリッシュの設定は「フルフラッシュサイト(3)」で示したもので問題ない。
コメントする