Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you look at the <code>measure</code> method of <code>mx.controls.ComboBase</code>, you'll see that the the comboBox calculates it's <code>measuredMinWidth</code> as a sum of the width of the text and the width of the comboBox button.</p> <pre><code> // Text fields have 4 pixels of white space added to each side // by the player, so fudge this amount. // If we don't have any data, measure a single space char for defaults if (collection &amp;&amp; collection.length &gt; 0) { var prefSize:Object = calculatePreferredSizeFromData(collection.length); var bm:EdgeMetrics = borderMetrics; var textWidth:Number = prefSize.width + bm.left + bm.right + 8; var textHeight:Number = prefSize.height + bm.top + bm.bottom + UITextField.TEXT_HEIGHT_PADDING; measuredMinWidth = measuredWidth = textWidth + buttonWidth; measuredMinHeight = measuredHeight = Math.max(textHeight, buttonHeight); } </code></pre> <p>The <code>calculatePreferredSizeFromData</code> method mentioned by @defmeta (implemented in <code>mx.controls.ComboBox</code>) assumes that the data renderer is just a text field, and uses <code>flash.text.lineMetrics</code> to calculate the text width from label field in the <code>data</code> object. If you want to add an additional visual element to the item renderer and have the <code>ComboBox</code> take it's size into account when calculating it's own size, you will have to extend the <code>mx.controls.ComboBox</code> class and override the <code>calculatePreferredSizeFromData</code> method like so:</p> <pre><code> override protected function calculatePreferredSizeFromData(count:int):Object { var prefSize:Object = super.calculatePrefferedSizeFromData(count); var maxW:Number = 0; var maxH:Number = 0; var bookmark:CursorBookmark = iterator ? iterator.bookmark : null; var more:Boolean = iterator != null; for ( var i:int = 0 ; i &lt; count ; i++) { var data:Object; if (more) data = iterator ? iterator.current : null; else data = null; if(data) { var imgH:Number; var imgW:Number; //calculate the image height and width using the data object here maxH = Math.max(maxH, prefSize.height + imgH); maxW = Math.max(maxW, prefSize.width + imgW); } if(iterator) iterator.moveNext(); } if(iterator) iterator.seek(bookmark, 0); return {width: maxW, height: maxH}; } </code></pre> <p>If possible store the image dimensions in the data object and use those values as <code>imgH</code> and <code>imgW</code>, that will make sizing much easier.</p> <p>EDIT: </p> <p>If you are adding elements to the render besides an image, like a label, you will also have to calculate their size as well when you iterate through the data elements and take those dimensions into account when calculating <code>maxH</code> and <code>maxW</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload