# Problem with TextField

**URL:** <https://forum.kirupa.com/t/problem-with-textfield/233899>\
**Category:** flash\
**Created:** [July 27, 2007, 8:23pm UTC](https://forum.kirupa.com/t/problem-with-textfield/233899 "2007-07-27T20:23:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NaveenRam](https://avatars.discourse-cdn.com/v4/letter/n/ecc23a/32.png) [@NaveenRam](https://forum.kirupa.com/u/NaveenRam)\
**Post date:** [July 27, 2007, 8:23pm UTC](https://forum.kirupa.com/t/problem-with-textfield/233899/1 "2007-07-27T20:23:25Z")

</div>

I started with making a new class for extended TextField. What is my objective is to have a transform tool for the textField to resize it and i’ve done it. The problem is when i reduce the textfield it should stop resizing while hitting the textBound just like the one we’re using in Flash authoring. But it doesn’t.

here is the code

```auto
package components
{
import flash.events.*;
import flash.display.*;
import flash.text.*;

public class textComponent extends Sprite
{
    private var _textHtml:String;
    private var _type:String;
    private var _transformTool:Sprite = new Sprite();
    private var txtInput:TextField = new TextField();
    private var _textHeight:Number;
    private var _textWidth:Number;
    private var toolPress:Boolean = false;
    
    public function textComponent()
    {
        addChildAt(txtInput,0);
        txtInput.multiline = true;
        txtInput.wordWrap = true;
        txtInput.border = true;
        txtInput.borderColor = 0x000000;
        txtInput.type = "input";
        addChild(_transformTool);
        drawTransformTool();
        _transformTool.addEventListener(MouseEvent.MOUSE_MOVE, function(e){if(e.buttonDown){txtInput.width = _transformTool.x; txtInput.height = _transformTool.y;trace(txtInput.textWidth + " : "+ getBounds(txtInput));}});
        _transformTool.addEventListener(MouseEvent.MOUSE_DOWN, function(e){e.target.startDrag();});
        _transformTool.addEventListener(MouseEvent.MOUSE_UP, function(e){e.target.stopDrag();});
    }
    public function get textHtml():String {
        return _textHtml;
    }
    public function set textHtml(txt:String) {
        txtInput.htmlText =txt;
    }
    private function drawTransformTool()
    {
        _transformTool.x=txtInput.width;
        _transformTool.y=txtInput.height;
        _transformTool.graphics.clear();
        _transformTool.graphics.beginFill(0x0);
        _transformTool.graphics.lineStyle(1,0xFFFFFF);
        _transformTool.graphics.drawRect(-3,-3,6,6);
        _transformTool.graphics.endFill();
    }
}
}

```

Also i initantiate the new class in the swf as

```auto
import components.textComponent;

var tft:textComponent = new textComponent();
addChild(tft);

tft.textHtml = "<img src='http://in.yimg.com/i/in/adv/housead/592091_bm_may3.gif' hspace='5' vspace='5'>Hi, this is a new text Component";

```

please help me.

Also i’ve the following doubt about the TextField class

The TextField class can hold an image (instance of Loader class). If that so be it contains a displayobject and it should be a subclass of DisplayobjectContainer. Why it doesn’t ? Is there any technique to get the number of images (such as numChildren) except parsing the htmlText property.

I tried the following code, but it fails

var spr:DisplayObjectContainer = txtField as DisplayObjectcontainer;  
trace(spr.numChildren);
