Help needed with dynamic textfields

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

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


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.

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

:slight_smile:

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