缩放 UIComponent 并不是缩放其子组件

发布于 2024-10-17 02:05:51 字数 1049 浏览 3 评论 0原文

我正在构建一个 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 图像。

我在 Adob​​e 文档中读到,调整 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 技术交流群。

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

发布评论

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

评论(1

撕心裂肺的伤痛 2024-10-24 02:05:51

UIComponentwidth 属性与其父类 Sprite 的工作方式不同,因为 Flex 组件具有不同的调整大小逻辑。在示例中,修改宽度高度不会影响图形层。如果您想缩放 UIComponentgraphics 层,请尝试直接使用 scaleXscaleY 属性。

在示例中尝试一下(如果您想将宽度缩放到 520 并保持纵横比):

component.scaleX = component.scaleY = 520 / component.width;

The width property for UIComponent works in a different way of its parent class Sprite because Flex components have a different resizing logic. In example modifing width or height do not affects the graphics layer. If you want to scale your UIComponent and the graphics layer try to use directly the scaleX and scaleY properties.

Try this in example (if you want to scale by width to 520 and keep the aspect ratio):

component.scaleX = component.scaleY = 520 / component.width;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文