Copy link to clipboard
Copied
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
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.
Copy link to clipboard
Copied
are you assigning htmlText using the p tag?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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."
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
you're welcome.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more