Is there a way to give the end user control over the text in a dynamic text box? My client wants to be able to update their own text. I can't figure out how to load text without it being in HTML. Is it a way to do that?
Printable View
Is there a way to give the end user control over the text in a dynamic text box? My client wants to be able to update their own text. I can't figure out how to load text without it being in HTML. Is it a way to do that?
yes I do this all the time.
The way I do it is just a simple text file. lets say it's aboutus.txt for an about us page
then when I want to load that into say a content pane I use LoadVars
content=new LoadVars();
then using the onData function I get the raw file contents
content.onData=function(src){
contentpane1.setContent(0,src,1,2);
}
Thank you ... but I don't know what I'm doing wrong. My text file is welcome.txt. On my first frame I have a contentpanel object. I put your code in the first frame replacing src with welcome.txt. Like this:Quote:
Originally Posted by blanius
Code:content=new LoadVars();
content.onData=function(welcome){
contentpane1.setContent(0,welcome,1,2);
}
You have to load it.... Sorry I left that out.
content.load("welcome.txt");
thanks blanius. it worked. is it a way I can make that text auto scroll like a news ticker? I've been searching for that effect.
Not in a content pane I don't think.
Once you have the text in the flash you can do whatever you want with it.
Try something like this
You probably could make that work with a content pane after allCode:myArray=welcome.split("\n");
function showWelcome() {
txt1.text=""
if(count >= maxCount) {
clearInterval(intervalId);
}
for (x=count;x<=count+10;x++){
txt1.text+=myArray[x];
}
count++
}
maxCount=myArray.length
intervalId = setInterval(this, "showWelcome", 1000);
hey blanius, will that code work with a dynamic text box? I want the background to be transparent and I can't acheive that with a contentpanel. At least I don't think I can. but the text box object gives me that option so I'd rather use the text box. I tried the code but it returns an error. this is what i have:Quote:
Originally Posted by talytech
Code:content=new LoadVars();
content.onData=function(src){
text.setContent(0,src,1,2);
}
content.load("welcome.txt")
this is what the text box displays: _level0.mc9.text
That's what I assumed named txt1 try it. I just pulled this code from a test project so it should work.
what is txt1.text? my txt object is named text and my variable is named text. Nothing is named txt1. And do I put this code on the same frame as the dynamic text box?Quote:
Originally Posted by blanius
So change txt1 to whatever it's an example only. I would not reccomend naming a text field to the name 'text' the default names are txt1, txt2 etc so that was what I used in the example.
Put the code in the OnData is fine as you don't want to execute it until you have the text from your file loaded in.
Hi Bret,
I've been trying for a week now to get the data from my text file loaded into my dynamic text box and to scroll. I can't get it to work. Can you please tell me what I'm doing wrong ... I give up. Here's what I have:
Code:content=new LoadVars();
content.onData=function(welcome){
text.setContent(0,welcome,1,2);
}
content.load("welcome.txt")
myArray=welcome.split("\n");
function showWelcome() {
welcome.text=""
if(count >= maxCount) {
clearInterval(intervalId);
}
for (x=count;x<=count+10;x++){
welcome.text+=myArray[x];
}
count++
}
maxCount=myArray.length
intervalId = setInterval(this, "showWelcome", 1000);
Can anyone help me ... this is driving me crazy. I've searched through several pages on the forum for how to use the LoadVars to import a text file and I can't seem to get my function to work. I don't know what I'm doing wrong. I have a text file (welcome.txt) that simply reads: My name is talytech. On frame 2 of my KoolMoves movie I have a dynamic text box named welcome and the variable name is welcome. I put the following AS code on frame 2:
that code returns the following in my dynamic text box: _level0.welcomeCode:content=new LoadVars();
content.onData=function(welcome){
this.welcome.setContent(0,welcome,1,2);
}
content.load("welcome.txt");
I can't figure it out. Why won't it display what's in my text file? Please somebody help me ... I'm running out of time.
You're almost there.
First off if you want to load as a variable you must format the text as a variable so your text file should be
&welcome=my name is Talytech
Code:content=new LoadVars();
content.onLoad(success){
if (success){
contentpane1.setContent(0,this.welcome,1,2);
}
}
content.load("welcome.txt")
You use onData only if you want to access the raw data
thanks Blanius. But someone else assisted me. This is the code I used:
Code:var R;
//
res=new LoadVars();
res.load("welcome.txt");
res.onData=function(info){
if (info==undefined){
R="Loading failed";
}else{
R=info;
}
txt1.text=R;
}
That's actually the way I do it on my sites. But I keep it shorter
res.onData=function(src){
if (src==undefined){
txt1.text="data not loaded";
}else{
txt1.text=src;
}