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 to ask me for the file.
Thanks
:rd:
I use this function to get the height of a textField (it’s somewhat inefficient, but it works like a charm):
// 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”):
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.