Re: [Flashcoders] text line overflow

2008-11-18 Thread Latcho

Hi Rob,
That is great and complete info !
I overlooked the possibility of getCharIndexAtPoint.
Thanks for the example, this will save me a lot of time.
Kind regards,
Latcho

Rob Romanek wrote:

Hi Latcho,

I see you've gotten a couple response but I'll throw another one in to 
the mix. The main functions that will interest you are:
1) getCharIndexAtPoint which locates the char at the edge of the 
textfield

2) replaceSelectedText which is used to substitute in ...

This is some code ripped out of a class I use that extends TextField 
and does a bunch of things for me, one of which is the truncation of 
text. It is not complete but should give you an idea for approaching 
this problem.


private var _htmlText:String = ; //holds the complete text for the 
field even when truncation occurs
private var _tempText:TextField = new TextField();; //another 
textField which is used to truncate the text and then place it into 
this actual field
private var _gutterCompensation:Number = -5; // -5 compensates for the 
gutter on either side of the text


private function checkDimensions(){
_htmlText = super.htmlText;
if(super.textWidth  width - _gutterCompensation){
//use the temporary text holder to do the text shortening and 
replacing

_tempText.htmlText = _htmlText;
_tempText.defaultTextFormat = super.defaultTextFormat; //this 
ensures that the ... are placed using the correct formatting
//find the character located at the edge of the text then count 
back 2 more characters and replace everything from there to the end 
with ...
_tempText.setSelection(super.getCharIndexAtPoint(width-_gutterCompensation, 
2)-2, super.text.length);

_tempText.replaceSelectedText(...);
super.htmlText = _tempText.htmlText;
}

Again is this an email/modified version so it is not complete just to 
give you ideas. (I don't remember if I really needed to use 
super.htmlText or could have gotten by with just this.htmlText)


Basically what I do is when the text field looses focus after editting 
I run the checkDimensions function which does my truncation but also 
stores the complete text. When the user brings the textfield back in 
to focus I replace the truncated text with the complete text I have 
stored.


hth,

Rob

On 17-Nov-08, at 4:26 AM, Latcho wrote:

How to break a line of text on the optimal charachter and adding 
... if it doesn't fit a single lined textfield

| I would like to break | this line of text.
| I would like to br... |

Any suggestions (AS3)

Latcho
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] text line overflow

2008-11-17 Thread Latcho
How to break a line of text on the optimal charachter and adding ... 
if it doesn't fit a single lined textfield

| I would like to break | this line of text.
| I would like to br... |

Any suggestions (AS3)

Latcho
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] text line overflow

2008-11-17 Thread Hans Wichman
Hi,

I've got an as2 implementation maybe you can convert it (and clean it:)):

//nametextfield contains actual text. Check what is smaller the actual
width of the textfield or a combo of the available width +
margin+dotwidth
//50 == margin, 20== correction, +5 == no clue old code;))
//so the actual width is the minimum of the textWidth and the given width
this.nameTextField._width = Math.min
(this.width-50-this.dotTextField._width,
this.nameTextField.textWidth+20)+5;
//position dots behind main textfield
this.dotTextField._x = this.nameTextField._x+this.nameTextField._width-2;
//determine visibility on whether text in nametextfield fits or not
this.dotTextField._visible = (this.nameTextField.textWidth 
this.nameTextField._width);

greetz
JC



On Mon, Nov 17, 2008 at 10:26 AM, Latcho [EMAIL PROTECTED] wrote:
 How to break a line of text on the optimal charachter and adding ... if it
 doesn't fit a single lined textfield
 | I would like to break | this line of text.
 | I would like to br... |

 Any suggestions (AS3)

 Latcho
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] text line overflow

2008-11-17 Thread Gregory Boland
Just find out how many characters fit into your allocated textfield space
then count the characters coming in


You could put the string of text that you want in the textfield into an
array that is broken by each word like this..

//str being the string that u want to work with
  _str_arr = str.split( );


Then character count each word till you reach the maximum your textfield
holds  
//keeps track of how many characters
var char_cnt:int = 0;

//limit is how many characters your textfield can hold
var limit:int = 50;

//new string array
newString_arr = new Array();

for(var z:int = 0; z  _str_arr.length; z++){
//want to keep count of each word and break when the char_cnt
//hits the limit
char_cnt += _str_arr[z].length;
//if the character count is equal or greater than the limit *
the num of lines, store that info
//and  break out of the for loop
if(char_cnt = limit){
newString_arr = _str_arr[z]);
break;
}
} 

Now u have a new array of words that fit into your textfield.  Concat them
together into a new string and put it into the textfeld.

In your new array if the last word in the element doesn't include a period
then you need to add the ...

Hope this helps

greg   

On 11/17/08 4:26 AM, Latcho [EMAIL PROTECTED] wrote:

 How to break a line of text on the optimal charachter and adding ...
 if it doesn't fit a single lined textfield
 | I would like to break | this line of text.
 | I would like to br... |
 
 Any suggestions (AS3)
 
 Latcho
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 
Gregory Boland | IconNicholson
Flash Engineer, Technology
[EMAIL PROTECTED]
tel +1 212.981.0563
mobile +1 201.600.6269
295 Lafayette Street, New York, NY 10012
 
www.iconnicholson.com
--
This communication may contain information that is confidential or exempt
from disclosure.  If you are not the intended recipient, please note that
any dissemination, distribution, or copying of this communication is
strictly prohibited. Anyone who receives this message in error should notify
the sender immediately by telephone or by return email and delete it from
his or her computer.


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] text line overflow

2008-11-17 Thread Rob Romanek

Hi Latcho,

I see you've gotten a couple response but I'll throw another one in to  
the mix. The main functions that will interest you are:
1) getCharIndexAtPoint which locates the char at the edge of the  
textfield

2) replaceSelectedText which is used to substitute in ...

This is some code ripped out of a class I use that extends TextField  
and does a bunch of things for me, one of which is the truncation of  
text. It is not complete but should give you an idea for approaching  
this problem.


private var _htmlText:String = ; //holds the complete text for the  
field even when truncation occurs
private var _tempText:TextField = new TextField();; //another  
textField which is used to truncate the text and then place it into  
this actual field
private var _gutterCompensation:Number = -5; // -5 compensates for the  
gutter on either side of the text


private function checkDimensions(){
_htmlText = super.htmlText;
if(super.textWidth  width - _gutterCompensation){
//use the temporary text holder to do the text shortening and replacing
_tempText.htmlText = _htmlText;
	_tempText.defaultTextFormat = super.defaultTextFormat; //this ensures  
that the ... are placed using the correct formatting
	//find the character located at the edge of the text then count back  
2 more characters and replace everything from there to the end with  
...
	_tempText.setSelection(super.getCharIndexAtPoint(width- 
_gutterCompensation, 2)-2, super.text.length);

_tempText.replaceSelectedText(...);
super.htmlText = _tempText.htmlText;
}

Again is this an email/modified version so it is not complete just to  
give you ideas. (I don't remember if I really needed to use  
super.htmlText or could have gotten by with just this.htmlText)


Basically what I do is when the text field looses focus after editting  
I run the checkDimensions function which does my truncation but also  
stores the complete text. When the user brings the textfield back in  
to focus I replace the truncated text with the complete text I have  
stored.


hth,

Rob

On 17-Nov-08, at 4:26 AM, Latcho wrote:

How to break a line of text on the optimal charachter and adding  
... if it doesn't fit a single lined textfield

| I would like to break | this line of text.
| I would like to br... |

Any suggestions (AS3)

Latcho
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders