缩放 UIComponent 并不是缩放其子组件
我正在构建一个 Flex 应用程序,它根据一些选项/过滤器创建整洁的矢量图像。对于 Flash/Flex/AS3 来说相对较新,所以我正在学习。
简而言之:
// I create a new UIComponent
var myuic:UIComponent = new UIComponent();
// I then draw some vector graphics to it..
myuic_prev.graphics.beginFill(fgRGB, 1);
myuic_prev.graphics.drawRect(xptr, yptr, pxls, pxls);
myuic_prev.graphics.beginFill(fgRGB, 1);
myuic_prev.graphics.drawCircle(cx,cy,cr);
myuic.graphics.beginFill(fgRGB, 1);
myuic.graphics.drawCircle(cx,cy,cr);
myuic_prev.graphics.endFill();
由于各种原因,生成的图像可能适合也可能不适合我的 Canvas 或 Display 容器,在本例中是一个 VBOX有固定的宽度。在这种情况下我 需要缩放生成的 UIComponent 图像。
我在 Adobe 文档中读到,调整 UIComponent 的比例将适当地缩放其子组件。事实上,我看到很多关于如何防止这种情况的帖子。
所以我尝试了...简单地说:
// Scale my UIC by changing the width
myuic_prev.width = 520;
// Now make the two scale factors the same, this keeps proportions.
myuic_prev.scaleY = mxuic_prev.scaleX;
我发现这似乎缩放了 UIComponent 本身,但不是子组件或我绘制到其中的形状。现在,形状超出了范围,或者被剪裁超出了页面范围。
我不明白什么?难道这些形状没有被当作孩子对待吗?或者我该如何做这个工作。谢谢!
I'm building a Flex application that creates neat vector images based on some options/filters. Relatively new to Flash/Flex/AS3, so I'm learning as I go..
In short:
// I create a new UIComponent
var myuic:UIComponent = new UIComponent();
// I then draw some vector graphics to it..
myuic_prev.graphics.beginFill(fgRGB, 1);
myuic_prev.graphics.drawRect(xptr, yptr, pxls, pxls);
myuic_prev.graphics.beginFill(fgRGB, 1);
myuic_prev.graphics.drawCircle(cx,cy,cr);
myuic.graphics.beginFill(fgRGB, 1);
myuic.graphics.drawCircle(cx,cy,cr);
myuic_prev.graphics.endFill();
For various reasons, the resulting image that gets produced may or may not fit in my Canvas or Display container, in this case a VBOX that has a fixed width. In this case I
have need to scale the resulting UIComponent image.
I read in the Adobe documentation that adjusting the scale of a UIComponent will appropriately scale its children. In fact I see lots of threads about how to prevent this.
So I tried that... simply:
// Scale my UIC by changing the width
myuic_prev.width = 520;
// Now make the two scale factors the same, this keeps proportions.
myuic_prev.scaleY = mxuic_prev.scaleX;
What I find is that this seems to scale the UIComponent itself, but NOT the children, or the shapes I drew into it. The shapes now are out-of-bounds, or clipped running off the page.
What am I not understanding? Are these shapes not being treated as children? Or how do I make this work. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIComponent
的width
属性与其父类Sprite
的工作方式不同,因为 Flex 组件具有不同的调整大小逻辑。在示例中,修改宽度
或高度
不会影响图形
层。如果您想缩放UIComponent
和graphics
层,请尝试直接使用scaleX
和scaleY
属性。在示例中尝试一下(如果您想将宽度缩放到 520 并保持纵横比):
The
width
property forUIComponent
works in a different way of its parent classSprite
because Flex components have a different resizing logic. In example modifingwidth
orheight
do not affects thegraphics
layer. If you want to scale yourUIComponent
and thegraphics
layer try to use directly thescaleX
andscaleY
properties.Try this in example (if you want to scale by width to 520 and keep the aspect ratio):