1 Reply Latest reply on Apr 17, 2006 7:44 PM by Rothrock

    Loading Text w/ Formatting

      Trying to load text depending on state that people choose. However, to keep my formatting I input html code into a text file then used the following code:

      on (release) {
      var txt_xml = new XML();
      _root.text_mc.rep_txt.html = true;
      txt_xml.onLoad = function () {
      _root.text_mc.rep_txt.htmlText = txt_xml;

      However, the only text that loads is between the <title> </title> tags.
      And also, <p> </p> tags present single line return, while </br> present double returns.

      I may be code-retarded, but shouldn't html just be uniform? I thought that was the whole point.
        • 1. Re: Loading Text w/ Formatting
          Rothrock Level 5
          I think you are code-retarded. I'm just joking. But if <p> gives single line returns and </br> presents double returns and they always do that, then I would call that uniform, not just what you wanted!

          I'm thinking there are several issues going on here. First I would call my file "new2.xml" just so you know that it is xml.

          Next, I've never used the XML class without myXML.ignorewhite=true

          So unless your file is not human readable you will need that.

          Next is that I don't think you can just assign a whole XML object to a text field's htmlText property and get the results you want. (BTW, here is a good think you have done correctly. You did enable html AND you assigned the htmlText property, not just the regular text property. Good job!)

          So you will need to get the values of the nodes. Check the XML entries in the help files. Since your code is in txt_xml.onLoad you can do something like:

          var curNode=this.firstChild.childNodes[0]

          Or such.

          A valuable tool is the for...in construction. That allows you to step through the children of a parent object. So try something like this inside your onLoad handler:

          for(var a in this.firstChild){
          trace(a + " is " + this.firstChild[a]);

          Finally the last issue that I've faced is that as far as XML mark up is concerned, any html tags are just more tags marking up more nodes. So you will find it isn't that easy to get the whole text because the parser will stop at each html tag and think it is a child node.

          To deal with this you could take a couple of approaches, but the best approach is probably to wrap your text parts with a CDATA tag. At the bottom of the page I've shown you how I have used the CDATA tag. You can then use:


          Or some such, depending exactly where it is in your structure.

          <![CDATA[<p>My description <b>goes</b> here.<p>And it has all the tags inside the CDATA tag.]]>