From ad67558798b067724377795336ca13d661020bb6 Mon Sep 17 00:00:00 2001 From: Jamie Doornbos Date: Mon, 26 Oct 2009 20:52:04 +0000 Subject: [PATCH] Some more useful methods for FlexUtil for creating layout containers and wrappers inline. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@859 ed5b42cb-e716-0410-a449-f6a68f950b19 --- src/as/com/threerings/flex/FlexUtil.as | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/as/com/threerings/flex/FlexUtil.as b/src/as/com/threerings/flex/FlexUtil.as index 4af5cffd..f56ab663 100644 --- a/src/as/com/threerings/flex/FlexUtil.as +++ b/src/as/com/threerings/flex/FlexUtil.as @@ -21,6 +21,8 @@ package com.threerings.flex { +import flash.display.DisplayObject; + import mx.controls.Label; import mx.controls.Spacer; import mx.controls.Text; @@ -28,6 +30,9 @@ import mx.controls.Text; import mx.core.Container; import mx.core.UIComponent; +import mx.containers.HBox; +import mx.containers.VBox; + /** * Flex-related utility methods. */ @@ -111,5 +116,51 @@ public class FlexUtil component.includeInLayout = visible; return visible; } + + /** + * Creates a new container of the given class and adds the given children to it. + */ + public static function createContainer (clazz :Class, ...children) :Container + { + var container :Container = new clazz() as Container; + for each (var comp :UIComponent in children) { + container.addChild(comp); + } + return container; + } + + /** + * Creates a new HBox container and adds the given children to it. + */ + public static function createHBox (...children) :Container + { + children.unshift(HBox); + return createContainer.apply(null, children); + } + + /** + * Creates a new VBox container and adds the given children to it. + */ + public static function createVBox (...children) :Container + { + children.unshift(VBox); + return createContainer.apply(null, children); + } + + /** + * Creates a simple UIComponent that wraps a display object. + */ + public static function wrap (obj :DisplayObject) :FlexWrapper + { + return new FlexWrapper(obj); + } + + /** + * Creates a simple UIComponent that wraps a display object and inherits its size. + */ + public static function wrapSized (obj :DisplayObject) :FlexWrapper + { + return new FlexWrapper(obj, true); + } } }