# createTextField properties not working / for loop problems

**URL:** <https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826>\
**Category:** flash\
**Created:** [April 9, 2003, 7:23pm UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826 "2003-04-09T19:23:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)\
**Post date:** [April 9, 2003, 7:23pm UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/1 "2003-04-09T19:23:31Z")

</div>

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

```php

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 =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 9, 2003, 7:42pm UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/2 "2003-04-09T19:42:47Z")

</div>

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

[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, 20_i, 40, 14);  
with (label) {  
background = true;  
border = true;  
type = “dynamic”;  
text = \_root.link_;  
setTextFormat(myFormat);  
}  
}  
}[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 9, 2003, 8:14pm UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/3 "2003-04-09T20:14:50Z")

</div>

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

```php

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 9, 2003, 8:33pm UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/4 "2003-04-09T20:33:19Z")

</div>

would i need to say

```php

_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”

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 9, 2003, 9:52pm UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/5 "2003-04-09T21:52:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 10, 2003, 12:50am UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/6 "2003-04-10T00:50:01Z")

</div>

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 =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 10, 2003, 2:42am UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/7 "2003-04-10T02:42:34Z")

</div>

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, 20_i, 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]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 10, 2003, 2:49am UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/8 "2003-04-10T02:49:56Z")

</div>

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 … ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 10, 2003, 2:51am UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/9 "2003-04-10T02:51:23Z")

</div>

Thats what I did the first time 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 10, 2003, 2:58am UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/10 "2003-04-10T02:58:33Z")

</div>

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 🙂

```php

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);
};
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 10, 2003, 3:02am UTC](https://forum.kirupa.com/t/createtextfield-properties-not-working-for-loop-problems/17826/11 "2003-04-10T03:02:35Z")

</div>

Congrats 🙂

See you when you get back 🙂
