> Hi Danny, it would be multi line text and I don't know if it > will be center aligned. Maybe some parts will be. I didn't > really get the technique you described. Can you please try > and describe it again? Or is it possible that you share the > code that you have? I can even compensate it somehow if it gets used.
My code is a bit complicated but the key function is this (warning: untested email version; only works on left-aligned fields with a single text format - no HTML. Also probably needs a bit of adjusting to take margins into account. All these issues are fixable if necessary!): function charToLoc(tPos:Number, tField:TextField):Object { // this returns an object {x:..., y:...} - it could be a Point object if you wanted // find the text to look at and create a new textField for testing var tTempField:TextField = tField._parent.createNewTextField("temp", tField._parent.getNextHighestDepth) var tFormat:TextFormat = tField.getTextFormat() var tText:String = tField.text.substr(0, tPos) // first find the bottom of the line: var tStartOfLine:Number = lastCharBeforeLine(tText, tTempField, tFormat) // now we know the y position var tY:Number = 0) if (tStartOfLine > 0) { tTempField.text = tText.substr(0,tStartOfLine) tTempField.setTextFormat(tFormat) tY = tTempField.textHeight } // and the x position is got from the width of the remaining text tTempField.text = tText.substr(tStartOfLine) tTempField.setTextFormat(tFormat) return {x: tTempField.textWidth, y:tY} } function lastCharBeforeLine(tText:String, tTempField:TextField, tFormat:TextFormat):Number { // get hald the line height tTempField.text = "Ay" tTempField.setTextFormat(tFormat) var tHalfLine:Number = tTempField.textHeight/2 tTempField.text = tText tTempField.setTextFormat(tFormat) var tBottom:Number = tTempField.textHeight - tHalfLine var tMax:Number = tText.length var tInterval:Number = 16 // find an interval during which the line drops do { var tMin:Number = Math.max(tMax - tInterval, 0) tTempField.text = tText.substr(0,tMin) tTempField.setTextFormat(tFormat) } while (tTempField.textHeight > tBottom && tMin>0) if (tMin == 0) { //we're on the first line return 0 } // otherwise home in on the point at which the line drops while (tInterval>1) { tInterval /= 2 var tMid:Number = tMin + tInterval tTempField.text = tText.substr(0,tMid) tTempField.setTextFormat(tFormat) if (tTempField.textHeight < tBottom) { tMin = tMid } } return tMin } I'll leave it up to you to adapt these for your purposes; I hope they help. Best Danny _______________________________________________ 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