This content has been marked as final.
Show 16 replies
-
1. Re: detect line break
kglad Aug 23, 2008 10:42 AM (in response to zibber)flash has more than enough string methods to detect line breaks. what's the problem? -
2. Re: detect line break
zibber Aug 24, 2008 3:35 AM (in response to kglad)Hi again
The problem is that I have tried to detect line breaks in the text field and I just cant seem to get to them:|
I have tried (trace(testField.text.indexOf('\n'))) aswell as newline etc and it always returns a -1.
As mentioned in original post. The textfield is a fixed width with wordwrap set to true. I read somewhere that wordwrap somehow makes the linebreaks undetectable? I am hoping this isn't the case. All i need to be able to is send the contents of the textfield to a php page with the linebreaks included. Any help on this would be great. This is as2 targetting flashlite 2.1.
thx in advance -
-
4. Re: detect line break
zibber Aug 24, 2008 10:44 AM (in response to kglad)I have tried and no dice. To try and be clear I have a text field on stage say 160 pixels wide. I type copy in say a thirty h's. Say fifteen fit on first line and rest push onto second. I need to be able to send to server the linebreak flash has placed in there. /n first exist I'm there and /r only exists at the very end of the text. It's driving me nuts -
5. Re: detect line break
kglad Aug 24, 2008 3:42 PM (in response to zibber)oh. you'll need to create a custom function to do that.
duplicate your textfield and its properties (which can all be automated using actionscript) except enable the duplicate's autoSize property, don't assign text/htmlText, yet and assign its _height to be small like 10.
then start assigning text one character at a time until your textfield's bottomScroll property increments. at that point is a line break. -
6. Re: detect line break
zibber Aug 25, 2008 2:54 AM (in response to kglad)Hi again
Firstly kglad, many thanks for your help, it is very much appreciated.
I have implemented your suggestion and it is pretty much there. However, there seems to be a slight lag in the processing which results in the pseudo line break characters being added a few characters late. Taking font embedding off the fields has improved this, but it it is still out enough that it will screw up my text rendeing when its passed to the server.
My code is as below:
origStr = orig.text
origStrLength = origStr.length;
currentScroll = 1
newText.autoSize = true;
newText.wordWrap = true;
temp_str = "";
for (var i=0; i < origStrLength; i++ ){
temp_str += origStr.charAt(i)
newText.text = temp_str;
amount = newText.bottomScroll;
if(amount > currentScroll){
temp_str += "*"
currentScroll ++;
trace("insertLineBreak" + currentScroll)
}
}
The textfields have the same properties, namely multiline is set and thats it. As mentioend I have removed font embedding, but would ideally need this atleast for the original text box. I can work around that but the slippage in positioning of the linebreak is a real problem still. And more worrying if it is down to horsepower is this will be running on mobiles.
any further help would be fantastic
-
7. Re: detect line break
zibber Aug 25, 2008 4:47 AM (in response to zibber)Doh I think I've been stupid:) in my ordering of things will confirm when home and hopefully close the thread thanks again -
-
9. Re: detect line break
zibber Aug 25, 2008 6:51 AM (in response to kglad)nope, sorry kglad Im still not there:(
I cannto sem to get it right the linebreak text i place in is either 1 char or out. Code is below:
origStr = orig.text
origStrLength = origStr.length;
currentScroll = 1
newText.autoSize = true;
newText.wordWrap = true;
//temp_str = "";
for (var i=0; i < origStrLength; i++ ){
if(amount > currentScroll){
newText.text += "*"
currentScroll = amount;
newText.text += origStr.charAt(i)
} else {
newText.text += origStr.charAt(i)
//newText.text = temp_str;
amount = newText.bottomScroll;
}
amount = newText.bottomScroll;
}
I know this must be something really stupid, but i just cant see it:~
-
10. Re: detect line break
kglad Aug 25, 2008 6:54 AM (in response to zibber)why are you adding a "*" to your textfield after the line break? -
11. Re: detect line break
zibber Aug 25, 2008 7:37 AM (in response to kglad)because i thought the idea was that I needed to add a line break or a marker for a linebreak into the new string/text field based on when the new text field started a new line? is this not the case? -
12. Re: detect line break
zibber Aug 25, 2008 7:40 AM (in response to zibber)to add: i was using the asterix as a marker just to see if it was placed in the correct position but it is always one character late. -
13. Re: detect line break
kglad Aug 25, 2008 8:27 AM (in response to zibber)well, you're adding it after the line break, so that's probably not what you want.
generally, after finding the "word" where the break occurs you go to a subfunction and find the previous "word". between the two is where you denote the line break. -
14. Re: detect line break
monk3y29 Aug 28, 2008 1:42 PM (in response to zibber)Here's the hex code value for AS2 
 -
15. Re: detect line break
kglad Aug 29, 2008 7:43 AM (in response to zibber)great first post, monkey. -
16. Re: detect line break
ReaperMedia Jun 11, 2009 5:22 AM (in response to zibber)Worked it out guys:
you find the line breaks, however you loose the actual break and replace it with whatever you want (eg. "<br>")
This is all the text you need:
origStr = orig.text newMessage = origStr.split('\r').join('<br>'); newText.text = newMessage
Input:
Hi There How Are You?
Output:
Hi<br>There<br><br>How Are You?
It's funny how "\r" works and "/r", "/n" and "\n" don't.