View Full Version : problem loading variables into dynamic text fields
onlyrobot
11-10-2002, 07:34 PM
Hi everyone. I'm trying to load some text from a .txt file into a dynamic text field (for use as a "news" section of my site) and it isn't working.
I have the dynamic text field named "newstext" and the text file is called "news.txt". It's always in the same directory as my .swf.
In the text file itself, it says:
&thetext=test!
In frame 1 of the layer that newstext, the text field is on, the actionscript is:
loadVariables("news.txt", _root)
newstext.text = _root.thetext
It just doesn't work. I don't understand. Any suggestions would be greatly appreciated, thanks much.
Noah
you have to wait until the text file is loaded before you can start to use the data. makes sense, doesn't it?
try this:
in frame 1:
loadVariables("news.txt", "newstext")
put this code on newstext mc:
onClipEvent(data){
text = thetext;
}
cheerz
tost
farafiro
11-11-2002, 07:11 AM
as from what u wrote, I can see that u r using MX, so why don't you use the new features for that (LoadVars)//assigning a new LoadVars and loading the text file
newsVar = new LoadVars()
newsVar.load("news.txt")
//checking if the file loaded 100% to display it
newsVar.onLoad = function(done){
if(done){
newstext.text = this.thetext
}else{
//put some condition here
}
}
you are - of couse - right, farafiro,
i just wanted to make it simple and understandabe
but, noah, please listen to the egyptian! his code is better! :)
greetz
tost
farafiro
11-11-2002, 09:10 AM
why OF COURCE
I usualy make some mistakes (a lot actualy)
so, where is gent?? is it in Bilgum??
"of course", as in "i agree one should prefer to use a better way the moment it is available", not as in "you're always right" :)
.be stands for belgium, indeed.
dr_flokk
04-03-2007, 09:09 AM
Here is my code:
this.createTextField("news1_txt",3,3,-22,198,150);
//this.createTextField(name,depth,x,y,weight,height)
news1_txt.border = false;
news1_txt.html = true;
news1_txt.multiline = true;
news1_txt.wordWrap = true;
// Create a new style sheet and LoadVars object.
var myVars_lv:LoadVars = new LoadVars();
var styles:TextField.StyleSheet = new TextField.StyleSheet();
// Location of CSS and text files to load.
var txt_url:String = "Newsbox.txt";
var css_url:String = "styles.css";
// Define onData handler and load text to display.
myVars_lv.onData = function(src:String):Void {
if (src != undefined) {
news1_txt.htmlText = src;
} else {
trace("Unable to load HTML file");
}
};
myVars_lv.load(txt_url);
// Define onLoad handler and Load CSS file.
styles.onLoad = function(success:Boolean):Void {
if (success) {
/* If the style sheet loaded without error,
then assign it to the text object,
and assign the HTML text to the text field. */
news1_txt.styleSheet = styles;
news1_txt.text = storyText;
} else {
trace("Unable to load CSS file.");
}
};
styles.load(css_url);
so please help me, the text is loaded correctly but after a refresh the text is not displayed saying just ... undefined, or sometimes the text it's not loaded at all. what's wrong?
http://www.mandrake.3x.ro/sandust/index.htm here can be veiwed!
|
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.