如何使用 Flash 中的 ComboBox 组件修复此潜在错误?
当我将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是因为 Adobe 愚蠢地植入了 Flash 组件,如果您查看 Flash IDEA 中组件的第二帧,您可以看到它是返回初始大小的临时头像。
要解决此问题,您应该迭代化身子项并标准化其大小:
用法:
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.
to solve this you should iterate over the avatar children and normalize their size:
usage:
“如果它被打开,那么下拉框的高度”
嗯,我认为当列表添加到按钮下方的显示列表时,它实际添加的会有一个弹出窗口。因此高度应该保持按钮的高度,因为精灵实际上永远不会包含下拉列表。
容器高度在发生任何失效之前可能是错误的一个可能原因可能是由于它包含的子项。也许是组合框皮肤(可能是 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.
我不认为这是
ComboBox
独有的错误。当我将组件
Button
添加到Sprite
容器时,在跟踪按钮和容器尺寸时也会得到不同的结果。实际上,我收到了相同的100 x 100
结果。我会放弃下拉框的可能性,因为
Button
组件没有下拉框。我认为两个组件对象(
ComboBox
和Button
)的解决方法是相同的,但我还没有找到解决方案。当我这样做时会更新。更新:
我只能使用
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 aSprite
container I also get different results when tracing the button and the container dimensions. Actually, I receive the same100 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
andButton
), 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=0Essentially, the link instructs us to put the
validateNow()
call inside anEnterFrame
event, or inside aSetTimeout
with proper timing.所以 - 我猜 ComboBox 的显示高度是实际高度 - id est,如果它打开,则带有下拉框的高度,如果没有,则不带有。然而 - 这些项目仍然在那里,尽管 .visible 设置为 false,即使您看不到它,它仍然会扩展容器......因此 - 我会说这样做:
那就是通常的方法也是如此......
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:
That is the way to usually do it as well...
您可以在此代码之前手动设置吗:
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);
您好,我在某个地方找到了 NumericStepper 类似问题的解决方案。
解决方案是:
根据您的情况,请尝试以下操作:
Hi i found somewhere a solution for a similar problem with NumericStepper.
and the solution was:
In your case try the following: