2 Replies Latest reply on Nov 7, 2006 2:55 AM by DavidWhewell

    Resizing TextField objects problem

      Hi there,

      I am writing an AS3.0 application, which arranges TextField objects in a grid format. These may be of variable width and height, so each row/column works out how large it needs to be, by polling its contents for the largest width/height. (I was unable to find a pure AS3.0 object that does this sort of thing, but that's another story). The TextFields update over time, so their widths/heights change, and the grid dimensions with it. This is all working fine.

      However, what I am having a problem with, is I am trying to make the TextFields resize to fill the area of their "Cell" in the grid, if they are too small. This is because I am doing some highlighting with background/foreground colours, and want the effect to fill the whole cell. So for instance, if the Textfields in a column are 100, 100, 50 and 100 pixels wide, I want to make the 50-pixel wide one 100 pixels wide as well, so if its background colour changes, it affects the same width as the rest of them and looks right :)

      If I try to force the TextField's width property, it doesn't cooperate very well - sometimes it simply ignores it (I guess the rendering tells it what to do). I currently have the autoSize feature turned to TextFieldAutoSize.LEFT so it trims off from the default (100,100) dimension. I understand this may be what is interfering with the resizing I am trying to do. However, with autoSize set to TextFieldAutoSize.NONE, it seems to resize the entire text object (eg if it is 10 pixels wide, resizing it to 80 pixels wide makes the text 8 times bigger!!), which is obviously not what I'm after.

      I'm trying to do this TextField resize so I can keep all the highlight formatting in one place (ie I can just set the TextField forground and background, rather than its foreground and call some other object to set the background). Does anyone have any tips how I can accomplish this resizing of the TextFields to fit in the grid structure?

      Thanks very much in advance! :)

        • 1. Re: Resizing TextField objects problem
          peterent Level 2
          A quick question - did you look at the Grid layout <mx:Grid> container? Not the DataGrid, the Grid container. From your description I think it fits the bill.
          • 2. Re: Resizing TextField objects problem
            DavidWhewell Level 1
            hi peterent, thanks for getting back to me.

            the issue isn't the grid layout (i implemented my own because i wanted to have specific control over some of its layout abilities, and also, this is a pure AS3 project, without flex elements, to keep the file size tiny), but expanding the contents to fit the cell it's given, so they all line up correctly within it.

            i think i've got it - i implemented getter/setter methods for a variable in an interface for the text fields i mentioned, which then fires off events to control the highlighting. so i'm going to create a displayobjectcontainer which both contains the textfield and draws the background, but implements the interface, so i won't have to change the rest of the surrounding code :)

            if you have any suggestions for neater ways to control that issue of filling grid cells, with variable size contents, do let me know. but thanks!