Skip to main content
Known Participant
February 3, 2011
Question

Applying different background colors to selected paragraphs

  • February 3, 2011
  • 1 reply
  • 1137 views

Hello there,

In the text that is loaded dynamically as XML (i.e. markup format) I need to specify background color for selected paragraphs.

So, I tried this: <p backgroundColor='#800000'>.

Alas, it has no effect.

What puzzles me even more is that declaring this attribute in span DOES work:

<p><span backgroundColor='#800000'>Lorem impsum ... </span></p>

This way it does change the background color, albeit, it is not solid background but sort of highlight of the text lines.

Although, it's not ideal, I could live with that, but still would be interested to find out: what am I missing?

After all, span can't have children, so it is a patch rather then nice solution.

So, far I couldn't find the explanation of that behavior - ignoring 'backgroundColor' attribute in the paragraph tag.

I'm on Mac 10.6.6 and use TLF 2.0 build 228

BTW, searching for an answer I found a typo in the official TLF 1.1 Markup specification that was published back in December:

6.3.13 backgroundColor attribute

<xs:attribute name="textAlpha" type="xs:text" default=" transparent"/>

Background color of the text.

backgroundColor is non-inheriting.

Valid values include:

• transparent: No color is applied.

• <hexadecimal value>: A value that conforms to the color data type.

Thanks,

Igor Borodin

This topic has been closed for replies.

1 reply

FTQuestAuthor
Known Participant
February 3, 2011

Last night I checked various ways of defining 'backgroundColor' on element - in XML markup, in AS, and in MXML.

The result is consistent - the 'backgroundColor' property/attribute is recognized in 'span', but is ignored in 'paragraph'.

Trying multiple spans with the new SubParagraphGroupElement <p><g>...</g></p> I received runtime error in Flash Player 10.1: 'unknown element g'

Any comments/clarification?

IB

Adobe Employee
February 3, 2011

You are correct - backgroundColor on block-level elements is an unimplemented feature. Applying backgroundColor on a paragraph is not the same as applying it to all the spans of the paragraph, because the former will cover the entire area covered by the paragraph (including first line indent), and the latter includes only the area covered by the text. Because backgroundColor is non-inheritable, applying it to the paragraph doesn't cause it to be applied to the spans. Eventually TLF should include both backgroundColor on block-level and borders; but, alas, not yet.

In the meantime, your workaround is to apply it to the spans.

The error with the <g> element I would expect if you were using TLF 1.0 or TLF 1.1, but not with the new (prerelease) TLF 2.0.
If you are using TLF 2.0 and get this error, can you provide us a short application that shows it?

Thanks!

- robin

FTQuestAuthor
Known Participant
February 3, 2011

Here is the app and the screen shot of the runtime error:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

   xmlns:s="library://ns.adobe.com/flex/spark" >

<fx:Script>

<![CDATA[

import spark.utils.TextFlowUtil;

XML.ignoreWhitespace = false;

[Bindable]

private var txtXML:XML = <TextFlow version="2.0.0" xmlns="http://ns.adobe.com/textLayout/2008" fontSize='18' >   

    <p>

<g>Lorem ipsum dolor sit amet,

<span color='#880000'>consectetur adipiscing elit.</span>

Quisque tempus, eros ac dignissim interdum, elit sem euismod velit,

<span fontStyle='italic'>eget laoreet urna metus nec enim.</span>

</g>

</p>

</TextFlow>

]]>

</fx:Script>

<s:RichText horizontalCenter="0" verticalCenter="0" width="200"

textFlow="{TextFlowUtil.importFromXML(txtXML)}" />

</s:Application>

I'm on Mac 10.6.6 Flex Hero 4.5 TLF 2.0 build 228

It's the same on Safari and FireFox

HTH,

Igor Borodin