A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: XML doen't display simple HTML in flash as3

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    6

    Unhappy XML doen't display simple HTML in flash as3

    Hey there!

    I am trying to load simple html text from xml using AS3 in flash. Here is my sample xml tag.

    Code:
    <startPage>Hey there!<br/>This is driving me nuts.<br/>Well, lets see if anyone in the forum knows any solutions to this?<br/>Click <b>Start</b> to begin.</startPage>
    When I assign this as htmlText to a textfield, it displays as:

    Hey there!

    This is driving me nuts.

    Well, lets see if anyone in the forum knows any
    solutions to this?

    Click
    Start
    to begin.

    And what I expect to see it:

    Hey there!

    This is driving me nuts.

    Well, lets see if anyone in the forum knows any solutions to this?

    Click Start to begin.


    Somehow all the sentences that are automatically wrapped start from the beginning, where as others start after a space. Though <b> do bold the text, they also break the line. I wonder whats going on!!

    Any ideas/solutions? I appreciate your inputs.

    KrisAG

  2. #2

  3. #3
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    jAQUAN, you're making that way too complicated.

    His problem is because he's nesting "XML" elements, so the parser is fk'd up.

    Here comes a little thing called CDATA tags. Wrap your element like this:
    Code:
    <startPage><![CDATA[Hey there!<br/>This is driving me nuts.<br/>Well, lets see if anyone in the forum knows any solutions to this?<br/>Click <b>Start</b> to begin.]]></startPage>
    The <![CDATA[ & ]]> tell XML that everything between those tags should be parsed as a literal string. So stick those in your XML, and it should work just fine. No need to strip out the CDATA since those are automatically recognized to the XML parser.

    Think of <![CDATA[ and ]]> and " and " to delimit a string.

  4. #4
    Junior Member
    Join Date
    Feb 2009
    Posts
    6
    Taco,

    Thanks for the tips. I will give it a try and see if it does the trick. I am sure CDATA might take care of it.. But I just didn't wanted to go down that route initially.

    I guess I assumed AS3 is far more matured in handling html tags in XML. But I gotta admit.. man it improved on handling XML atleast.

  5. #5
    Junior Member
    Join Date
    Feb 2009
    Posts
    6
    Taco,

    Yes, that baby was hungry for some CDATA. Thank you. Its working better now. But somehow, it doesn't seem to insert line breaks wherever I used <br/> or <br>.

    Any hints there?

  6. #6
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Is your field multiline?

  7. #7
    Junior Member
    Join Date
    Feb 2009
    Posts
    6
    It wasn't. Turned on multiline property and it works as it should! Thanks a ton MyFriendIsATaco.

  8. #8
    Junior Member
    Join Date
    Mar 2009
    Posts
    1

    Same XML Issue

    Guys, I'm experiencing the same issue as above. Just trying to do some basic HTML formatting of an XML node as user above.

    I am pushing the XML text to an HTML enabled, dynamic text field.
    I have Multiline on as well.
    For some reason my textfields output the HTML tags and no formatting is applied.

    XML Ex:

    <comments><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit. In dolor urna, gravida ut, aliquet nec, sodales nec, orci.</b> Donec porta pede ut enim. ]]></comments>


    Any html tags I try I just get outputted like regular text. Any ideas??
    Also is the <br/> a XHTML version of the regular <br>??

    Many thanks!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center