Note that there are some explanatory texts on larger screens.

plurals
  1. POIn Actionscript 2, why is this TextField _height inconsistent?
    primarykey
    data
    text
    <p>I've created a dynamic text field, and set autoSize to true, so it can grow was tall as necessary. I then want to use the _height value to size a container graphic (speech bubble).</p> <p>Here's the (simplified) code:</p> <pre><code>var format:TextFormat = new TextFormat("Arial", 14); format.color = 0x000000; format.letterSpacing = -0.2; var txt:TextField = _root.createTextField("dialog_txt", 150, 10, 10, 150, 0); txt.multiline = true; txt.wordWrap = true; txt.autoSize = 'left'; txt.embedFonts = true; txt.selectable = false; txt.text = value; txt.setTextFormat(format); </code></pre> <p>I then try to set my container's height to the height of the textfield + 5, but it comes out way too short.</p> <pre><code>container._height = txt._height + 5; </code></pre> <p>I found that by adding <code>trace(txt._height)</code> before, the values come out right, even though the trace value is too small. Even just assigning the txt._height to a temp variable (<code>var junk=txt._height;</code>) fixes the problem. Replacing that with a couple trace functions:</p> <pre><code>trace(txt._height); //Note: No code between these two calls trace(txt._height); </code></pre> <p>Returns <code>19.6</code> followed immediately by <code>35.2</code>. It's as though reading <code>txt._height</code> causes it to recalculate, so it's correct the second time.</p> <p>I also tried the <code>textHeight</code> property, which also seems to get recalculated after <code>_height</code> is accessed. This sequence, for example:</p> <pre><code>trace(txt.textHeight); // Returns 15 trace(txt.textHeight); // Returns 15 trace(txt._height); // Returns 19.6 trace(txt.textHeight); // Returns 31 trace(txt._height); // Returns 35.2 </code></pre> <p>This is in AS 2, being compiled by <a href="http://www.mtasc.org/" rel="nofollow" title="MTASC">MTASC</a>.</p> <p>Any ideas on what's going on here?</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.
 

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