Flex3 画布、滚动条
我想将一个“简单”的 Sprite
添加到 Flex Canvas
中。 我正在这样做:
var uic:UIComponent=new UIComponent;
var s:Sprite=new Sprite(); //<-- my simple Sprite
uic.addChild(s);
myCanvas.addChild(uic);
Sprite
已正确添加到 Canvas
中,但现在,我需要根据 Canvas
ScrollBar 激活 Canvas
ScrollBar代码>精灵大小。 (画布有固定尺寸)
欢迎任何想法,
谢谢
I would like to add a "simple" Sprite
into a flex Canvas
.
I'am doing this:
var uic:UIComponent=new UIComponent;
var s:Sprite=new Sprite(); //<-- my simple Sprite
uic.addChild(s);
myCanvas.addChild(uic);
The Sprite
is correctly added to the Canvas
, but now, i need to activate the Canvas
ScrollBar depending on the Sprite
size. (the Canvas have a fixed size)
Any ideas wellcome,
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发现的问题是,普通 UIComponent 不会向其父级报告宽度或高度值(因为它根本不知道该值应该是什么!)。
如果您必须在 Flex 中使用简单的 Sprites 和其他原始显示对象,我建议您创建一个 UIComponent 的子类,并覆盖
measure()
函数。 在那里,将measuredWidth 和measuredHeight 属性设置为UIComponent 子级的大小。这是一个您可能想要尝试的快速(且未经测试)的解决方案(在您的 UIComponent 子类中,它将替换普通的 UIComponent):
就个人而言,只要有可能,我会尝试使所有内容成为 UIComponent 的正确子类,而不是创建像这样的 hack 来使Sprite 或其他非 UIComponent 类型在 Flex 容器内工作。 但是,您的方法似乎很常见,因此希望这对您和其他人有用。
The problem you've discovered is that plain UIComponent does not report a width or height value to its parent (because it simply doesn't know what that value should be!).
If you must work with simple Sprites and other primitive display objects in Flex, I would recommend creating a subclass of UIComponent with an override of the
measure()
function. In there, set the measuredWidth and measuredHeight properties to the size of the UIComponent's children.This is a quick (and untested) solution you might want to try (in your UIComponent subclass that will replace the plain UIComponent):
Personally, whenever possible, I try to make all content proper subclasses of UIComponent rather than creating hacks like this to make Sprite or other non-UIComponent types work inside Flex's containers. However, your approach seems to be very common, so hopefully this will be useful to you and others.