16 Replies Latest reply on Jun 11, 2009 5:22 AM by ReaperMedia

    detect line break

    zibber Level 1
      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
        • 1. Re: detect line break
          kglad Adobe Community Professional & MVP
          flash has more than enough string methods to detect line breaks. what's the problem?
          • 2. Re: detect line break
            zibber Level 1
            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
            • 3. Re: detect line break
              kglad Adobe Community Professional & MVP
              try \r
              • 4. Re: detect line break
                zibber Level 1
                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 Adobe Community Professional & MVP
                  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 Level 1
                    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 Level 1
                      Doh I think I've been stupid:) in my ordering of things will confirm when home and hopefully close the thread thanks again
                      • 8. Re: detect line break
                        kglad Adobe Community Professional & MVP
                        you're welcome.
                        • 9. Re: detect line break
                          zibber Level 1
                          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 Adobe Community Professional & MVP
                            why are you adding a "*" to your textfield after the line break?
                            • 11. Re: detect line break
                              zibber Level 1
                              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 Level 1
                                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 Adobe Community Professional & MVP
                                  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
                                    Here's the hex code value for AS2 &#xA;
                                    • 15. Re: detect line break
                                      kglad Adobe Community Professional & MVP
                                      great first post, monkey.
                                      • 16. Re: detect line break
                                        ReaperMedia

                                        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.