# Help needed with dynamic textfields

**URL:** <https://forum.kirupa.com/t/help-needed-with-dynamic-textfields/55155>\
**Category:** Uncategorized\
**Created:** [June 21, 2004, 4:54pm UTC](https://forum.kirupa.com/t/help-needed-with-dynamic-textfields/55155 "2004-06-21T16:54:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![firstSteps](https://avatars.discourse-cdn.com/v4/letter/f/b487fb/32.png) [@firstSteps](https://forum.kirupa.com/u/firstSteps)\
**Post date:** [June 21, 2004, 4:54pm UTC](https://forum.kirupa.com/t/help-needed-with-dynamic-textfields/55155/1 "2004-06-21T16:54:12Z")

</div>

Hi all,  
i have used this code to make a textfield, but would like to know how to change it into a function so i can re-create the textfields anywhere i like and just change the value of tData to an other string.Im using 2004pro and actionScript2  
//--------------------------------------------------------------------  
var nWidth:Number = mcDisplayBackground.\_width;  
var nHeight:Number = mcDisplayBackground.\_height+1;  
var nX:Number = mcDisplayBackground.\_x+3;  
var nY:Number = mcDisplayBackground.\_y-1.5;  
this.createTextField(“tData”, this.getNextHighestDepth(), nX, nY, nWidth, nHeight);  
tData.text = “INTERACTIVE PORTFOLIO”;  
tData.selectable = false;  
tData.multiline = false;  
tData.wordWrap = false;  
var tfFormatter:TextFormat = new TextFormat();  
tfFormatter.font = “kroeger 05\_56”;  
tfFormatter.size = 8;  
tfFormatter.color = 0x7fdc09;  
tData.setTextFormat(tfFormatter);  
};  
//------------------------------------------------------------

any help would be welcome

firstSteps

---

<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:** [July 6, 2004, 6:29pm UTC](https://forum.kirupa.com/t/help-needed-with-dynamic-textfields/55155/2 "2004-07-06T18:29:39Z")

</div>

Well, you could just make the mcDisplayBackground be a parameter of the function

```auto

MovieClip.prototype.create_text=function(textnam, backgroundClip){
var nWidth:Number = backgroundClip._width;
var nHeight:Number = backgroundClip._height+1;
var nX:Number = backgroundClip._x+3;
var nY:Number = backgroundClip._y-1.5;
this.createTextField("tData", this.getNextHighestDepth(), nX, nY, nWidth, nHeight);
tData.text = textnam;
tData.selectable = false;
tData.multiline = false;
tData.wordWrap = false;
var tfFormatter:TextFormat = new TextFormat();
tfFormatter.font = "kroeger 05_56";
tfFormatter.size = 8;
tfFormatter.color = 0x7fdc09;
tData.setTextFormat(tfFormatter);
}

```

Which would be called as  
\_root.create\_text(“YOUR TEXT1”, mcDisplayBackground);  
\_root.create\_text(“YOUR TEXT2”, mcDisplayBackground2);  
Which would make two text clips, at different positions.

---

<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:** [July 6, 2004, 7:02pm UTC](https://forum.kirupa.com/t/help-needed-with-dynamic-textfields/55155/3 "2004-07-06T19:02:33Z")

</div>

Hi Dunga,  
thanks for your help, i took your advice and this is what i have done it seems to work even if it’s a bit long winded and not very godd scripting

//-------------------------------------------------------------  
//--------------------------------------------- textfields--------------------------------------  
var sGreenFormat:TextFormat = new TextFormat(“kroeger 06\_56”, 8, 0x7FDC09);  
var sWhiteFormat:TextFormat = new TextFormat(“kroeger 06\_56”, 8, 0xFFFFFF);  
var sGreyFormat:TextFormat = new TextFormat(“kroeger 06\_56”, 8, 0x9A9A9A);  
MovieClip.prototype.create\_text = function(sTextName, newDepth, TFormat, SizeMC, nX, nY, nWidth, nHeight) {  
trace(" \>\>\> " + this + “.create\_text() \>\>\>”);  
TFormat = (TFormat == undefined) ? tfFormatter : TFormat;  
SizeMC = (SizeMC == undefined) ? mcDisplayBackground : SizeMC;  
newDepth = (newDepth == undefined) ? 0 : newDepth;  
nX = (nX == undefined) ? 3 : nX;  
nY = (nY == undefined) ? -1.5 : nY;  
nWidth = (nWidth == undefined) ? SizeMC.\_width: nWidth;  
nHeight = (nHeight == undefined) ? SizeMC.\_height+1 : nHeight;  
trace(“Creating new text: tData”+newDepth+", “+nX+”, “+nY+”, “+nWidth+”, “+nHeight);  
this.createTextField(“tData”+newDepth, newDepth, nX, nY, nWidth, nHeight);  
var t = this[“tData” + newDepth];  
trace(” t: " + t);  
with(t){  
embedFonts = true;  
selectable = false;  
multiline = false;  
wordWrap = false;  
text = sTextName;  
setTextFormat(TFormat);  
}  
};  
this.create\_text(“INTERACTIVE PORTFOLIO”, 0, sGreenFormat ,mcDisplayBackground, mcDisplayBackground.\_x+3, mcDisplayBackground.\_y-1);  
mcMenu.mcTitleMenu.create\_text(“MENU”, 1, sGreenFormat, mytest, undefined, -2);  
stop();

🙂

i could do with some help thou on another post i have put on text  
firstSteps
