RE: [Flashcoders] Measuring width of some text
Strangely, the TextField.textWidth property returns different values on different systems. On WIN IE v6.0.2900 Service Pack 2 with Flash Player Version 8,0,24 textWidth is consistently larger than on WIN IE v6.0.2800 Service Pack 1 with Flash Player 8,0,22. Are the different values of textWidth the result of different IE/Service Pack versions, or the result of different Flash Player minor versions? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Van De Velde Hans Sent: Friday, December 22, 2006 5:56 AM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Measuring width of some text Just a txt.textWidth should do the trick -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Perdue, Blake Sent: donderdag 21 december 2006 22:28 To: flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] Measuring width of some text I need to measure the width of some text. Here's the function I'm using: private function getTextWidth(txt,fontSize) { var fmt=new TextFormat(); fmt.font='Univers 67 CondensedBold'; fmt.size=fontSize; fmt.autoSize='left'; var metrics=fmt.getTextExtent(txt); return metrics.textFieldWidth; } This function is not predictable - for the same text, it returns different numbers on different OSes or flash player versions: - works fine in IE/FF for flash player 6 - doesn't work in Mac Safari for flash player 6 - works fine in IE/FF for flash player 8 using Service Pack 1 - doesn't work for IE/FF for flash player 8 using Service Pack 2 Is there another function I can use, or another way to go about measuring the width of some text? Blake Perdue | 212.522.1292 | AIM: blakepCNN ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] Measuring width of some text
Just a txt.textWidth should do the trick -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Perdue, Blake Sent: donderdag 21 december 2006 22:28 To: flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] Measuring width of some text I need to measure the width of some text. Here's the function I'm using: private function getTextWidth(txt,fontSize) { var fmt=new TextFormat(); fmt.font='Univers 67 CondensedBold'; fmt.size=fontSize; fmt.autoSize='left'; var metrics=fmt.getTextExtent(txt); return metrics.textFieldWidth; } This function is not predictable - for the same text, it returns different numbers on different OSes or flash player versions: - works fine in IE/FF for flash player 6 - doesn't work in Mac Safari for flash player 6 - works fine in IE/FF for flash player 8 using Service Pack 1 - doesn't work for IE/FF for flash player 8 using Service Pack 2 Is there another function I can use, or another way to go about measuring the width of some text? Blake Perdue | 212.522.1292 | AIM: blakepCNN ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Measuring width of some text
getTextExtent() is really unpredictable and it works properly only with flash player ver 7 or higher. Adobe document says its been deprecated since flash player 8, but i dont think so and their doc must have wrongly said so. anyway, heres another approach where textWidth and textHeight properties of textField have been utilised. var my_str:String = Sample text; var fmt:TextFormat = new TextFormat(); function getTextWidthAndHeight(txt, fmt, fontsize) { fmt.font = Arial; fmt.bold = true; fmt.size = fontsize; this.createTextField(dummyTF, this.getNextHighestDepth(), 1, 1, 100, 100); dummyTF.text = txt; dummyTF.setTextFormat(fmt); var o = new Object(); o.Width = dummyTF.textWidth; o.Height = dummyTF.textHeight; removeMovieClip(dummyTF); return o; } var dimensionInfo = getTextWidthAndHeight(my_str, fmt, 12); this.createTextField(newTField, this.getNextHighestDepth(), 100, 100, dimensionInfo.Width+4, dimensionInfo.Height+4); newTField.border = true; newTField.wordWrap = true; newTField.text = my_str; newTField.setTextFormat(fmt); Hope this helps, and plz give the feedback. Arindam Perdue, Blake [EMAIL PROTECTED] wrote: I need to measure the width of some text. Here's the function I'm using: private function getTextWidth(txt,fontSize) { var fmt=new TextFormat(); fmt.font='Univers 67 CondensedBold'; fmt.size=fontSize; fmt.autoSize='left'; var metrics=fmt.getTextExtent(txt); return metrics.textFieldWidth; } This function is not predictable - for the same text, it returns different numbers on different OSes or flash player versions: - works fine in IE/FF for flash player 6 - doesn't work in Mac Safari for flash player 6 - works fine in IE/FF for flash player 8 using Service Pack 1 - doesn't work for IE/FF for flash player 8 using Service Pack 2 Is there another function I can use, or another way to go about measuring the width of some text? Blake Perdue | 212.522.1292 | AIM: blakepCNN ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com Send instant messages to your online friends http://asia.messenger.yahoo.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com