/** *============================================================ * copyright(c) 2011 www.romatica.com * @author itoz *============================================================ */ package { import qnx.ui.buttons.LabelButton; import qnx.ui.core.Container; import qnx.ui.core.ContainerAlign; import qnx.ui.core.ContainerFlow; import qnx.ui.core.SizeMode; import qnx.ui.core.SizeUnit; import qnx.ui.core.Spacer; import qnx.ui.text.Label; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import flash.text.TextFormatAlign; public class TestContainer extends Sprite { private const _TFM : TextFormat = new TextFormat(null, 26, 0x333333, null, null, null, null, null, TextFormatAlign.CENTER); private var _container : Container; public function TestContainer() { stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; stage.addEventListener(Event.RESIZE, onResize); addEventListener(Event.ADDED_TO_STAGE, onAdded); } private function onAdded(event : Event) : void { removeEventListener(Event.ADDED_TO_STAGE, init); // ---------------------------------------------------- //  コンテナクラス _container = addChild(new Container()) as Container; _container.flow = ContainerFlow.VERTICAL;// ★このコンテナ内、縦並び _container.align = ContainerAlign.MID; // ★このコンテナ内、縦中央揃え // ---------------------------------------------------- // コンテナ上部から20% スペースを空ける _container.addChild(new Spacer(20)); // ---------------------------------------------------- // タイトルラベル var titleLabel : Label = _container.addChild(new Label()) as Label; titleLabel.text = "Liquid Layout Sample"; titleLabel.format = _TFM; titleLabel.setSize(300, 35); titleLabel.sizeMode = SizeMode.BOTH; // ---------------------------------------------------- // 10% スペースを空ける _container.addChild(new Spacer(10)); // ---------------------------------------------------- // 任意のDisplayObject(ここではスプライト) var _sp:Sprite = _container.addChild(new Sprite()) as Sprite; _sp.graphics.beginFill(0xdedede); _sp.graphics.drawRect(0, 0, 400, 80); _sp.graphics.endFill(); var _tf : TextField = _sp.addChild(new TextField()) as TextField; _tf.text = "Sprite : 任意のDisplayObjectも、リキッドレイアウトになります"; _tf.autoSize = TextFieldAutoSize.LEFT; _tf.width = 400; _tf.height = 50; _tf.x = 400/2-(_tf.width/2); _tf.y = 80/2-(_tf.height/2); // ---------------------------------------------------- // 10% スペースを空ける _container.addChild(new Spacer(10)); // ---------------------------------------------------- // ラベルボタン var btn : LabelButton = _container.addChild(new LabelButton()) as LabelButton; btn.label = "Label Button Sample"; btn.sizeUnit=SizeUnit.PERCENT; btn.size=40; // ---------------------------------------------------- // 10% スペースを空ける _container.addChild(new Spacer(10)); // ---------------------------------------------------- // ※最後に Container のサイズを指定してあげます _container.width = stage.stageWidth; _container.height = stage.stageHeight; } // ----------------------------------------------------------------- /** * resize */ private function onResize(event : Event) : void { if (stage != null) { if (_container != null) { _container.width = stage.stageWidth; _container.height = stage.stageHeight; } } } } }