as3 Hanging indent issue when displaying xml data

  • Jean-Paul Bardou
  • Newbie
  • Newbie
  • Jean-Paul Bardou
  • Posts: 8

Post 3+ Months Ago

Hi,



I am reading an xml file into my flash project, and I display the html-formatted data.

The problem is that I get a hanging indent on the first line of each paragraph, like this.

This is the data, and you can see
that it has an indent on its first line.

Where I would like to see this:

This is the data, and you can see
that it does not have an indent on
its first line.

Simple question, I would suppose, for one who knows the answer...

Some of the code, if that can help

// Define variables
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var _titles:Array = new Array();
_titles[0] = new TextField();

// setup listener on xl data load
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

function LoadXML(e:Event):void //restore for event
{
xmlData = new XML(e.target.data); // restore for event
_titles[0].htmlText = xmlData._2_header;
addChild(_titles[0]); // <-------THAT IS WHERE I GET THE BLASTED HANGING INDENT!
}

Hope somebody can help.

Very truly yours,

Jean-Paul

P.S.

I suspect that it has to do with prettyIndent and prettyPrinting, and I could not make it to work.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

two things to try. First have you tried ignoreWhiteSpace = true? That should take out the spaces entirely. You might also want to try the XMLDocument Class instead of the XML class since its made to deal with mostly text.
  • Jean-Paul Bardou
  • Newbie
  • Newbie
  • Jean-Paul Bardou
  • Posts: 8

Post 3+ Months Ago

Hi Graphixboy,

Well, I did try the ignoreWhiteSpace = true option. The result is that all my data is dumped as one nice string, which I cannot live with, because I have a bunch of <br/> in the original data!

And in fact, the hanging indent I get is NOT something that is there in the first place which the ignoreWhiteSpace directive can ignore!

I will look into the XMLDocument Class, though, if it can help.

Thank you.

jean-Paul
  • Jean-Paul Bardou
  • Newbie
  • Newbie
  • Jean-Paul Bardou
  • Posts: 8

Post 3+ Months Ago

Hi again, Graphixboy,

I have begun to try using XMLDocument instead of XML, and it is more involved than just adding "Document" to my XML declaration.

For instance, the following line:

_titles[0].htmlText = xmlData._2_header;

now gives the following error:

1119: Access of possibly undefined property _2_header through a reference with static type flash.xml:XMLDocument.

I am relatively new to both java-like programmering (I have been a straight-C programmer for many years, and I slowly move up to OOP!).

Could you indicate what I should change to make this work?

Very truly yours,

Jean-Paul
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Hey Jean-Paul, Unfortunately I won't be a lot of help. I haven't used that class so I'm not as familiar with all the ins and outs. When I was looking up the XML spec for your previous question, I ran across the XMLDocument class and thought it might be a better fit for you.

Maybe someone else has an idea??? *Bump*
  • Jean-Paul Bardou
  • Newbie
  • Newbie
  • Jean-Paul Bardou
  • Posts: 8

Post 3+ Months Ago

Hi Graphixboy (and hopefully others!),

Well, I managed to get XMLDocument to work for me, from a tutorial I found some place...

I have an additional question, still relating to reading and displaying xml data.

When I read some text, and that within an xml tag I have html codes, because they are too xml codes, how do I get Flash to interpret them for what they are, for instance when meeting a <b>... </b> put the text within in bold (which it does) WITHOUT though putting it on a new line all by itself as it does for the other xml tags.

Any ideas, anyone...

Very truly yours,

Jean-Paul Bardou
  • mik77
  • Born
  • Born
  • mik77
  • Posts: 1

Post 3+ Months Ago

Hi,
Had the same problem and finally managed to sort it out by hiding the html content from flash's xml parser - which tries to parse html tags as xml and adds indentation for xml structure to show nicely.

I used CDATA which stops the parser from checking for xml tags within CDATA tags. Now my html looks fine in Flash without the superfluous indents.

Example:

XML:
Code: [ Select ]
 
<article>
  <title>The title of the article</title>
  <html>
    <![CDATA[ // open CDATA tag
    <body>
      <h1>Hello</h1>
      <p>world...</p>
    </body>
    ]]> // close CDATA tag
  </html>
</article>
 
  1.  
  2. <article>
  3.   <title>The title of the article</title>
  4.   <html>
  5.     <![CDATA[ // open CDATA tag
  6.     <body>
  7.       <h1>Hello</h1>
  8.       <p>world...</p>
  9.     </body>
  10.     ]]> // close CDATA tag
  11.   </html>
  12. </article>
  13.  


So you would load this xml into an XML object (e.g. myXmlObject) and add the content of its html field to the htmlText property of a textField as follows.

ActionScript:
Code: [ Select ]
 
var myTextField:textField = new textField();
myTextField.htmlText = myXmlObject.html;
addChild(myTextField); // in order to display the textfield you need to add it to the stage
 
  1.  
  2. var myTextField:textField = new textField();
  3. myTextField.htmlText = myXmlObject.html;
  4. addChild(myTextField); // in order to display the textfield you need to add it to the stage
  5.  


Hope this helps someone.
  • scott80
  • Born
  • Born
  • scott80
  • Posts: 3

Post 3+ Months Ago

I'm having a similar (if not the same) issue. I have a flash file that gets embedded in an HTML page. The content is fed in through XML and is assigned to the htmlText property of a dynamically created TextField object. The issue is there is an indent on the first line because Flash is adding an empty paragraph tag with text formatting, then closing it before the actual code from the XML.

Has anyone seen anything like this? The code sample is what came up when I passed the content of the htmlText property to the JavaScript alert function through ExternalInterface.call.

Code: [ Select ]
<P ALIGN="JUSTIFY"><FONT FACE="Arial" SIZE="10" COLOR="#000000" LETTERSPACING="0" KERNING="0"><B></B></FONT></P><P ALIGN="JUSTIFY"><FONT FACE="Arial" SIZE="10" COLOR="#000000" LETTERSPACING="0" KERNING="0"><B>  This is the first page of the first tab of text.</B></FONT></P>
  • scott80
  • Born
  • Born
  • scott80
  • Posts: 3

Post 3+ Months Ago

Nevermind my last post. I had tried mik77's CDATA approach and the size of the indent increased. I must not have done something right, because I tried it again and it's working now. Nice find on the CDATA hack.
  • scott80
  • Born
  • Born
  • scott80
  • Posts: 3

Post 3+ Months Ago

One more post as I ran into this issue again and couldn't figure out why it wasn't working, even while using the CDATA tag.

targetTextField.multiline must be set to 'true'. I only had targetTextField.wordwrap set to 'true', so all the line breaks were technically on a single line that was just wrapping and looking like it was indented. Also, sourceXML.ignoreWhitespace should be set to 'true' as well.

It all seems obvious now, but it's incredibly frustrating when you're overlooking it.

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.