保持孩子固定大小

发布于 2024-11-25 04:32:16 字数 718 浏览 1 评论 0原文

我有以下设置:

<mx:Canvas>
 <mx:ViewStack width="800" height="600">

  <mx:Canvas width="100%" height="100%">
   <s:BorderContainer width="100%" height="100%">
    <mx:Canvas x="80" y="46" width="640" height="480">
      <custom:CustomComponent width="640" height="480" />
    </mx:Canvas>
   </s:BorderContainer>
  </mx:Canvas>

 </mx:ViewStack>
</mx:Canvas>

是我无法更改的。这是显示视频的东西。然而,由于某种原因,某些东西(我猜是一个容器)的大小为 800x 600。所以我在 内得到了滚动条。

有没有办法可以强制某个容器的所有子项不超过一定的宽度/高度。

I have the following setup:

<mx:Canvas>
 <mx:ViewStack width="800" height="600">

  <mx:Canvas width="100%" height="100%">
   <s:BorderContainer width="100%" height="100%">
    <mx:Canvas x="80" y="46" width="640" height="480">
      <custom:CustomComponent width="640" height="480" />
    </mx:Canvas>
   </s:BorderContainer>
  </mx:Canvas>

 </mx:ViewStack>
</mx:Canvas>

The <custom:CustomComponent /> is something I can't change. It's something that displays videos. However, for some reason, something (a container I guess) gets the size 800x 600. So I get scrollbars inside the <custom:CustomCompnent />.

Is there a way I can force all children of a certain container not to get beyond a certain width/heigth.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

熟人话多 2024-12-02 04:32:16

您只需重写自定义容器的 addChildAt() 方法即可。 (这也涵盖了 addChild() 方法,因为 addChild() 调用 addChildAt())。在那里,您可以检查宽度和高度,并添加changeWatchers以在组件的宽度/高度每次更改时进行检查。应该使用changewatchers,因为DisplayObject没有maxWidth/maxHeight属性(否则会更容易)。

override public function addChildAt(child:DisplayObject, index:int):DisplayObject
{
    super.addChildAt(child, index);

    if(child.width > 640)child.width = 640;
    if(child.height > 480)child.height = 480;

    ChangeWatcher.watch(child, "width", function():void{child.width = (child.width > 640) ? 640 : child.width;});
    ChangeWatcher.watch(child, "height", function():void{child.height = (child.height > 480) ? 480 : child.height;});
}

编辑

当您想使用此代码时,只需创建一个扩展 Canvas 类的新类,如下所示:

package com
{
    import mx.containers.Canvas

    public class CustomCanvas extends Canvas
    {
        public function CustomCanvas():void
        {
            super();
        }

        override public function addChildAt(child:DisplayObject, index:int):DisplayObject
        {
            super.addChildAt(child, index);

            if(child.width > 640)child.width = 640;
            if(child.height > 480)child.height = 480;

            ChangeWatcher.watch(child, "width", function():void{child.width = (child.width > 640) ? 640 : child.width;});
            ChangeWatcher.watch(child, "height", function():void{child.height = (child.height > 480) ? 480 : child.height;});
        }
    }
}

为了然后使用简单的 mxml 添加此代码,您可以执行类似的操作。这将具有 Canvas 具有的所有功能,并使用您自己的 adchild() 功能进行扩展。

<com:CustomCanvas someproperty="somevalue"></com:CustomCanvas>

You could just override the addChildAt()-method of your custom container. (this also covers the addChild()-method, because addChild() calls for addChildAt()). There you can check the width and height and add changeWatchers to check every time the width/height of a component changes. the changewatchers should be used because DisplayObject does not have a maxWidth/maxHeight-property (else it would be even easier).

override public function addChildAt(child:DisplayObject, index:int):DisplayObject
{
    super.addChildAt(child, index);

    if(child.width > 640)child.width = 640;
    if(child.height > 480)child.height = 480;

    ChangeWatcher.watch(child, "width", function():void{child.width = (child.width > 640) ? 640 : child.width;});
    ChangeWatcher.watch(child, "height", function():void{child.height = (child.height > 480) ? 480 : child.height;});
}

EDIT

When you want to use this code, just create a new class that extends the Canvas-class, like so:

package com
{
    import mx.containers.Canvas

    public class CustomCanvas extends Canvas
    {
        public function CustomCanvas():void
        {
            super();
        }

        override public function addChildAt(child:DisplayObject, index:int):DisplayObject
        {
            super.addChildAt(child, index);

            if(child.width > 640)child.width = 640;
            if(child.height > 480)child.height = 480;

            ChangeWatcher.watch(child, "width", function():void{child.width = (child.width > 640) ? 640 : child.width;});
            ChangeWatcher.watch(child, "height", function():void{child.height = (child.height > 480) ? 480 : child.height;});
        }
    }
}

In order to then add this using simple mxml, you can just do something like this. This will have all functionalities a Canvas would have, extended with your own adchild()-functionality.

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