Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

detect line break

Guest
Aug 22, 2008 Aug 22, 2008
Hi I wondered if anyone could help. As my deadline is looming to a dangerous point and im stuck:|


I have a dynamic text field in flash that is populated by an input box.

The dynamic text field has a maxmium width it can be. So i have it as multiline WITH wodrwap on.

My problem is that I have to send this data to server and for the php to be able to text the text and output the text as it is displayed in flash.

There seems to be no way of finding the linebreaks and passing them in the string as far as I can see? Does anyone have any ideas on this or a workaround?

The noose is tightening.

thx in advance

ade
TOPICS
ActionScript
4.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jun 11, 2009 Jun 11, 2009

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.

Translate
Community Expert ,
Aug 23, 2008 Aug 23, 2008
flash has more than enough string methods to detect line breaks. what's the problem?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 24, 2008 Aug 24, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2008 Aug 24, 2008
try \r
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 24, 2008 Aug 24, 2008
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 24, 2008 Aug 24, 2008
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2008 Aug 25, 2008
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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2008 Aug 25, 2008
Doh I think I've been stupid:) in my ordering of things will confirm when home and hopefully close the thread thanks again
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2008 Aug 25, 2008
you're welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2008 Aug 25, 2008
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:~

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2008 Aug 25, 2008
why are you adding a "*" to your textfield after the line break?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2008 Aug 25, 2008
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?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 28, 2008 Aug 28, 2008
Here's the hex code value for AS2 &#xA;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 25, 2008 Aug 25, 2008
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2008 Aug 25, 2008
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2008 Aug 29, 2008
great first post, monkey.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 11, 2009 Jun 11, 2009
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines