views:

75

answers:

3

When I add a ComboBox component into a Sprite, the height of the container is larger than it should.

Here's what I mean:

import fl.controls.ComboBox;
//add combo box inside a container sprite
var combo:ComboBox = new ComboBox();
var container:Sprite = new Sprite();
addChild(container);
container.addChild(combo);
//draw the outline of the container sprite
container.graphics.lineStyle(1,0x009900);
container.graphics.drawRect(0,0,container.width,container.height);
//I don't get this:
trace(combo.height);//outputs 22
trace(container.height);//outputs 101

Note: You will need the ComboBox component in your Library. I'm using Flash CS3 for this.

If I invalidate/redraw, like this:

combo.invalidate(InvalidationType.ALL,true);
combo.drawNow();

the height changes from 101 to 104.

Any solutions ?

UPDATE: I've overwritten the configUI method in a ComboBox subclass, but the measurements are correct all the time. Why does the container height change to 100 ?

A: 

So - I guess the displayed height of ComboBox is the actual height - id est, if it is opened, then the height WITH the drop down box, if not then WITHOUT. However - the items are STILL there, although with .visible set to false, which still expands the container, even if you can't see that... Therefore - I would say to do:

container.graphics.drawRect(0, 0, combo.width, combo.height);

That is the way to usually do it as well...

Aurel300
@Aurel300 Thanks for the input. I'm trying to put together a simple GUI. I want to use sprites to align components inside them(either vertically or horizontally). Say 'container' in my example would contained horizontally aligned components. If I were to add another container bellow it, I would set container2.y = container1.y+container.height,right ? Since container is giving me incorrect measurements, this aligning containers vertically would fail. About the dropdown List, not so sure you're right. If I set the rowCount to 2, that doesn't change anything, and by default(closed) it's not added
George Profenza
Still - this is a kind of bug... Maybe the .visible=false drop down is by default (before initialization) set to some value, and it is changed to the right size after... Not sure though - bugs, glitches - those annoying things are very hard to "reverse engineer" or even remotely understand if you don't have the source and/or can not debug it properly.
Aurel300
@Aurel300 It looks like a bug. The source is available(e.g. /Applications/Adobe\ Flash\ CS3/Configuration/Component\ Source/ActionScript\ 3.0/User\ Interface). A fix would be amazing, but all I'm expecting really is a workaround.
George Profenza
and what about **Flash CS5**?
Eugene
@Eugene Just tried that :( No luck. I've checked the source for the components and it looks like it hasn't changed much since Flash CS3. I'll need to dive deep and see where flash components measure the children sprites/components.
George Profenza
A: 

can you setup manually before this code:

container.width=100;

container.height=100;

container.graphics.drawRect(0,0,container.width,container.height);

Eugene
@Eugene not really :( If I set the height after the combo was added, the combo gets scaled down. If I set the height, before, while there is nothing added to container, it goes to 0 after I add the combo
George Profenza
explain please, what is your real goal?
Eugene
@Eugene I want to whip out a simple GUI with some comboboxes, text inputs, etc. I started adding components to the stage, but had problems with that, so I decided I to draw the GUI from code. I'm just nesting Sprites and trying to align them to get an HBox/VBox type of behavior. At the moment am having issues with the measures because of the ComboBox.
George Profenza
what if I'll advice you are flex with mxml, i think it will more powerful to cover your goals. Could you explain which component/GUI you are trying to build?
Eugene
+1  A: 

"if it is opened, then the height WITH the drop down box"

Hmm, I think when the list is added to the displayList below the button its actually added has a popup. So the height is supposed to remain the button height, since the sprite will never actually contain the drop-down list.

A possible reason the Container height could be wrong before it goes through any invalidation could be due to the children it contains. Maybe the combobox skin (could be a movieClip of 102px height) or a combobox sub-component that always start at 102px height or with weird height (TextField in a Button is known to be sometime wrong).

A simple solution would be to wait until a creationComplete/added event and see what is the final height, then draw the border.

Guillaume Malartre
I've looked at the component skins: the list component is 100x100. I subclassed ComboBox and in the 'overriden' configUI method, I've set the height to 22(setSize). If I draw the border in an event handler for Event.ADDED triggered by the combobox, the border still looks wrong. I added a timeout though, for 335 miliseconds and that seems to work, but it's a flakey workaround.
George Profenza
Have a look at validateNow() method http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/ComboBox.html#methodSummary
Guillaume Malartre
tried validateNow(), drawNow() without much luck :(
George Profenza