制作 AS3“文本字段”使用buttonMode和useHandCursor

发布于 2024-12-29 18:37:28 字数 539 浏览 1 评论 0原文

抱歉,标题不好。想不出更好的了...

我正在开发一款可以使用 XML 加载的数据进行配置的软件。 用户可以定义文本字段的最大“宽度”,并且文本字段是多行的,当文本不适合宽度时会发生换行。 TextFields 的文本也是从 XML 文件加载的,并且长度是任意的。

因为 TextField 既没有 buttonMode 也没有 useHandCursor 属性,所以我将 TextFields 设为精灵的子级。因此,对于每个 TextField 都有一个精灵作为父级。

那么真正的问题是:(

“TextFields”实际上是以 TextField 作为子级的精灵)

“TextFields”不应该在其中的文本之外可单击。目前,精灵似乎延伸到文本字段的整个宽度,因此用户实际上可以从没有文本的区域单击“文本字段”。

我“尝试”更改精灵的大小,检查了 AS3 参考,现在我知道为什么之后一切都消失了。

所以我需要一个解决方案,其中“TextFields”启用了 buttomMode 和 useHandCursor,并且容器应该能够切断没有文本的区域。

Sorry for the bad title. Couldn't think of a better one...

I'm doing a software that is configurable with loaded data from XML.
User can define the max "width" of an TextField and the TextFields are multiline and wrapping happens when the text wouldn't fit the width. Text for the TextFields is also loaded from the XML file and the length is arbitrary.

Because TextField doesn't have neither buttonMode or useHandCursor properties I made TextFields children of sprites. So for every TextField there is a sprite as a parent.

Then the real problem:

("TextFields" are actually the sprites with a TextField as a child)

The "TextFields" should not be clickable outside of the text in them. At the moment it seems like that the sprites extend to the full width of the TextFields and therefore user can actually click the "TextFields" from an area where there is no text.

I "tried" to change the size of the sprite, checked the AS3 reference and now I know why everything disappeared after that.

So I need a solution in which, the "TextFields" have buttomMode and useHandCursor enabled and the container should be able to cut off the area where there is no text.

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

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

发布评论

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

评论(2

半窗疏影 2025-01-05 18:37:28

TextField 对象具有一些默认的大小调整特征。您需要应用其中之一:

到此属性:

使其适合您的文本。然后通过将其添加到一个空的 Sprite 中,所述 Sprite 也将是您的文本的确切大小。

更改 Sprite 的大小是错误的方法,因为在这种情况下您实际上所做的是缩放其内部内容。精灵会自动调整自身大小以适应它们所包含的对象。只要您确保 TextField 的大小正确,父 Sprite 的大小也将正确。

The TextField object has some default sizing characteristics. You need to apply one of these:

to this property:

to get it to form fit your text. Then by adding it into an empty Sprite, said Sprite will also be the exact size of your text.

Changing the size of the Sprite is the wrong approach as what you're actually doing in that case is scaling its interior content. Sprites automatically size themselves to fit the objects they contain. As long as you deal with making sure the TextField is sized properly, the parent Sprite will be sized properly as well.

思念绕指尖 2025-01-05 18:37:28

我确信您不再需要它,但有人可能会需要,所以就在这里。

当你有一个精灵作为它们的父级时,你可以让他禁用鼠标子级。

yourSprite.tf.text = 'something';
yourSprite.buttonMode = true;
yourSprite.mouseChildren = false;

Im sure you dont need it anymore but someone may do, so here it is.

As you have a sprite as parent them you can make him to desable the mouseChildren.

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