View Full Version : [AS2] TextArea
nhagan
12-15-2009, 10:30 PM
Hey all i'm using Actionscript 2.0 and i have a TextArea in where i want text to be displayed when a button is pressed.
I have 8 buttons named btn1, btn2, etc. and the TextArea is called text.
I was wondering what code i would need to use i kind of know how to do it in AS 3.0 but not 2.0
If anyone could be of help would appreciate it
Thanks.
Nat.
eddiewireless
12-15-2009, 10:35 PM
var btn_att:Array = [btn1, btn2, btn3];
var txt_arr:Array = ["text 1", "text 2", "text 3"];
for (i=0; i<btn_arr[i]; i++) {
btn_arr[i].onPress = function() {
text_instance_name.text = txt_arr[i];
};
}
nhagan
12-15-2009, 10:44 PM
bit confused
var btn_att:Array = [btn1, btn2, btn3];
what is btn_att and btn1, btn3 are the buttons names or instance name?
var txt_arr:Array = ["text 1", "text 2", "text 3"];
txt_arr is what? and text 1 etc is the text which appears?
for (i=0; i<btn_arr[i]; i++) {
btn_arr[i].onPress = function() {
text_instance_name.text = txt_arr[i];
am i meant to change text_instance_name?
};
}
Thanks for reply x
eddiewireless
12-15-2009, 10:47 PM
//this is an array containing your buttons' instance names
var btn_att:Array = [btn1, btn2, btn3];
//this is an array containing the coresponding text to be displayed for each button
var txt_arr:Array = ["text 1", "text 2", "text 3"];
for (i=0; i<btn_arr[i]; i++) {
btn_arr[i].onPress = function() {
//yes you need to change this to your instance name (I would not use text was I you, since this is a reserved keyword in flash
text_instance_name.text = txt_arr[i];
};
}
nhagan
12-15-2009, 11:08 PM
not sure why but it isn't working this is what i have atm:
var btn_att:Array = [btn1, btn2, btn3];
var txt_arr:Array = ["text 1", "text 2", "text 3"];
for (i=0; i<btn_arr[i]; i++) {
btn_arr[i].onPress = function() {
text_area.text = txt_arr[i];
};
}
nothing is happening tho when im clicking the buttons ;s
nhagan
12-16-2009, 03:16 PM
I have a TextArea and the following code:
var btn_arr:Array = [stomach, brain, heart, kidneys, bladder, lungs, skinn, liver];
var txt_arr:Array = ["hellohellohello", "text 2", "text 3", "kidneys", "bladder", "lungs", "skinn", "liver"];
for (i=0; i<btn_arr.length; i++) {
btn_arr[i].onPress = function() {
text_area.text = txt_arr[i];
};
}
And undefined displays in the TextArea anyone know why?
nhagan
12-16-2009, 09:51 PM
solution thanks to barna biro:
var btn_arr:Array = [stomach, brain, heart, kidneys, bladder, lungs, skinn, liver];
var txt_arr:Array = ["stomach", "brain", "heart", "kidneys", "bladder", "lungs", "skinn", "liver"];
var btnArrLength:Number = btn_arr.length;
for (var i:Number = 0; i < btnArrLength; i++) {
btn_arr[i].storedText = txt_arr[i];
btn_arr[i].onPress = function():Void {
text_area.text = this.storedText;
}
}
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.