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 8531345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:27:46+00:00 2026-06-11T09:27:46+00:00

I have a rectangle on which I would like to display a label. I

  • 0

I have a rectangle on which I would like to display a label. I have tried to do this by creating a rectangle sprite, and then adding a textField to the display tree of the sprite.

The problem is that there seems to be a lot of extra blank padding surrounding the textField. Although the text fits within the box, the boundaries of the textField extend beyond the visible region of it’s containing rectangle. This causes the rectangle’s width and height to change also.

The issue is that I want the user to be able to drag the rectangle around the screen. I added an event listener on MOUSE_DOWN to initiate the drag. However, the user can start the drag by clicking on the area surrounding the visible rectangle, rather than only on the rectangle itself. I assume this is because the user will actually be clicking on the extra blank space coming from the the TextField and seeping out over the edges

Any ideas?

  • 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-06-11T09:27:47+00:00Added an answer on June 11, 2026 at 9:27 am

    I think what you’re looking for is the textField.autoSize parameter. It makes the text field bounds shrink to the size of the text (otherwise it has a default height/width regardless of the text it contains)

    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    
    var textField:TextField = new TextField();
    
    textField.autoSize = TextFieldAutoSize.LEFT;
    textField.text = "your text"; //set this AFTER autoSize
    

    You can also set the width of the your textField to the width of your rectangle. Or forgo the autosize property and manually set the height/width of your text box to the height/width of the rectangle, though this would truncate any text that doesn’t fit.

    There is always some padding on the text field. Getting the exact bounds of the actual text can be tricky (though it is possible). An easier way is to just mask your text box.

    If your rectangle is drawn with the graphics class, you could do this:

    var rectangle:Sprite = new Sprite();
    rectangle.graphics.beginFill(0xFF0000);
    rectangle.graphics.drawRect(0,0,100,100);
    addChild(rectangle);
    
    var myMask:Shape = new Shape();
    myMask.graphics.copyFrom(rectangle.graphics);
    rectangle.addChild(myMask);
    
    var textField:TextField = new TextField();
    textField.width = rectangle.width;
    textField.height = rectangle.height;
    textField.mask = myMask;
    
    rectangle.addChild(textField);
    

    One other option you could do, is in your event listener, check to see if the target is the text box and exit the function. (just make sure your text field’s mouseEnabled property is true (default) if you use this method)

    function rectangleClickHandler(e:Event):void {
        if(e.target == myTextField) return;
        //rest of your code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a rectangle drawable like this: <shape xmlns:android=http://schemas.android.com/apk/res/android android:shape=rectangle> <corners android:radius=4dip/> <solid
I have created a Rectangle inside of a ScrollViewer like this <ScrollViewer ManipulationMode=Control x:Name=songScrollViewer
I would like to have some text to be inside a rectangle with stroke
I would like to draw a rectangle (or more) which printed on paper shows
I have a custom UIView on which I would like to show simple animated
I have 2 groupboxes which I would like to customise a bit more, and
I have a group of shapes like this: Group g = new Group(); Rectangle
I have a rectangle which has known width and height.Now devide rectangle diagonally to
I have a Flex application in which I draw a rectangle using: <s:Rect height=20
I have a rectangle that I've created and set its individual properties like so

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.