如何使用 Flash 中的 ComboBox 组件修复此潜在错误?

发布于 2024-09-18 10:24:19 字数 829 浏览 3 评论 0原文

当我将 ComboBox 组件添加到 Sprite 中时,容器的高度大于应有的高度。

我的意思是这样的:

import fl.controls.ComboBox;
//add combo box inside a container sprite
var combo:ComboBox = new ComboBox();
var container:Sprite = new Sprite();
addChild(container);
container.addChild(combo);
//draw the outline of the container sprite
container.graphics.lineStyle(1,0x009900);
container.graphics.drawRect(0,0,container.width,container.height);
//I don't get this:
trace(combo.height);//outputs 22
trace(container.height);//outputs 101

注意:您的库中将需要 ComboBox 组件。我为此使用 Flash CS3。

如果我无效/重画,如下所示:

combo.invalidate(InvalidationType.ALL,true);
combo.drawNow();

高度从 101 变为 104。

有什么解决方案吗?

更新: 我已经覆盖了 ComboBox 子类中的 configUI 方法,但测量结果始终正确。为什么容器高度变为 100 ?

When I add a ComboBox component into a Sprite, the height of the container is larger than it should.

Here's what I mean:

import fl.controls.ComboBox;
//add combo box inside a container sprite
var combo:ComboBox = new ComboBox();
var container:Sprite = new Sprite();
addChild(container);
container.addChild(combo);
//draw the outline of the container sprite
container.graphics.lineStyle(1,0x009900);
container.graphics.drawRect(0,0,container.width,container.height);
//I don't get this:
trace(combo.height);//outputs 22
trace(container.height);//outputs 101

Note: You will need the ComboBox component in your Library. I'm using Flash CS3 for this.

If I invalidate/redraw, like this:

combo.invalidate(InvalidationType.ALL,true);
combo.drawNow();

the height changes from 101 to 104.

Any solutions ?

UPDATE:
I've overwritten the configUI method in a ComboBox subclass, but the measurements are correct all the time. Why does the container height change to 100 ?

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

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

发布评论

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

评论(6

感性 2024-09-25 10:24:19

这是因为 Adob​​e 愚蠢地植入了 Flash 组件,如果您查看 Flash IDEA 中组件的第二帧,您可以看到它是返回初始大小的临时头像。

在此处输入图像描述

要解决此问题,您应该迭代化身子项并标准化其大小:

public static function normalizedComponent(component:Sprite):void {
    for (var i:int = 0; i < component.numChildren; i++) {
        component.getChildAt(i).height = component.height;
        component.getChildAt(i).width = component.width;
    }
}

用法:

var comboBox:ComboBox = new ComboBox();
normalizedComponent(comboBox);
normalizedComponent(comboBox.textField);

This is because of Adobe silly implantation of Flash components, if you look in the 2nd frame of a component inside a Flash IDEA you can see it's temporary avatar which returns the initial size.

enter image description here

to solve this you should iterate over the avatar children and normalize their size:

public static function normalizedComponent(component:Sprite):void {
    for (var i:int = 0; i < component.numChildren; i++) {
        component.getChildAt(i).height = component.height;
        component.getChildAt(i).width = component.width;
    }
}

usage:

var comboBox:ComboBox = new ComboBox();
normalizedComponent(comboBox);
normalizedComponent(comboBox.textField);
唯憾梦倾城 2024-09-25 10:24:19

“如果它被打开,那么下拉框的高度”

嗯,我认为当列表添加到按钮下方的显示列表时,它实际添加的会有一个弹出窗口。因此高度应该保持按钮的高度,因为精灵实际上永远不会包含下拉列表。

容器高度在发生任何失效之前可能是错误的一个可能原因可能是由于它包含的子项。也许是组合框皮肤(可能是 102px 高度的 movieClip)或始终以 102px 高度开始或具有奇怪高度的组合框子组件(众所周知,按钮中的 TextField 有时是错误的)。

一个简单的解决方案是等到创建完成/添加事件并查看最终高度是多少,然后绘制边框。

"if it is opened, then the height WITH the drop down box"

Hmm, I think when the list is added to the displayList below the button its actually added has a popup. So the height is supposed to remain the button height, since the sprite will never actually contain the drop-down list.

A possible reason the Container height could be wrong before it goes through any invalidation could be due to the children it contains. Maybe the combobox skin (could be a movieClip of 102px height) or a combobox sub-component that always start at 102px height or with weird height (TextField in a Button is known to be sometime wrong).

A simple solution would be to wait until a creationComplete/added event and see what is the final height, then draw the border.

初见你 2024-09-25 10:24:19

我不认为这是 ComboBox 独有的错误。

当我将组件 Button 添加到 Sprite 容器时,在跟踪按钮和容器尺寸时也会得到不同的结果。实际上,我收到了相同的 100 x 100 结果。

我会放弃下拉框的可能性,因为 Button 组件没有下拉框。

我认为两个组件对象(ComboBoxButton)的解决方法是相同的,但我还没有找到解决方案。当我这样做时会更新。

更新:

我只能使用validateNow()来完成此工作,几分钟后 - 我找到了以下链接:http://forums.adobe.com/message/816912?tstart=0

本质上,该链接指示我们将在 EnterFrame 事件内或在适当时机的 SetTimeout 内调用 validateNow()

I don't think this a ComboBox exclusive bug.

When I add a component Button to a Sprite container I also get different results when tracing the button and the container dimensions. Actually, I receive the same 100 x 100 results.

I would discard the drop down box possibility, since the Button component doesn't have one.

I think the workaround would be the same for the 2 components objects (ComboBox and Button), but I haven't found the solution just yet. Will update when I do.

UPDATE:

I was just able to get this working using validateNow(), and a few minutes later - I found the following link: http://forums.adobe.com/message/816912?tstart=0

Essentially, the link instructs us to put the validateNow() call inside an EnterFrame event, or inside a SetTimeout with proper timing.

尹雨沫 2024-09-25 10:24:19

所以 - 我猜 ComboBox 的显示高度是实际高度 - id est,如果它打开,则带有下拉框的高度,如果没有,则不带有。然而 - 这些项目仍然在那里,尽管 .visible 设置为 false,即使您看不到它,它仍然会扩展容器......因此 - 我会说这样做:

container.graphics.drawRect(0, 0, combo.width, combo.height);

那就是通常的方法也是如此......

So - I guess the displayed height of ComboBox is the actual height - id est, if it is opened, then the height WITH the drop down box, if not then WITHOUT. However - the items are STILL there, although with .visible set to false, which still expands the container, even if you can't see that... Therefore - I would say to do:

container.graphics.drawRect(0, 0, combo.width, combo.height);

That is the way to usually do it as well...

痴情 2024-09-25 10:24:19

您可以在此代码之前手动设置吗:

container.width=100;

container.height=100;

container.graphics.drawRect(0,0,container.width ,容器.高度);

can you setup manually before this code:

container.width=100;

container.height=100;

container.graphics.drawRect(0,0,container.width,container.height);

來不及說愛妳 2024-09-25 10:24:19

您好,我在某个地方找到了 NumericStepper 类似问题的解决方案。

解决方案是:

var tInput:TextInput = numericStepper.getChildAt(2) as TextInput;
tInput.textField.height = 22; 

根据您的情况,请尝试以下操作:

var tInput:TextInput = combo.getChildAt(1) as TextInput;
tInput.textField.height = 22; 

Hi i found somewhere a solution for a similar problem with NumericStepper.

and the solution was:

var tInput:TextInput = numericStepper.getChildAt(2) as TextInput;
tInput.textField.height = 22; 

In your case try the following:

var tInput:TextInput = combo.getChildAt(1) as TextInput;
tInput.textField.height = 22; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文