Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

TextField Stylesheet is not working?

Explorer ,
Jun 22, 2010 Jun 22, 2010

Hi,

I guess this one i easy but i can't figure out what's the problem:

I have a TextField which styleSheet i want to change at runtime.

For testing I created a new .FLA  put a Textfield on stage, set it to dynamic, named it mytxt and added some AS3:

import flash.text.StyleSheet;
import flash.text.TextField;

var _style = new StyleSheet();
_style.parseCSS('p{color:#ff0000;}');

mytxt.styleSheet = _style;

Well - nothing changed I still have a default black text when I publish the swf.

What am I missing?

My goals:

- Set a TextField in Flash IDE

- set the font, weight, color, size etc.

- apply a styleSheet containing colors for links

Thanks, Booya

TOPICS
ActionScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 22, 2010 Jun 22, 2010

because the font tag occurs after the p tag, the font tag will override your p tag.  if you switch the order of the p and font tags, then your p tag will override the color in the font tag.

Translate
Community Expert ,
Jun 22, 2010 Jun 22, 2010

are you assigning htmlText using the p tag?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2010 Jun 22, 2010

Hi klad,

thanks for your response.

The TextField's htmlText is already set within the IDE (in the real application it will also be set within the .fla).

AFAIK the HTML Text from IDE is something like (with some more attributes):

<textformat><p><font>TEXT</font></p></textformat>

So i am sure to have a <P> tag in there - I also tried something like

var _html = mytxt.htmlText;

mytxt.htmlText = '';

mytxt.htmlText = _html;

to (maybe) force the TextField to re-render ...

But no luck yet

Didn't think this one would be difficult ...

More suggestions are welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2010 Jun 22, 2010

i'm sure you don't have a p tag.

remove those 3 lines of code in your previous message and use:

mytxt.htmlText = "<p>this is red text</p> and this is the default text color."

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2010 Jun 22, 2010

ok, it works via code - thanks for that.

Now I have to figure out how to retain the formating from the IDE which is in my testfile

<TEXTFORMAT LEADING="4"><P ALIGN="LEFT"><FONT

FACE="Arial" SIZE="16" COLOR="#242424" LETTERSPACING="0"

KERNING="1">TEXT</FONT></P></TEXTFORMAT>

and just add my CSS on top.
I need this to change at least the colors of links with a, a:hover

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2010 Jun 22, 2010

because the font tag occurs after the p tag, the font tag will override your p tag.  if you switch the order of the p and font tags, then your p tag will override the color in the font tag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 23, 2010 Jun 23, 2010

Ok, everything works now. Thanks for clearing things up.

It confused me that I couldnt change the style of font - well i still cant.

<TEXTFORMAT LEADING="4"><P ALIGN="LEFT"><FONT
FACE="Arial" SIZE="16" COLOR="#242424" LETTERSPACING="0"
KERNING="1">TEXT</FONT></P></TEXTFORMAT>

import flash.text.StyleSheet;
import flash.text.TextField;

var _style = new StyleSheet();
_style.parseCSS('font{color:#00ff00}');


mytxt.styleSheet = _style;

The text will still be "black"

But it is not that bad because i will add some additional HTML within the existing font tags:

<TEXTFORMAT LEADING="4"><P ALIGN="LEFT"><FONT
FACE="Arial" SIZE="16" COLOR="#242424" LETTERSPACING="0"
KERNING="1"><SPAN CLASS="red">TEXT</SPAN></FONT></P></TEXTFORMAT>


so changing the stylesheet according to my HTML and everything works like expected:

import flash.text.StyleSheet;
import flash.text.TextField;

var _style = new StyleSheet();
_style.parseCSS('.red{color:#00ff00}');


mytxt.styleSheet = _style;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2010 Jun 23, 2010
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines