ActionScript 3: UIScrollBar bug(?) - width of container returns +85px

社会主义新天地 提交于 2019-12-12 01:07:42

问题


Using Flash CS5 I came across something odd today.

The UIScrollBar component has the rigid width of 15px. When you add it to a container such as a Sprite, you'd expect the width of the sprite to return 15, but it returns 100 instead!

Here's an example code.

import flash.display.Sprite;
import fl.controls.UIScrollBar;

var spr:Sprite = new Sprite();
addChild(spr);
trace('spr.width:',spr.width);

var bar:UIScrollBar = new UIScrollBar();
spr.addChild(bar);
trace('bar.width',bar.width);
trace('spr.width:',spr.width);

Interestingly, output is

spr.width: 0
bar.width 15
spr.width: 100

Does anybody know what's happening there? Is this a bug?


回答1:


Found out that it's kind of a bug. What happens is, it takes some time for it to draw/render the component on the stage so its size becomes accessible only after it's drawn. For the record, in my computer it takes 1 ms. until it returns the expected value.

Another surprising issue is, UIScrollBar returns 15px as its width whereas the container sprite returns 16px. For those looking for the reason, it's probably related to the outline of the bar, which is drawn with thickness=1 and scaleMode=LineScaleMode.NONE. I had the exact same issue with a class I wrote, in which I had to override the width and height getters by adding 1 to the return values of each super method.



来源:https://stackoverflow.com/questions/11677547/actionscript-3-uiscrollbar-bug-width-of-container-returns-85px

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!