TextFormat.getTextExtent() forgets text

TextFormat.getTextExtent() forgets text

Post by Mark Bagna » Sat, 29 Apr 2006 22:12:41


Hi

As part of a larger printing problem (involving printing dynamic text without
scrolling problems), I have created an empty movie clip (printClip) and inside
an empty text field (printArea). However, the text field seems to be forgotten
by Flash after using the TextFormat.getTextExtent() function meaning I can't
access the text (please see code).

Does anyone know why this is happening and how it can be resolved?

Thanks
Mark

// create printClip, printArea and set parameters
var tf:TextFormat = printClip.printArea.getTextFormat();
trace("clip = "+typeof (printClip.printArea)); // displays: clip = object
var extent:Object = tf.getTextExtent(printClip.printArea.text,
printClip.printArea._width);
trace("clip = "+typeof (printClip.printArea)); // displays: clip = undefined
 
 
 

TextFormat.getTextExtent() forgets text

Post by babo_y » Sat, 29 Apr 2006 23:31:02

Does this work if the printArea textfield is NOT empty?

 
 
 

TextFormat.getTextExtent() forgets text

Post by Mark Bagna » Sat, 29 Apr 2006 23:46:04

I did put some text in printArea (sorry I didn't state that). Here's the 'full'
code (minus any irrelevant lines to this problem). You should be able to put
all this in a new Flash document and test it. Thanks for your help.

var printClip = createEmptyMovieClip("printClip", getNextHighestDepth());
printClip.createTextField("printArea", printClip.getNextHighestDepth(), 10,
10, 100, 0);
printClip.printArea.text = "Here is some text.";
trace("text = "+printClip.printArea.text); // text = Here is some text.

var tf:TextFormat = printClip.printArea.getTextFormat();
trace("clip = "+typeof (printClip.printArea)); // clip = object
var extent:Object = tf.getTextExtent(printClip.printArea.text,
printClip.printArea._width);
trace("clip = "+typeof (printClip.printArea)); // clip = undefined
 
 
 

TextFormat.getTextExtent() forgets text

Post by babo_y » Sat, 29 Apr 2006 23:50:50

text = Here is some text.
clip = object
clip = object

I copied your code and pasted and that's what I get.
 
 
 

TextFormat.getTextExtent() forgets text

Post by Mark Bagna » Sun, 30 Apr 2006 00:19:13

After you said you couldn't duplicate the problem, I tried it myself in a blank
fla, which worked. Then I dragged a Button component onto the stage and tried
again - this time it didn't work! Curiouser and curiouser...
 
 
 

TextFormat.getTextExtent() forgets text

Post by kgla » Sun, 30 Apr 2006 09:33:21

oh, it's another component issue. there are so many of them i can't keep track of them all.