Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating multiple textboxes during runtime

Status
Not open for further replies.

rolan18

Programmer
May 11, 2006
26
CA
I am trying to create multiple textfields during runtime using the createTextField method in my actions layer.

I've tried to create them all in a loop in one movieclip, but that was only displaying one textfield, so I figured it was a problem with the movieclip... so now I'm trying to create a movieclip for each textfield without overwriting any of my other movieclips...

Here's my code for the textfields and movieclips:


var pixelsx:Number=_root.cyclo._x+20;
var pixelsy:Number=_root.cyclo._y + 20;
var boxNumber: Number=1;
var depth:String;
var layer:MovieClip;
var my_fmt:TextFormat= new TextFormat();

my_fmt.color= 0xFFFFFF


do{
depth=this.getNextHighestDepth();

layer.createEmptyMovieClip(("magnetic"+depth), Number(depth));

layer["magnetic"+depth].createTextField(("label" + boxNumber), magnetic.getDepth(),pixelsx,pixelsy,30,30);

pixelsx=pixelsx+30;
layer["magnetic"+depth}["label"+boxNumber].setTextFormat(my_fmt);

layer["magnetic"+depth]["label"+boxNumber].text="X";
boxNumber++;
}while(pixelsx<(_root.cyclo._x+_root.cyclo._width));


I'm wondering what I'm doing wrong or if there is a better/easier way to create textfields with unique names at runtime.

Thanks
 
Apart from few syntax errors, the biggest issue in your script is that "depth" is neither defined nor incremented so in every loop objects previously created are overwritten with new ones.

There's no need to create a new MovieClip for each TextFields. If you want to create multiple TextFields in "cyclo" you can do something like:

[tt]//
var pixelsx:Number = 20;
var pixelsy:Number = 20;
var boxNumber:Number = 1;
var depth:Number = 1;
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0xFFFFFF;
do {
cyclo.createTextField("label"+boxNumber, depth, pixelsx, pixelsy, 30, 30);
var tf:TextField = cyclo["label"+boxNumber];
with (tf) {
setNewTextFormat(my_fmt);
text = "X";
}
boxNumber++;
depth++;
pixelsx += 30;
} while (pixelsx<cyclo._width);
stop();
//[/tt]


Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top