createTextField properties not working / for loop problems

alright i’m trying to create a menu dynamically as I am learning about the for loop and creating things with actionscript

i have a loop set up to create text fields based on an array and put them in a line

the line is too long so i would like to make it into two lines but i don’t know how to do that … i’ve only figured out how to put it into one line so far

also the font property and the size property for the created text fields isn’t working

drop this code into a frame in a blank movie to see what i’m talking about


var link = ["AESD", "Board", "CHMO", "COMET", "CCCC", "DAO", "EXEO", "FCSD", "GOVA", "HBSB", "HRSD", "INVO", "ISOF", "ITSD", "LEGO", "MBSB", "OFAS", "OSSD", "PAOF", "PLRD", "RRP", "RSTP", "SLIP", "STP"];
for (i=0; i<link.length; i++) {
	_root.createEmptyMovieClip("mc"+i, i);
	with (_root["mc"+i]) {
		createTextField("label", 1003, 0, 20*i, 40, 14);
		with (label) {
			background = true;
			border = true;
			type = "dynamic";
			font = "Arial";
			size = 11;
			textColor = 0x000066;
			text = _root.link*;
		}
	}
}

your help is greatly appreciated =)

Because you have to set up the TextFormat() object to format your text :slight_smile:

[AS]myFormat = new TextFormat();
myFormat.font = “Arial”;
myFormat.size = 10;
myFormat.color = 0x000066;
var link = [“AESD”, “Board”, “CHMO”, “COMET”, “CCCC”, “DAO”, “EXEO”, “FCSD”, “GOVA”, “HBSB”, “HRSD”, “INVO”, “ISOF”, “ITSD”, “LEGO”, “MBSB”, “OFAS”, “OSSD”, “PAOF”, “PLRD”, “RRP”, “RSTP”, “SLIP”, “STP”];
for (i=0; i<link.length; i++) {
_root.createEmptyMovieClip(“mc”+i, i);
with (_root[“mc”+i]) {
createTextField(“label”, 1003, 0, 20i, 40, 14);
with (label) {
background = true;
border = true;
type = “dynamic”;
text = _root.link
;
setTextFormat(myFormat);
}
}
}[/AS]

genius beta … pure genius … so how do i get em into two lines

also i’m trying to apply an onPress function to them and it’s not working yet … here’s what i have for that so far


_root["mc"+i].label.onPress = function() {
	trace(_root.link*);
};

would i need to say


_root["mc"+i].label.onPress = function() {
	trace(" " +_root.link[Number((this._name).substring(2)]);
};

or something like that so it will trace the value of the item in the array that corresponds to the number in it’s name after “mc”

  1. You can’t do an onPress on a textbox, you will have to do it on the movie clip that houses the text box.

[AS]_root[“mc”+i].onPress = function() {
trace(this.label.text);
};[/AS]

Is that what you meant?

And I am not sure what you mean by getting them in two lines? I see no labels here that require two lines of text. Am I missing something? Why can’t you just change the height of the textboxes that are created?

ok … don’t worry about the two lines. i got that figured out.

i have it figured out how to apply an onPress event to the buttons … i.e. the lil hand comes up … but i can’t make it do what i want

the symbols are made and given a name of mc+i so they are called mc0, mc1 etc. the 0, 1 etc correspond to values set in var link

eventually i would like to tell the buttons to gotoandStop on a label inside a symbol … the label will be the name of the button … so calling it by the text like you suggested might work.

for instance the button could be told to
this.onPress = function(){
_root.map.gotoAndStop(_this.label.text);
}

i’m leaving for vacation tonight so i unfortunately won’t be able to test this out but i’ll check it next week when i get back. so if you have any more thoughts or suggestions on this … please post them here … if not have a great week and thanks very much for all your help. as always i couldn’t do this stuff without you =)

Well you could create a new variable inside the new MC (dynamically)… lets call it targ. Then assign that variable the value of i at that particular time. Then you can call that in the on press…

[AS]myFormat = new TextFormat();
myFormat.font = “Arial”;
myFormat.size = 11;
myFormat.color = 0x000066;
var link = [“AESD”, “Board”, “CHMO”, “COMET”, “CCCC”, “DAO”, “EXEO”, “FCSD”, “GOVA”, “HBSB”, “HRSD”, “INVO”, “ISOF”, “ITSD”, “LEGO”, “MBSB”, “OFAS”, “OSSD”, “PAOF”, “PLRD”, “RRP”, “RSTP”, “SLIP”, “STP”];
for (i=0; i<link.length; i++) {
_root.createEmptyMovieClip(“mc”+i, i);
with (_root[“mc”+i]) {
createTextField(“label”, 1003, 0, 20i, 40, 14);
with (label) {
background = true;
border = true;
type = “dynamic”;
text = _root.link
;
setTextFormat(myFormat);
}
}
_root[“mc”+i].targ = i;
_root[“mc”+i].onPress = function() {
trace(this.targ);
};
}[/AS]

that traces the number … you can’t have a frame label that’s a number

how could i make it trace the name like if it’s mc0 it traces AESD … ?

Thats what I did the first time :stuck_out_tongue:

sweet … so now i have this … and it looks like it’s working … i’ll get the code from this thread when i get back in town :slight_smile:


myFormat = new TextFormat();
myFormat.font = "Arial";
myFormat.size = 11;
myFormat.color = 0x003399;
var link = ["AESD", "Board", "CHMO", "COMET", "CCCC", "DAO", "EXEO", "FCSD", "GOVA", "HBSB", "HRSD", "INVO", "ISOF", "ITSD", "LEGO", "MBSB", "OFAS", "OSSD", "PAOF", "PLRD", "RRP", "RSTP", "SLIP", "STP"];
for (i=0; i<link.length; i++) {
        _root.createEmptyMovieClip("mc"+i, i);
        with (_root["mc"+i]) {
                createTextField("label", 1003, 0, 20*i, 100, 16);
                with (label) {
                        background = true;
                        border = true;
                        type = "dynamic";
                        text = _root.link*;
						selectable = false;
                        setTextFormat(myFormat);
                }
        }
        _root["mc"+i].onPress = function() {
        trace(this.label.text);
};
}

Congrats :slight_smile:

See you when you get back :slight_smile: