Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts

    dynamically format text with actionscript 2.0

    Hi all,
    I have the following code in my flash, which retrieves text from an xml file.
    What I want to do is to apply some styles on the text before it's printed on page

    Code:
    myXML.onLoad = function(success){
            if(success){
                var root = this.firstChild;
                nodes = root.childNodes;
                for(var i=0; i<nodes.length; i++) {  
    				scroll_text.text += nodes[i].attributes.name + "\n";
                    subnodes = nodes[i].childNodes;
    				scroll_text.text += subnodes[0].firstChild.toString() + "\n\n";
                }
            } else title_txt.text = "Error loading XML document";
    }
    right now the code above give this kind of output:
    title ( ---> scroll_text.text += nodes[i].attributes.name + "\n"; )
    text ( ---> scroll_text.text += subnodes[0].firstChild.toString() + "\n\n"; )

    title
    text
    ...

    What I want is to make title bold and draw a line between two nodes:
    title
    text
    -------------------------------------------------line------
    title
    text
    -------------------------------------------------line------
    ...

    How am I supposed to do that?
    Last edited by ktsixit; 12-15-2008 at 09:30 AM.

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You can use HTML to make this happen

    Code:
    myXML.onLoad = function(success){
            if(success){
                var root = this.firstChild;
                nodes = root.childNodes;
                for(var i=0; i<nodes.length; i++) {  
    				scroll_text.htmlText += "<strong>" + nodes[i].attributes.name + "</strong>\n";
                    subnodes = nodes[i].childNodes;
    				scroll_text.htmlText += subnodes[0].firstChild.toString() + "\n\n";
                }
            } else title_txt.text = "Error loading XML document";
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • Users who have thanked gnomeontherun for this post:

    ktsixit (12-15-2008)

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    106
    Thanks
    27
    Thanked 3 Times in 3 Posts
    I tried this but it doesn't seem to work

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You might have to set the field as able to accept HTML output.

    Put this near the top of the actionscript (outside of the onLoad)

    Code:
    scroll_text.html=true;
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •