tim richter

An Vbox arranges its child components vertically according to their desired size. If the size is is declared in percentage values, it will set the components bounds percentaged to the space left filled by fixed size components.

NOTE: percentaged values of child components are just handled if the desired size of the VBox was set explicitly.

For a detailed view on the component/container structure see AS3-Layout-Framework.

The following example demonstrates a basic usage of the VBox:

 
package
{
	import com.addicted2flash.layout.component.Application;
	import com.addicted2flash.layout.component.VBox;
 
	/**
	 * @author Tim Richter
	 */
	public class VBoxTest extends Application
	{
		public function VBoxTest()
		{
			super( Application.ABSOLUTE );
 
			var box: VBox = new VBox();
			box.add( new SimpleComponent( 100, 100 ) );
			box.add( new SimpleComponent( 50, 100 ) );
			box.add( new SimpleComponent( 100, 150 ) );
 
			//-- add hbox to the application container
			container.add( box );
		}
	}
}
 

SimpleComponent.as

 
package
{
	import com.addicted2flash.layout.core.Component;
 
	import flash.display.Graphics;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;	
 
	/**
	 * @author Tim Richter
	 */
	public class SimpleComponent extends Component
	{
		private static var _id: int = 0;
		private var _tField: TextField;
 
		public function SimpleComponent( w: Number, h: Number )
		{
			desiredWidth = w;
			desiredHeight = h;
 
			_tField = new TextField( );
			_tField.autoSize = TextFieldAutoSize.CENTER;
			_tField.selectable = false;
			_tField.textColor = 0x999999;
			_tField.text = ( _id++ ).toString();
 
			display.addChild( _tField );
		}
 
		override public function arrange(): void
		{
			var g: Graphics = display.graphics;
			g.clear();
			g.beginFill( 0xccff00 );
			g.drawRect( 0, 0, width, height );
			g.endFill();
 
			_tField.x = ( width - _tField.textWidth ) * 0.5;
			_tField.y = ( height - _tField.textHeight ) * 0.5;
		}
	}
}
 
7 COMMENTS
September 23, 2009
ad

Nice to see a simple lightweight layout framework. Would be great as a feature request is to have float items. By this I mean, set a desired width on a VBox and then fill it full of components, if these components are smaller than the desired width and fits another component next to it, then display them inline. Bit like how CSS when you float left and display inline.

I thinking of extending the class to enable this, but the VBox has BoxLayout hardcoded in the constructor. So I guess I could make a VBoxInline (or another name ;-) ) so I can swap out the layout.

I didn’t really want to start messing about with the code, although if / when I get around to it I will push it to you to see if it could be incorporated as it should be quite clean and tidy (hopefully!)

tim
September 30, 2009
ad

Hi Simon,

thanks for your comment. Please take a look at the FlowBox, perhaps it will fulfill your needs.

October 3, 2009
ad

Hi tim,

It did indeed fulfill my requirements. Worked like a charm ;-)

I like then new features as well (good to see the framework is always evolving), but I notice lock and unlock has vanished. Are they ever coming back, because I will just remove from my code if they’ve gone.

Out of interest why did they disappear ?

Cheers
Simon

tim
October 8, 2009
ad

Hi Simon,

you are right. I just removed these methods. There are not needed anymore. I have implemented an validation mechanism based on the Stage.RENDER event, so all components are just arranged at a frame, when flash will repaint the screen. This mechanism is therefore asynchron and you can now invoke add/remove or set properties of the components multiple times and there will only be one invalidation (measure/arrange in component).

Another change was to encapsulate the DisplayObject from the Component itself. Every component has a explicit getter for display (an Sprite) now.

October 12, 2009
ad

Hi tim,

Cheers for the response. I’m a big fan of the new DisplayObject ecapsulation, spotted that straight away, makes perfect sense.

Cheers
Simon

March 25, 2010
ad

Hi Tim,
i want to embed a .swc file and then remove it from the display at the tick of an event. i am using hBox is flex to embed the source. Can i do the same using HBox ?

tim
March 28, 2010
ad

hi shrikant,

the HBox has a field display which is of type Sprite, so you can add any display object to it (and of course remove it). Hope this was useful. If not, please be a bit more precise.

regards
tim

Post a comment