     					if (isNaN(mr))
     						mr = 0;
     				}
-                    child.x = ml;
                     if (child is ILayoutChild)
                     {
                         ilc = child as ILayoutChild;
                         if (!isNaN(ilc.percentWidth))
-                            ilc.setWidth(contentView.width * ilc.percentWidth / 100, true);
+                            ilc.setWidth(contentView.width * ilc.percentWidth / 100, !isNaN(ilc.percentHeight));
                     }
+                    setPositionAndWidth(child, left, ml, right, mr, w);
                     maxWidth = Math.max(maxWidth, ml + child.width + mr);
                     child.y = hh - child.height - mb;
     				hh -= child.height + mt + mb;
     				lastmt = mt;
-                    halign = ValuesManager.valuesImpl.getValue(child, "horizontal-align");
-                    horizontalMargins[i] = { marginLeft: ml, marginRight: mr, halign: halign };
     			}
-            
-                child = contentView.getElementAt(flexChildIndex) as IUIBase;
-                margin = ValuesManager.valuesImpl.getValue(child, "margin");
-                if (margin is Array)
-                {
-                    if (margin.length == 1)
-                        marginLeft = marginTop = marginRight = marginBottom = margin[0];
-                    else if (margin.length <= 3)
-                    {
-                        marginLeft = marginRight = margin[1];
-                        marginTop = marginBottom = margin[0];
-                    }
-                    else if (margin.length == 4)
-                    {
-                        marginLeft = margin[3];
-                        marginBottom = margin[2];
-                        marginRight = margin[1];
-                        marginTop = margin[0];					
-                    }
-                }
-                else if (margin == null)
-                {
-                    marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left");
-                    marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top");
-                    marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right");
-                    marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom");
-                }
-                else
-                {
-                    marginLeft = marginTop = marginBottom = marginRight = margin;
-                }
-                mt = Number(marginTop);
-                if (isNaN(mt))
-                    mt = 0;
-                mb = Number(marginBottom);
-                if (isNaN(mb))
-                    mb = 0;
-                if (marginLeft == "auto")
+            } 
+            
+            child = contentView.getElementAt(flexChildIndex) as IUIBase;
+            ilc = child as ILayoutChild;
+            left = ValuesManager.valuesImpl.getValue(child, "left");
+            right = ValuesManager.valuesImpl.getValue(child, "right");
+            margin = ValuesManager.valuesImpl.getValue(child, "margin");
+            if (margin is Array)
+            {
+                if (margin.length == 1)
+                    marginLeft = marginTop = marginRight = marginBottom = margin[0];
+                else if (margin.length <= 3)
+                {
+                    marginLeft = marginRight = margin[1];
+                    marginTop = marginBottom = margin[0];
+                }
+                else if (margin.length == 4)
+                {
+                    marginLeft = margin[3];
+                    marginBottom = margin[2];
+                    marginRight = margin[1];
+                    marginTop = margin[0];					
+                }
+            }
+            else if (margin == null)
+            {
+                marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left");
+                marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top");
+                marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right");
+                marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom");
+            }
+            else
+            {
+                marginLeft = marginTop = marginBottom = marginRight = margin;
+            }
+            mt = Number(marginTop);
+            if (isNaN(mt))
+                mt = 0;
+            mb = Number(marginBottom);
+            if (isNaN(mb))
+                mb = 0;
+            if (ilc)
+            {
+                if (!isNaN(ilc.percentHeight))
+                    ilc.setHeight(contentView.height * ilc.percentHeight / 100, !isNaN(ilc.percentWidth));
+            }
+            if (marginLeft == "auto")
+                ml = 0;
+            else
+            {
+                ml = Number(marginLeft);
+                if (isNaN(ml))
                     ml = 0;
-                else
-                {
-                    ml = Number(marginLeft);
-                    if (isNaN(ml))
-                        ml = 0;
-                }
-                if (marginRight == "auto")
+            }
+            if (marginRight == "auto")
+                mr = 0;
+            else
+            {
+                mr = Number(marginRight);
+                if (isNaN(mr))
                     mr = 0;
-                else
-                {
-                    mr = Number(marginRight);
-                    if (isNaN(mr))
-                        mr = 0;
-                }
-                child.x = ml;
-                if (child is ILayoutChild)
-                {
-                    ilc = child as ILayoutChild;
-                    if (!isNaN(ilc.percentWidth))
-                        ilc.setWidth(contentView.width * ilc.percentWidth / 100, true);
-                }
-                maxWidth = Math.max(maxWidth, ml + child.width + mr);
-                child.y = yy + mt;
-                child.height = hh - yy - mb;
-                halign = ValuesManager.valuesImpl.getValue(child, "horizontal-align");
-                horizontalMargins[flexChildIndex] = { marginLeft: ml, marginRight: mr, halign: halign };
-            }
-            
-            for (i = 0; i < n; i++)
-			{
-				var obj:Object = horizontalMargins[0]
-				child = contentView.getElementAt(i) as IUIBase;
-				if (obj.halign == "center")
-					child.x = (maxWidth - child.width) / 2;
-				else if (obj.halign == "bottom")
-					child.x = maxWidth - child.width - obj.marginRight;
-				else
-					child.x = obj.marginLeft;
-			}
+            }
+            if (child is ILayoutChild)
+            {
+                ilc = child as ILayoutChild;
+                if (!isNaN(ilc.percentWidth))
+                    ilc.setWidth(contentView.width * ilc.percentWidth / 100, !isNaN(ilc.percentHeight));
+            }
+            setPositionAndWidth(child, left, ml, right, mr, w);
+            maxWidth = Math.max(maxWidth, ml + child.width + mr);
+            child.y = yy + mt;
+            child.height = hh - yy - mb;
+            
             return true;
 		}
 
-        // TODO (aharui): utility class or base class
-        /**
-         *  Determines the top and left padding values, if any, as set by
-         *  padding style values. This includes "padding" for all padding values
-         *  as well as "padding-left" and "padding-top".
-         * 
-         *  Returns an object with paddingLeft and paddingTop properties.
-         *  
-         *  @langversion 3.0
-         *  @playerversion Flash 10.2
-         *  @playerversion AIR 2.6
-         *  @productversion FlexJS 0.0
-         */
-        protected function determinePadding():Object
-        {
-            var paddingLeft:Object;
-            var paddingTop:Object;
-            var paddingRight:Object;
-            var padding:Object = ValuesManager.valuesImpl.getValue(host, "padding");
-            if (typeof(padding) == "Array")
-            {
-                if (padding.length == 1)
-                    paddingLeft = paddingTop = paddingRight = padding[0];
-                else if (padding.length <= 3)
-                {
-                    paddingLeft = padding[1];
-                    paddingTop = padding[0];
-                    paddingRight = padding[1];
-                }
-                else if (padding.length == 4)
-                {
-                    paddingLeft = padding[3];
-                    paddingTop = padding[0];					
-                    paddingRight = padding[1];
-                }
-            }
-            else if (padding == null)
-            {
-                paddingLeft = ValuesManager.valuesImpl.getValue(host, "padding-left");
-                paddingTop = ValuesManager.valuesImpl.getValue(host, "padding-top");
-                paddingRight = ValuesManager.valuesImpl.getValue(host, "padding-right");
-            }
-            else
-            {
-                paddingLeft = paddingTop = paddingRight = padding;
-            }
-            var pl:Number = Number(paddingLeft);
-            var pt:Number = Number(paddingTop);
-            var pr:Number = Number(paddingRight);
-            if (isNaN(pl))
-                pl = 0;
-            if (isNaN(pr))
-                pr = 0;
-            if (isNaN(pt))
-                pt = 0;
-            return {paddingLeft:pl, paddingTop:pt, paddingRight:pr};
-        }
-
+        private function setPositionAndWidth(child:IUIBase, left:Number, ml:Number,
+                                             right:Number, mr:Number, w:Number):void
+        {
+            var widthSet:Boolean = false;
+            
+            var ww:Number = w;
+            var ilc:ILayoutChild = child as ILayoutChild;
+            if (!isNaN(left))
+            {
+                child.x = left + ml;
+                ww -= left + ml;
+            }
+            else 
+            {
+                child.x = ml;
+                ww -= ml;
+            }
+            if (!isNaN(right))
+            {
+                if (!isNaN(left))
+                {
+                    if (ilc)
+                        ilc.setWidth(ww - right - mr, true);
+                    else
+                    {
+                        child.width = ww - right - mr;
+                        widthSet = true;
+                    }
+                }
+                else
+                    child.x = w - right - mr - child.width;
+            }
+            if (ilc)
+            {
+                if (!isNaN(ilc.percentWidth))
+                    ilc.setWidth(w * ilc.percentWidth / 100, true);
+            }
+            if (!widthSet)
+                child.dispatchEvent(new Event("sizeChanged"));
+        }
+        
         public function setDocument(document:Object, id:String = null):void
         {
             this.document = document;	

            var lastmb:Number;
            var lastmt:Number;
            var halign:Object;
            
            for (var i:int = 0; i < n; i++)
            {
                var child:IUIBase = contentView.getElementAt(i) as IUIBase;
                if (child == actualChild)
                {
                    flexChildIndex = i;

                mb = Number(marginBottom);
                if (isNaN(mb))
                    mb = 0;
                if (ilc)
                {
                    if (!isNaN(ilc.percentHeight))
                        ilc.setHeight(contentView.height * ilc.percentHeight / 100, !isNaN(ilc.percentWidth));
                }
                if (marginLeft == "auto")
                    ml = 0;
                else
