# autoSize vs. Text field - AS2

**URL:** <https://forum.kirupa.com/t/autosize-vs-text-field-as2/309945>\
**Category:** flash\
**Created:** [May 28, 2010, 8:54am UTC](https://forum.kirupa.com/t/autosize-vs-text-field-as2/309945 "2010-05-28T08:54:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anthony\_z](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@anthony\_z](https://forum.kirupa.com/u/anthony_z)\
**Post date:** [May 28, 2010, 8:54am UTC](https://forum.kirupa.com/t/autosize-vs-text-field-as2/309945/1 "2010-05-28T08:54:15Z")

</div>

Hey everyone,

I have a quick newbie question for you, as I am not a programmer.  
I want to autoSize my text field.

I have a text scrollbar module. Text is coming from an XML file and I simply want the text field to autoSize itself, according to the XML text length. Allowing me to feed infinite text into it.

Structure: [FONT=Arial]mc\_text \> contentMC \> tText[/FONT]

“mc\_text” is the main MovieClip, which contains “contentMC” and inside that you find the text field “tText” that needs to be autoSized.

[FONT=Arial]Instance names:[/FONT]

[FONT=Arial]scroller’s track: scRollBarMC[/FONT]  
[FONT=Arial]scroller’s slider: scrollBar[/FONT]  
[FONT=Arial]text field mask: mask[/FONT]

[FONT=Arial]I found the autoSize code already, but i don’t know how to apply it, where to put it etc, so please paste the proper code into my script and copy the corresponding chunk into your answer, if you can.  
[/FONT]

[FONT=Arial]If you have any questions let me know, thanks!  
[/FONT]

```auto

    [FONT=Arial]//This all MOVIE CLIP and BUTTON CURSOR visible FALSE[/FONT]
  [FONT=Arial]MovieClip.prototype.useHandCursor=false;[/FONT]
  [FONT=Arial]Button.prototype.useHandCursor=false;[/FONT]
  [FONT=Arial]//This SCROLL as ![/FONT]
  [FONT=Arial]function moveUnit(num){[/FONT]
  [FONT=Arial] if(num > 0){[/FONT]
  [FONT=Arial] if((currentPer + v * num) < 100){[/FONT]
  [FONT=Arial] movecontentMC(currentPer = currentPer + v * num);[/FONT]
  [FONT=Arial] moveScrollBar(currentPer = currentPer + v * num);[/FONT]
  [FONT=Arial] } else {[/FONT]
  [FONT=Arial] movecontentMC(100);[/FONT]
  [FONT=Arial] moveScrollBar(100);[/FONT]
  [FONT=Arial] delete this.onEnterFrame;[/FONT]
  [FONT=Arial] }[/FONT]
  [FONT=Arial] } else if((currentPer + v * num) > 0){[/FONT]
  [FONT=Arial] movecontentMC(currentPer = currentPer + v * num);[/FONT]
  [FONT=Arial] moveScrollBar(currentPer = currentPer + v * num);[/FONT]
  [FONT=Arial] } else {[/FONT]
  [FONT=Arial] movecontentMC(0);[/FONT]
  [FONT=Arial] moveScrollBar(0);[/FONT]
  [FONT=Arial] delete this.onEnterFrame;[/FONT]
  [FONT=Arial] }[/FONT]
  [FONT=Arial]}[/FONT]
  [FONT=Arial]currentPer = 0;[/FONT]
  [FONT=Arial]MH = mask._height;[/FONT]
  [FONT=Arial]CH = contentMC._height;[/FONT]
  [FONT=Arial]SBH = scRollBarMC.body._height;[/FONT]
  [FONT=Arial]ratio = MH / CH * SBH;[/FONT]
  [FONT=Arial]scrollBar.body._height = ratio;[/FONT]
  [FONT=Arial]SH = scrollBar.body._height;[/FONT]
  [FONT=Arial]scrollBar.bottom._y = SH;[/FONT]
  [FONT=Arial]v = ratio / 100;[/FONT]
  [FONT=Arial]contentMC.xMin = contentMC._x;[/FONT]
  [FONT=Arial]contentMC.yMin = contentMC._y;[/FONT]
  [FONT=Arial]contentMC.xMax = contentMC._x;[/FONT]
  [FONT=Arial]contentMC.yMax = contentMC._y - (CH - MH);[/FONT]
  [FONT=Arial]scrollBar.xMin = scrollBar._x;[/FONT]
  [FONT=Arial]scrollBar.yMin = scrollBar._y;[/FONT]
  [FONT=Arial]scrollBar.xMax = scrollBar._x;[/FONT]
  [FONT=Arial]scrollBar.yMax = (scrollBar._y + SBH) - SH;[/FONT]
  [FONT=Arial]scrollBar["onPress"] = function (){[/FONT]
  [FONT=Arial] this.startDrag(false, this.xMin, this.yMin, this.xMax, this.yMax);[/FONT]
  [FONT=Arial] this["onMouseMove"] = function (){[/FONT]
  [FONT=Arial] this.dis = Math.round(((this._y - this.yMin)) / ((this.yMax - this.yMin)) * 100);[/FONT]
  [FONT=Arial] movecontentMC(this.dis);[/FONT]
  [FONT=Arial] }[/FONT]
  [FONT=Arial]}[/FONT]
  [FONT=Arial]//SCROLL BAR actionscript code[/FONT]
  [FONT=Arial]scrollBar.onRelease = scrollBar.onReleaseOutside = function () {[/FONT]
  [FONT=Arial] delete this.onMouseMove; [/FONT]
  [FONT=Arial] this.stopDrag(); [/FONT]
  [FONT=Arial]};[/FONT]
  
  
  [FONT=Arial]moveScrollBar = function (num) {[/FONT]
  [FONT=Arial] scrollBar.onEnterFrame = function () {[/FONT]
  [FONT=Arial] this._y += ((this.yMin + ((this.yMax - this.yMin)) * num / 100) - this._y) * 0.2; [/FONT]
  [FONT=Arial] if (Math.abs(((this.yMin + ((this.yMax - this.yMin)) * num / 100) - this._y)) < 1){[/FONT]
  [FONT=Arial] this._y = this.yMin + ((this.yMax - this.yMin)) * num / 100; [/FONT]
  [FONT=Arial] delete this.onEnterFrame; [/FONT]
  [FONT=Arial] }[/FONT]
  [FONT=Arial] };[/FONT]
  [FONT=Arial]};[/FONT]
  [FONT=Arial]movecontentMC = function (num) {[/FONT]
  [FONT=Arial] contentMC.onEnterFrame = function () {[/FONT]
  [FONT=Arial] this._y += ((this.yMin + ((this.yMax - this.yMin)) * num / 100) - this._y) * 0.2; [/FONT]
  [FONT=Arial] if (Math.abs(((this.yMin + ((this.yMax - this.yMin)) * num / 100) - this._y)) < 1){[/FONT]
  [FONT=Arial] this._y = this.yMin + ((this.yMax - this.yMin)) * num / 100; [/FONT]
  [FONT=Arial] currentPer = num; [/FONT]
  [FONT=Arial] delete this.onEnterFrame; [/FONT]
  [FONT=Arial] }[/FONT]
  [FONT=Arial] };[/FONT]
  [FONT=Arial]};[/FONT]
  [FONT=Arial]//mouseWHEEL AS ![/FONT]
  [FONT=Arial]if(MH < CH){[/FONT]
  [FONT=Arial] wheel = new Object();[/FONT]
  [FONT=Arial] wheel["onMouseWheel"] = function (w){[/FONT]
  [FONT=Arial] moveUnit(w * -1);[/FONT]
  [FONT=Arial] }[/FONT]
  [FONT=Arial] Mouse.addListener(wheel);[/FONT]
  [FONT=Arial]} [/FONT]
  [FONT=Arial]else [/FONT]
  [FONT=Arial]{[/FONT]
  [FONT=Arial] scrollBar._visible = false;[/FONT]
  [FONT=Arial] delete scrollBar.onPress;[/FONT]
  [FONT=Arial] delete scrollBar.onRelease;[/FONT]
  
  [FONT=Arial]}[/FONT]
  [FONT=Arial]//end ![/FONT]
  

```
