PDA

View Full Version : Buttons and Dynamic Text


NeverBelieve
12-19-2004, 06:17 PM
I have a textfield which I want the content to change when I click on the buttons to the left of it. The content is located in external .txt files. I want this text to be drawn up by the click of the button into the textfield. I can get external text to display in the textfield normally but not through using buttons. I'm sure this is a simple task but I can't find what I'm doing wrong or anywhere to discover how to rectify this problem. Please help!

farafiro
12-20-2004, 07:27 AM
NeverBelieve
welcome to the forums

show me how u load it normaly, so I can help u in easier way

NeverBelieve
12-20-2004, 10:52 PM
loadVariablesNum("me.txt", 0);

loads me.txt into the frame at the beginning but i'd like buttons to be able to change this to other external content. :)

farafiro
12-21-2004, 06:38 AM
use the LoadVars() instead//the text file (me.txt) should look like
first=blah blah
second=koko wawa
//then in the first frame of the flash
myLoading = new LoadVars()
myLoading.load("me.txt")
myLoading.onLoad = function(done){
if(done){
myText.text = this.first
}
}
//then on the button
theButton.onRelease = function(){
myText.text = myLoading.second
}

NeverBelieve
12-22-2004, 06:46 PM
When I do this none of the text shows up :-\

farafiro
12-23-2004, 06:02 AM
even there was a mistake in the sext file (sorry), add a & before the 'second', but it worked great for me MX 2004
this.createTextField("myText", 1, 50, 50, 150, 30);
myText.border = true;
//then in the first frame of the flash
var myLoading:LoadVars = new LoadVars();
myLoading.load("me.txt");
myLoading.onLoad = function(done) {
if (done) {
myText.text = this.first;
}
};
//then on the button
theButton.onRelease = function() {
myText.text = _level0.myLoading.second;
};

NeverBelieve
12-23-2004, 02:21 PM
Well I don't have MX 2004 only MX so I don't know if that makes a difference but when I put the code in as you suggest the text box now shows _level0.myText and the button does nothing..very confusing.

Edit// Managed to figure out another way that works - although much more longwinded than your example. Thanks for the help anyway :)

farafiro
12-24-2004, 02:47 PM
MX version
this.createTextField("myText", 1, 50, 50, 150, 30);
myText.border = true;
//then in the first frame of the flash
var myLoading = new LoadVars();
myLoading.load("me.txt");
myLoading.onLoad = function(done) {
if (done) {
myText.text = this.first;
}
};
//then on the button
theButton.onRelease = function() {
myText.text = _level0.myLoading.second;
};