# Setting final mc position depending on text height

**URL:** <https://forum.kirupa.com/t/setting-final-mc-position-depending-on-text-height/22244>\
**Category:** flash\
**Created:** [June 1, 2003, 5:23pm UTC](https://forum.kirupa.com/t/setting-final-mc-position-depending-on-text-height/22244 "2003-06-01T17:23:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felipe\_Bastos](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@Felipe\_Bastos](https://forum.kirupa.com/u/Felipe_Bastos)\
**Post date:** [June 1, 2003, 5:23pm UTC](https://forum.kirupa.com/t/setting-final-mc-position-depending-on-text-height/22244/1 "2003-06-01T17:23:31Z")

</div>

I have an empty mc called “attachmcextra”.  
Into this empty mc is attached another mc called “mcnote” that contains a texto box named “loadnote”. So it`s path would be:

**\_root.attachextra.mcnote.loadnote**

The following code is set to the mc “attachextra”:

onClipEvent (load) {  
//set inicial position  
this.posY = 20;  
}

onClipEvent (enterFrame) {  
cY = this.\_y;  
difY = cy-this.posY;  
setProperty(this, \_y, cY-(difY/2.5));  
}

So when I click on btn\_note01 it sends the mc to some posY (vertical movement). But the notes have different amount of text, logically have different loadnote height.

[color=red]Is it possible to set the **“attachextra”** mc posY depending on the final loadnote height loaded?[/color] Note that the mc has a downward movement? It`s inicial position is y=20 and maximum is y=400.

Again: can I send the “attachextra” mc to a Y position depending on the text height loaded to “loadnote”?

I coul not attach the swf file  
Click [here](mailto:felipe@nwi.com.br) to ask me for the file.  
Thanks

:rd:

---

<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:** [June 2, 2003, 5:03am UTC](https://forum.kirupa.com/t/setting-final-mc-position-depending-on-text-height/22244/2 "2003-06-02T05:03:52Z")

</div>

I use this function to get the height of a textField (it’s somewhat inefficient, but it works like a charm):

```auto

// use this functoin to get the height of any textfield 
// with given string, width, font, size, and whether or not it is html
function getTextHeight(str, wd, font, size, htm) {
	// str: the string of which the Height of the textblock will be returned
	// wd: the width of the textblock, find height if text remains this wide
	// font:	the font in which the textblock will be displayed
	// size: the fontsize at which the textblock will be displayed
	// htm:	"html"||undefined, whether text is rendered as html or not
	
	// create an empty holder movieclip
	_root.createEmptyMovieClip("txtSizer_mc", 1000000);
	_root.txtSizer_mc._alpha = 100;
	// make clip invisible
	with (_root.txtSizer_mc) {
		// create the textfield and display the text
		createTextField("txtSizer_txt", 1000001, 0, 0, wd, 300);
		var sizer_tf = new TextFormat();
		sizer_tf.font = font;
		sizer_tf.size = size;
		sizer_tf.color = "0x000000";
		with (txtSizer_txt) {
			multiline = true;
			wordWrap = true;
			if (htm == "html") {
				html = true;
				htmltext = str;
			} else {
				text = str;
			} // end "if html"
			setTextFormat(sizer_tf);
		}	// end "with" grouping
		var thisSize = _root.txtSizer_mc.txtSizer_txt.textHeight;
		removeMovieClip(); // remove the test clip
	} // end "with" grouping
	return thisSize;
} // end getTextHeight()

```

You include this code in your file and then you use it like this (assuming you have a text string named “myString”):

```auto

var myTextHeight = getTextHeight(myString, 200, "arial", 10);

```

This will find the height of a text field that is 200 pixels wide, arial font, 10pt. You can adjust the parameters for whatever you need. Now you have “myTextHeight” that is the height of the textfield and then you can use that variable in your code.
