如何使动态文本框下推其他控件

发布于 2024-12-19 18:36:50 字数 278 浏览 1 评论 0原文

这是一个非常简单的问题,我认为很容易在谷歌上找到,但我想不出术语。

我正在使用 CS4 和 AS3,并在彼此下方放置一些多行动态文本框。当我填充顶部文本框时,我希望当内容流到额外的行时它会自动下推其下方的其他文本框。

目前,它仅环绕到每个文本框之间的间隙,但在到达下面的文本框时停止。

是否有一个属性允许这样做(我在 Silverlight 中工作过,并且那里有控件),我可以设置它,或者我必须手动实现它并调用功能以在每次我时重新设置所有控件 y 属性更改文本框中的文本?

谢谢

This is a really easy one that I thought would be easily found on google but I can't think of the terminology.

I'm using CS4 and AS3 with a few multi-line dynamic text boxes beneath one another. When I populate the top text box I would like it to automatically push down the other text boxes beneath it when the content flows on to extra lines.

At the moment it only wraps to the gap that is between each text box but then stops when reaching the text box beneath.

Is there a property to allow for this (I've worked in Silverlight and there was on controls there) that I can just set or will I have to manually implement this and call functionality to re-set all the controls y properties each time I change the text in the text box?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落□心尘 2024-12-26 18:36:50

首先,您需要自动调整文本字段的大小

myTextField.autoSize = TextFieldAutoSize.LEFT

,然后需要监听文本字段的更改,或者用户

myTextField.addEventListener(Event.CHANGE, function(e:Event):void{
    var newHeight:number = myTextField.height;
}

根据新的高度在其中输入内容,您可以向上或向下移动其下方的其他元素

first you need the textfield to be autosized

myTextField.autoSize = TextFieldAutoSize.LEFT

then you need to listen to the textfield changes, or the user typing in it

myTextField.addEventListener(Event.CHANGE, function(e:Event):void{
    var newHeight:number = myTextField.height;
}

based on the new height you can move the other elements under it up or down

冷血 2024-12-26 18:36:50

我不知道有任何属性可以轻松做到这一点,但我已经手动实现了类似的东西。每当您想要调整文本字段时,请调用与此类似的函数:
(未经测试的代码)

 private function arrangeText():void {

    var maxWidth:Number = 400; //the ending width of your

    //Set width to something low for all textfields, 
    //to get accurate reading of textWidth
    txtTitle.width = 200; 
    txtSub.width = 200;

    //Set autosizing temporarily
    txtTitle.autoSize = TextFieldAutoSize.LEFT;
    txtSub.autoSize = TextFieldAutoSize.LEFT;

    //Get roughly the number of lines required to display all the text
    var titleLines:Number = Math.ceil(txtTitle.textWidth / maxWidth) - 1;
    var subLines:Number = Math.ceil(txtSub.textWidth / maxWidth) - 1;

    //Now that you know roughtly how many lines are needed, 
    //Take off autosizing
    txtTitle.autoSize = TextFieldAutoSize.NONE;
    txtSub.autoSize = TextFieldAutoSize.NONE;

    //set textfield widths bask to normal
    txtTitle.width = maxWidth;
    txtSub.width = maxWidth;

    //Apply new height values to textfields
    //Prevent textfields from being too tall as well with the "> 3" part
    txtTitle.height = (titleLines > 3 ? 100 : txtTitle.textHeight) + 5;
    txtSub.height = (subLines > 3 ? 60 : txtSub.textHeight) + 5;

    //Starting from the top going down
    //Move each of your textfields under the previous one
    txtSub.y = txtTitle.x + txtTitle.height;

}

I'm not aware of any property to easily do this, but I have manually implemented something similar. Whenever you want to adjust your textFields call a function similar to this:
(untested code)

 private function arrangeText():void {

    var maxWidth:Number = 400; //the ending width of your

    //Set width to something low for all textfields, 
    //to get accurate reading of textWidth
    txtTitle.width = 200; 
    txtSub.width = 200;

    //Set autosizing temporarily
    txtTitle.autoSize = TextFieldAutoSize.LEFT;
    txtSub.autoSize = TextFieldAutoSize.LEFT;

    //Get roughly the number of lines required to display all the text
    var titleLines:Number = Math.ceil(txtTitle.textWidth / maxWidth) - 1;
    var subLines:Number = Math.ceil(txtSub.textWidth / maxWidth) - 1;

    //Now that you know roughtly how many lines are needed, 
    //Take off autosizing
    txtTitle.autoSize = TextFieldAutoSize.NONE;
    txtSub.autoSize = TextFieldAutoSize.NONE;

    //set textfield widths bask to normal
    txtTitle.width = maxWidth;
    txtSub.width = maxWidth;

    //Apply new height values to textfields
    //Prevent textfields from being too tall as well with the "> 3" part
    txtTitle.height = (titleLines > 3 ? 100 : txtTitle.textHeight) + 5;
    txtSub.height = (subLines > 3 ? 60 : txtSub.textHeight) + 5;

    //Starting from the top going down
    //Move each of your textfields under the previous one
    txtSub.y = txtTitle.x + txtTitle.height;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文