Copy link to clipboard
Copied
I've a manually created text field, newsText_tf, into which I am able to load text. The text file, writeUp1.txt, is definitely getting loaded, but the CSS styling found in "newsStyle.css" in not getting applied, or loaded at all.:mad:
I slipped in a few trace commands and supposed the CSS is getting loaded, or at least the function in which the trace code is found is getting read.:p
Anyway, here's the code:
import flash.events.Event;
import flash.net.URLLoader;
var navBanNews:URLRequest = new URLRequest("content_news/writeUp1.txt");
var newsLoader:URLLoader = new URLLoader(navBanNews);
var cssLoader:URLLoader = new URLLoader();
//Load the text file ("writeUp1.txt")
newsLoader.addEventListener(Event.COMPLETE, newsLoadCompleted);
function newsLoadCompleted(event:Event):void
{
var newsLoaded:URLLoader = URLLoader(event.target);
newsBox_mc.newsText_tf.htmlText = newsLoaded.data;
callCss();
trace("Text loaded!");
}
//Load the CSS file ("newsStyle.css")
function callCss():void
{
var newsStyleRequest:URLRequest = new URLRequest("content_news/newsStyle.css");
cssLoader.addEventListener(Event.COMPLETE, cssLoadComplete);
cssLoader.load(newsStyleRequest);
trace("CSS loaded!");
}
function cssLoadComplete(event:Event):void
{
var newsStyle:StyleSheet = new StyleSheet();
newsStyle.parseCSS(cssLoader.data);
newsBox_mc.newsText_tf.styleSheet = newsStyle;
newsBox_mc.newsText_tf.wordWrap = true;
newsBox_mc.newsScroller.update();
trace("CSS load complete!");
}
I don't know if it means anything, but when I Test the movie, the "CSS loaded" trace is displayed first in the Output panel.
Copy link to clipboard
Copied
i don't see how newsLoadCompleted is called so none of those traces will execute.
Copy link to clipboard
Copied
Maybe I'm not understanding your statement, but all the traces execute. It's just that (and the traces executing out of order is probably irrelevant to the whole thing) the trace CSS loaded! gets output first.
The text file gets loaded--no problem there; the styling in the css is not getting loaded/ parsed.
Copy link to clipboard
Copied
what kind of tags do you use?, this link show the supported tags in Flash
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/StyleSheet.html
Copy link to clipboard
Copied
Yep, my tags are pretty straightforward. Here's writeUp1.txt:
<h1>Homeland's Navid Negahban And David Marciano To Return As Series Regulars For Season 2</h1>
<p class="style1"><a href="http://www.cinemablend.com/television/Homeland-Navid-Negahban-David-Marciano-Return-Series-Regulars-..." target="_blank">TVLine</a> is reporting that Navid Negahban and David Marciano have both been promoted to regulars for the second season of the Golden Globe Best Drama. This news means we'll be getting a lot more of Abu Nazir, Homeland's central terrorist played by Negahban. And the move makes complete sense since the last we saw of him the show, he and Damian Lewis' Brody were only initiating plans for the latter to use his new found influence to infiltrate the government. While most might call Nazir the series central villain, TVLine caught up with the actor who added that Homeland "raises the questions, Who is your hero? Who is your villain? And that’s what I love about the show." It's like that old saying, one person's terrorist is another's freedom fighter.</p>
And newsStyle.css:
h1 | { |
color: red; | |
font-size: 16px; | |
font-family: Arial, Helvetica, sans-serif; |
}
p | { |
color: #666666; | |
font-size: 5px; |
LOL. That's it! I kept is simple because I had a feeling I would be running into troubles with code freshly learned from a book.....
Copy link to clipboard
Copied
I test your code and in fact don't works.
I only can change the link color
a{
color: #FF0000;
}
but I can't change the color or size of the text. the color and size is defined only by the panel control.
I created dynamicly a textFild but the result is same
Maybe is a bug, I tested this in Flash CS6
Copy link to clipboard
Copied
Thank you for checking it out.
I hope it's a result of bad coding on my part, and not some bug in Flash CS5.5 itself, otherwise I can't build dynamic text fields at all!
Copy link to clipboard
Copied
I DON'T FARGING BELIEVE IT!
It was all down to a matter of selecting TLF Text in the Properties panel!!!! In none of the tutorials did I read or watch was it mentioned! Oh boy!!!!!