Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3224774
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:15:45+00:00 2026-05-17T16:15:45+00:00

I have a sprite that contains a textfield. Then, I want to create a

  • 0

I have a sprite that contains a textfield. Then, I want to create a second sprite (“containerSprite”) which is the same size as the textfield. That’s not difficult and works fine.

Now I want to add a third sprite (“innerSprite”) to containerSprite. I need this third sprite because I’m going to use it for drag and drop purposes. I add a textfield to it, and I want the textfield to be the same width as both containerSprite and innerSprite. Depending on how much text is in the textfield, I need innerSprite to resize its height accordingly.

This should be simple. It isn’t working. What am I doing wrong?

Thanks,

David

package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;

public class SpriteAndTextField extends Sprite
{
    private var innerText:TextField;
    private var innerSprite:Sprite;
    private var containerSprite:Sprite

    public function SpriteAndTextField()
    {
        var tf:TextField = new TextField();
        tf.type = TextFieldType.INPUT;
        tf.width = 300;
        tf.height = 200;
        tf.x = 0;
        tf.y = 100; 
        tf.selectable = true;
        tf.border = true;
        tf.background = true;
        tf.backgroundColor = 0xCCCCCC;
        tf.multiline = true;
        tf.wordWrap = true;
        tf.text = "Some text here."
        addChild(tf);

        //containerSprite

        containerSprite = new Sprite();
        containerSprite.x = tf.x + tf.width + 10;
        containerSprite.y = tf.y;
        containerSprite.graphics.beginFill(0xFFFFFF,1 )
        containerSprite.graphics.drawRect(0, 0, tf.width, tf.height);
        containerSprite.graphics.endFill();
        containerSprite.name = "containerSprite";
        addChild(containerSprite);

        //now add another sprite, with a textfield. We want the sprite and the textfield it contains to be the same width
        //as the containerSprite. The innerSprite's height should be determined by however much text is in its child
        //textfield
        innerSprite = new Sprite();
        //not setting x and y, so it should appear at 0,0 of its parent containerSprite
        innerSprite.width = containerSprite.width;
        containerSprite.addChild(innerSprite);

        //add textfield to inner sprite
        innerText = new TextField();
        innerText.selectable = true;
        innerText.border = true;
        innerText.background = true;
        innerText.backgroundColor = 0xFFFF00;
        innerText.multiline = true;
        innerText.wordWrap = true;
        innerText.text = "The TextField class is used to create display objects for text display and input. All dynamic and input text fields in a SWF file are instances of the TextField class."
        innerSprite.addChild(innerText);
    }        

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:15:45+00:00Added an answer on May 17, 2026 at 4:15 pm

    Ultimately, Sprites adjust their size to match the content placed within them. If you are resizing a sprite that has DisplayObject children, you’re going to end up scaling those children instead of just resizing the container.

    If the TextField’s width is set to the width you want the InnerSprite to be, and you add the TextField to that Sprite, your Sprite will become that width (as long as the TextField is at 0, 0). Similarly, as the TextField’s vertical size increases/decreases, so will the Sprite that contains it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have emoticons in a css sprite image that I want to display within
(using flash) I have a Sprite object that I want to show on google
I have one div classA that contains inside one sprite element of classB. I
Here is the setup: I have a class called Sprite that contains an image
I have a Sprite that contains opaque objects surrounded by transparent pixels. I also
I have a sprite loaded from a PNG that has an alpha channel. The
I have created a nice joomla website with a sprite navigation that works fine
I'm currently working on the interesting example in cocos2d. I have a sprite, that
I have a logo link that's using a background-image (css sprite). All works fine,
I have a class called Sprite, and ballSprite is an instance of that class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.