4 Replies Latest reply on Jun 25, 2007 11:36 AM by BeniRose

    Whitespace holding true in htmlText

    BeniRose Level 1
      I'm coding a site in AS2 that pulls all the content from an XML file, which holds HTML inside <![CDATA[ tags. As it should, the XML file has tab formatting to align the levels. However, when I do tabs and even carriage returns inside my CDATA, and then set the htmlText attribute of a TextField to what's in the CDATA, all the tabs and carriage returns are being displayed. I even made a little test flash file and it's still happening. You download the test FLA at [L]http://argentumwebs.com/flashjunk/html_test.fla[/L] and the xml file driving it can be found at [L]http://argentumwebs.com/flashjunk/content.xml[/L]. If you don't want to download it then place the attached code in frame 1 of an empty movie and create an XML file as well. Thanks in advance.
        • 1. Re: Whitespace holding true in htmlText
          Level 7
          >>However, when I do tabs and even carriage returns inside my CDATA, and
          >>then set the htmlText attribute of a TextField to what's in the
          CDATA, all the tabs and carriage returns are being displayed.

          Don't do that. Formatting of your CDATA element should be taken care of by
          the HTML attributes you're using, not by putting tabs and breaks in the
          text.

          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Whitespace holding true in htmlText
            BeniRose Level 1
            I am formatting my CDATA element with HTML, which is then going into the HTML text. However, I want to format my XML file with tabs and whitespaces, so it's readable. I also want to format the CDATA so it's readable, the same way you would use tabs and carriage returns in a regular HTML file. I should be able to make my CDATA readable and not have it effect the textField, especially since I'm setting .htmlText and not .text. I'm pretty sure if I put whitespace and carriage returns in an external file and then load it in using loadVariables() into the .htmlText attribute of a textField, it doesn't effect my formatting of the textField, so why does it in CDATA?
            • 3. Re: Whitespace holding true in htmlText
              Beatie3 Level 1
              I've been playing with exactly the same problem in the last couple of weeks. This is Antonio de Donatis' solution and it works fine when loading simple text files. Hope it helps:
              • 4. Re: Whitespace holding true in htmlText
                BeniRose Level 1
                I suppose we could call this a "fix"! I'm not sure why it's showing up to begin with. I've expanded it to include tabs

                .split("\r\n").join("").split("\t").join("")

                I guess this is also the alternative because there's no replace function for strings in flash AS 2.0. I just hope there's never a time when there's a \n without an \r or vice versa.