PDA

View Full Version : TextArea won't load XML... corrupt file?


annie_d
10-09-2005, 02:48 AM
Okay... I"m a beginner, and using Flash MX 2004 to create a site for a client. I'm going to try to explain my problem as best as I can... I'm trying to use TextArea to load an XML file and CSS. I've used the tutorial over here (http://www.actionscripts.org/tutorials/beginner/XML-Formatted_Content/index.shtml) and got that working perfectly in a test document. However, when I go to apply that actionscript and component in the client's site, the XML file doesn't seem to load. When I test the flash movie, no TextArea shows up.. just a huge cursor area where you can type whatever you want. The TextArea is NOT editable, its set to HTML, etc... in fact, if I make a new Flash doc and copy that component and actionscript right out of the site document and paste it into the new document, it works there. It's almost like there's something corrupted with the main site doc or something? Has anyone heard of anything similar happening? I've seriously been trying to figure this out for 6 hours or so.

Basically, all I need is either XML files or TXT files to load in to a scrolling TextArea... and I'm hoping to apply CSS styles w/an external style sheet. It doesn't seem like it should be this hard.

spectravite
10-09-2005, 04:00 AM
Ann,

I had just typed a long and awesome explanation for you, and my comp crashed.so here i am again.

Here's the deal:
Always make sure your textArea's styleSheet is set BEFORE filling it with text.

Here's something extremely important that tutorial omitted, probably to keep it simple:

Whenever you're loading StyleSheets, XML, LoadVars, or anything else that has an onLoad() method, use the onLoad method.

ALWAYS use the onLoad() method:
//// first set the styleSheeet
var myCSS = new TextField.StyleSheet();
myTextArea.styleSheet = myCSS;

//now do the loads
var myXML = new XML();
myXML.ignoreWhite = true;

//here's what the tut left out
myXML.onLoad = function(success){
if(success){
trace("xml loaded");
//now you know the xml is loaded, fill up the text.
myTextArea.text = myXML;
}
}
myXML.load("myXML_file.xml");

myCSS.onLoad = function(success){
if(success){
trace("styles loaded");
//do stuff here
}
}
myCSS.load("myCSSfile.css");


I prefer using TextFields and not the TextArea component.
But this tutorial focusses on the TextArea component, so make sure that's what you're using.

The whole 'success' thing is passed in automatically by flash when a load went well.
inside the if(success){ }
you can do other stuff, knowing your data has loaded, such as call your other functions:

fillMyMenu();
playBackgroundMusic();

annie_d
10-09-2005, 02:49 PM
Thank you so much for the reply. That worked perfectly in a test doc! But then when I tried to apply it to the entire site doc, it doesn't work.. the TextArea component doesn't show up... its like a blank field that you can type in... same thing that's been happening before. The XML loaded trace works, but the CSS one doesn't show up.

I wonder if there's something I'm missing w/the use of components...? If I posted this FLA file, would you be willing to download and see what's up?