views:

26

answers:

1

Ok, I have no idea why this is happening.

I'm made an Item class which extends the Sprite class, the Item class basically has a few checkmarks & labels at the moment.

Then what I try to do is run through a for loop of items and create Item classes that I want to place one after each other on the y-axis, so I'm reading the Item.height property to find the y of the next Item in the list.

The problem is for some reason there is always an extra 75 pixels added to the Sprite height at the bottom, no matter how many checkmarks and labels are in each Item class ( varying the height of the Item class ).

Any idea why this is being added and how it can be removed?

I'm having trouble figuring this out, I tried dynamicly calculating and setting the Item.height property but when I do that the Sprite is simply cropped.

+1  A: 

It takes one or two frames until the size of an UI component is correctly set (the default height is 100 pixels).

To prevent this behavior call validateNow() on each Flash UI component you add.

var s:Sprite = new Sprite();
var label:Label = new Label();
label.text = "hello";
label.x = 0;
s.addChild(label);
var check:CheckBox = new CheckBox();
check.label = "hello";
check.x = 50;
s.addChild(check);
addChild(s);
trace(s.height); // output: 100

label.validateNow();
check.validateNow();
trace(s.height); // output: 28
Claus Wahlers
Thanks, thats the type of thing you gain with experience.
Emil