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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:22:15+00:00 2026-05-13T06:22:15+00:00

Actionscript 3 I have been wrecking my head most today on the best way

  • 0

Actionscript 3

I have been wrecking my head most today on the best way of going about this, but i end up over complicating what i would believe to be a simple task.

I have some TextFields lined up next to each other all fixed width, i.e ( [ width ])

      tf1         tf2       tf3      tf4        tf5
[     80     ][   50   ][   50   ][  50   ][    70   ]

What i want to do is be able to select which detail i want to show, and then redistribute the width of the removed TextField to the rest (note you can only remove from the right), so if i was to show up to “tf3”, 120 (70+50) would need to be evenly distributed to the other boxes:

[      80 + 50 + 50 = 180                 ]
           tf1
[80/180*120 + 80 = 133.3]
                       tf2
               [50/180*120 + 50 = 83.3]
                                  tf3
                         [50/180*120 + 50 = 83.3]

Then line them up again (x + width etc):

 [      133.3       ][     83.3      ][     83.3     ]

Any ideas of a better method, i sure there is some nice easy functions i can use to do this.

I probably have overcomplicated the question too now, but ill give it a try, anyone have 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-05-13T06:22:15+00:00Added an answer on May 13, 2026 at 6:22 am

    So, let me get this straight, you have N text fields of differing widths and you want to remove 1 or more of them, rearranging the remaining M text fields, redistributing their widths proportionally (i.e. so if text field T1 was twice the width of text field T2, it would still be after they are rearranged)?

    This isn’t actually a very simple problem, but I’ve taken a stab at it below. You pass it the array of your text fields (from left to right), the number you want to keep, and an optional X-offset.

    Note: I haven’t done AS3 in months so consider the below to be pseudocode–you will have to edit it to make it work.

    function arrangeTextFields(textFields:Array, keep:int, xOffset:Number = 0) {
      // we can't keep more fields than are provided
      keep = Math.min(keep, textFields.length);
    
      var totalWidth    = 0, // the total width of all textfields
          keptOrigWidth = 0, // the total combined widths of the ones you're keeping
          origNum:int   = textFields.length;
    
      // calculate the above values by addition in a loop
      // (because AS3 lacks an inject/reduce method)
      for(var i:int, i++, i < origNum) {
        totalWidth += textFields[i].width;
    
        if(i < take) {
          keptOrigWidth += textFields[i].width;
        }
      }
    
      var ratio:Number = totalWidth / takenOrigWidth, // the ratio we'll resize each field by to keep them proportional
          currentX:int = 0; 
    
      textFields = textFields.slice(0, keep - 1); // throw away the fields we're not keeping
    
      for(int i = 0; i < take; i++) {
        textFields[i].width = textFields[i].width * ratio; // resize it
        textFields[i].x     = currentX + xOffset;          // move it
    
        currentX += textFields[i].width;
      }  
    }
    

    Note: This code doesn’t actually remove the “unkept” text fields from view; you’ll have to add that or do it elsewhere.

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

Sidebar

Related Questions

I have been trying to understand the way ActionScript's events are implemented, but I'm
I have been programming flash/actionscript for a number of years; is there a way
In Actionscript you can have global variables like this: var number : Number =
I have a pure Actionscript 3 project, using flash.* libraries, compiles down to about
I have been given a book on Actionscript 3 and I am looking to
I have been successful in dynamically loading an album in SSP before, but using
I've been writing ActionScript for nigh on 10 years; but I've always used separate
I have been developing in ASP.NET and c#, actionscript flash/flex cs3, and the iPhone.
I have been moving over to JavaScript (esp. canvas) from Flash / Flex /
I'm looking for a reliable mocking framework for ActionScript. I've been using mock-as3, but

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.