# \[AS3\] Textfield in a Subclass

**URL:** https://forum.kirupa.com/t/as3-textfield-in-a-subclass/198425
**Category:** flash
**Created:** [August 24, 2006, 10:43pm UTC](https://forum.kirupa.com/t/as3-textfield-in-a-subclass/198425 "2006-08-24T22:43:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![knalpot](https://avatars.discourse-cdn.com/v4/letter/k/d6d6ee/32.png) [@knalpot](https://forum.kirupa.com/u/knalpot)
#### Post date: [August 24, 2006, 10:43pm UTC](https://forum.kirupa.com/t/as3-textfield-in-a-subclass/198425/1 "2006-08-24T22:43:55Z")

</div>

Hi  
I’m working on a AS3 Project in Flex 2 and I’ve been looking for hours for a solution to a (I’m sure very simple) problem: it’s a pure AS3 Project, so no mxml file, and I try to output text in a textfield created in a subclass. I’ve read a lot of posts and the documentation and whatever I could get hold of, but it only outputs when I define the textfield in the main application class.

If I define the field in a subclass, which is imported properly in the main class with the “new” statement instantiated, nothing happens. To illustrate it, take these examples:

Works perfect:

```auto
package {
    import flash.display.Sprite;
    import flash.text.*;

    public class whynot extends Sprite
    {
        private var display_txt:TextField;

        public function whynot()
        {
            display_txt = new TextField();
            display_txt.text = "a text";
            addChild(display_txt);    
        }
    }
}

```

No output from this:

```auto
Filename: whynot.as (the main application class):
package {
    import flash.display.Sprite;
    import OutputTheThing;

    public class whynot extends Sprite
    {
        private var theText:OutputTheThing;

        public function whynot()
        {
            theText = new OutputTheThing();    
        }
    }
}

Filename OutputTheThing.as:
package
{
    import flash.display.Sprite;
    import flash.text.*;

    public class OutputTheThing extends Sprite
    {
        private var display_txt:TextField;

        public function OutputTheThing()
        {
            display_txt = new TextField();
            display_txt.text = "a text";
            addChild(display_txt);    
        }

    }
}

```

Any ideas? I feel very stupid, I must have missed some basic idea of actionscript programming.  
Thanks for any help,  
Phil
