all groups > macromedia flash sitedesign > june 2005 >
You're in the

macromedia flash sitedesign

group:

Error Loading Stylesheet


Error Loading Stylesheet paulpsd7
6/18/2005 1:12:50 AM
macromedia flash sitedesign:
I'm trying to load an external stylessheet which I'll use to style a column of
text in a FLA. I've grabbed two pieces of code from the online help, and
neither works.

Here's one:

var styles = new TextField.StyleSheet ();
TextField.styles.load("abbott.css");
TextField.styles.onLoad = function (ok) {
if (ok) {
trace (this.getStyleNames());
trace ("CSS file loaded");
} else {
trace ("Error loading CSS file");
}
}

Here's the other:

var my_styleSheet:TextField.StyleSheet = new TextField.StyleSheet();
my_styleSheet.onLoad = function(success:Boolean) {
if (success) {
trace("Styles loaded:");
var styles_array:Array = my_styleSheet.getStyleNames();
trace(styles_array.join(newline));
} else {
trace("Error loading CSS");
}
};
my_styleSheet.load("abbott.css");

Both of these functions return "Error loading CSS". I have ensured that
"abbott.css" is spelled correctly, and that the file is in the same directory
as the SWF file. What is wrong?
Re: Error Loading Stylesheet merlinvicki
6/18/2005 10:52:31 AM
Hi paul
I've alredy answered your question in your another thread. Check that one . You will probably find what you are looking for.
:)
Re: Error Loading Stylesheet paulpsd7
6/24/2005 12:00:00 AM
Thanks, merlinvicki. Your example is great. It enabled me to trudge one more
step along.

I've modified your code and tried to bring in my own content. My own content
did come in, but the stylesheet still won't. Here's my code:

var ss:TextField.StyleSheet = new TextField.StyleSheet();
ss.load("abbott.css");
content.styleSheet = ss;
trace (this.getStyleNames());

content.multiline= true;
content.wordWrap = true;
content.html = true;

function loadChapter (chapter) {
story = new XML();
story.ignoreWhite = true;
story.load(chapter);
story.onLoad = function () {
content.htmlText = story;
}
}

I put your actionscript into a function that I can call, specifying which
chapter to load. This much works. My text gets imported and displayed. However,
the text has no formatting except for the default formatting set in my FLA
(Verdana, white, 14pt). The trace command returns undefined. Also, the text
appearing in the box doesn't wrap, despite setting wordWrap to true. There's no
question that the file abbott.css is located in the same folder as the FLA and
exported SWF. I also put your sample.css file in there too, and changed the
reference in the actionscript, but it wouldn't import that either.
Re: Error Loading Stylesheet merlinvicki
6/24/2005 7:42:01 AM
Can I have a look at ur FLA. There must be a very small thing u may be mising.

Check the movieclips instance name, instance name of the textbox, most of the time the problem lies in these areas.
Re: Error Loading Stylesheet paulpsd7
6/24/2005 8:46:42 PM
Thanks for your continued help on this. I don't think it's the instance name of
the dynamic text field. I've got it set as "content," and besides, if that were
the problem, none of my text would flow in. The fact that the text appears at
all indicates that the connection between my text file and the text field is
fine. My problem is all about importing the stylesheet.

I've uploaded some files http://psd7.com/temp/to_merlinvicki.zip.

In that ZIP file are:

chapter1.fla: This is the file where I'm trying to import the stylesheet and
text file. On Frame 2 of layer "init," you'll see the code I've put above. On
Frame 10 of layer "actions" is where I call the function loadChapter.

I've also included abbott.css and chapter1.htm, which are the stylesheet and
text file I'm trying to import.

Finally, I've included root.fla. This is the file that contains the main
interface of the whole project. It loads in chapter1.swf into a Movie Clip. If
you do a test movie of root.fla, and then select 1: Introduction from the top
navigation, it will load in chapter1.swf and you'll see what I'm talking about.

Thanks again.
Re: Error Loading Stylesheet merlinvicki
6/25/2005 11:02:32 AM
Change ur first frame code to this:

__________________________________________________________


_global.loadChapter = function(chapter) {
var ss:TextField.StyleSheet = new TextField.StyleSheet();
ss.load("abbott.css");
content.styleSheet = ss;
content.multiline = true;
content.wordWrap = true;
content.html = true;
story = new XML();
story.ignoreWhite = true;
story.load(chapter);
story.onLoad = function() {
content.htmlText = story;
};
};


________________________________________________________________

and call it via:
loadChapter("chapter1.htm")

There also seems to be some problem with your CSS cause it was working with
the sample.css I provided earlier.
Here is the css code for abbott.css try modifying the code with this css to
get ur required results.



h1 {
font-family: Arial,Helvetica,sans-serif;
font-size: 16px;
font-weight: bold;
display: block;
color:#000000;
}
subheadline {
font-family: Arial,Helvetica,sans-serif;
font-size: 13px;
font-weight: bold;
display: block;
color:#000000;
}
body_text {
font-family: Arial,Helvetica,sans-serif;
font-size: 10px;
display: block;
color:#000000;
}
biline {
font-family: Arial,Helvetica,sans-serif;
font-size: 11px;
font-style: italic;
display: inline;
color:#000000;
}
A {
font-family: Arial,Helvetica,sans-serif;
color:cccccc;
font-size: 10px;
display: inline;
text-decoration:underline;
color:#000000;
}

Any problems get the file here:
http://www.merlinvicki.com/samples/chapter1.zip
keep flashing!

Re: Error Loading Stylesheet paulpsd7
6/27/2005 10:04:08 PM
YES!!! It worked!

The problem seems have been caused by the fact that the stylesheet was
imported separately from the text. Once I combined both imports into the same
function, it worked! Merlinvicki, you are a star!!! Thank you so much.
Re: Error Loading Stylesheet merlinvicki
6/28/2005 12:00:00 AM
:D
cool. keep in touch
AddThis Social Bookmark Button