将容器(在MXML中定义)的子容器移动到“内部容器”内部

发布于 2024-08-19 05:35:31 字数 1500 浏览 5 评论 0原文

我目前正在开发一个扩展 Canvas 的自定义组件(我们称之为 SuperCanvas);它基本上是一个可以让你缩放和缩放的容器。平移其内容。

解释原因太长了,但我不能使用scrollRect,所以我被迫在我的 SuperCanvas 中声明一个 Canvas 对象(称为 innerCanvas)...(我知道,不是很好) =/)

我想知道是否有适当的方法来“重定向”此画布中我的组件子级的创建。

让我解释一下:

<comp:SuperCanvas id="superCanvas">
   <mx:Image id="img" source="image.jpg"/>
   <mx:Label id="lbl" text="Sample"/>
</comp:SuperCanvas>

这样,img 和 lbl 将添加到我的 SuperCanvas 中。我希望将它们添加到 superCanvas.innerCanvas 中。

我无法重写 add/removeChild 方法来执行“重定向”,因为我无法添加此innerCanvas...

所以我尝试了这个:

<comp:SuperCanvas>
   <comp:innerCanvas>
      <mx:Image id="img" source="image.jpg"/>
      <mx:Label id="lbl" text="Sample"/>
   </comp:innerCanvas>
</comp:SuperCanvas>

但 Flex 抱怨“ >在“内容”的初始值设定项中:类型 mx.controls.Image 无法分配给目标类型 mx.containers.Canvas”。我读到我可以使用带有 [ArrayElementType] 元标记的 UIComponent 数组,并手动实例化对象,但我正在寻找更简单(并且可能合适)的解决方案。

我还看到了 childDescriptor 属性(其中包含 MXML 文件中定义的每个子项的描述),但它是只读的,因此我无法将其传递到我的 innerCanvas

如果我不够清楚,请毫不犹豫地问我精确度,英语不是我的母语,所以很难很好地解释事情=/

任何帮助将不胜感激,我完全陷入困境。


编辑: 我的 SuperCanvas 类(减去导入以及此处无关紧要的缩放和平移逻辑):

public class SuperCanvas extends Canvas
{
    public innerCanvas:Canvas = new Canvas();

    public function SuperCanvas()
    {
      super();
      addChild( innerCanvas );
    }
}

I'm currently working on a custom component which extends Canvas (let's call it SuperCanvas) ; it's basically a container that let you zoom & pan its contents.

It would be too long to explain why, but I can't use scrollRect, so I was forced to declare a Canvas object (called innerCanvas)... inside my SuperCanvas (I know, not very nice =/)

I would like to know if there's a proper way to "redirect" the creation of my component's children in this canvas.

Let me explain:

<comp:SuperCanvas id="superCanvas">
   <mx:Image id="img" source="image.jpg"/>
   <mx:Label id="lbl" text="Sample"/>
</comp:SuperCanvas>

With this, img and lbl are added to my SuperCanvas. I want them to be added to superCanvas.innerCanvas instead.

I can't override the add/removeChild methods to do the "redirection", since I won't be able to add this innerCanvas...

So I tried this :

<comp:SuperCanvas>
   <comp:innerCanvas>
      <mx:Image id="img" source="image.jpg"/>
      <mx:Label id="lbl" text="Sample"/>
   </comp:innerCanvas>
</comp:SuperCanvas>

But Flex complains that "In initializer for 'contents': type mx.controls.Image is not assignable to target type mx.containers.Canvas". I read I could use an array of UIComponents with a [ArrayElementType] metatag, and manually instanciate objects, but I I'm looking for a simplier (and probably proper) solution.

I also saw the childDescriptor property (which contains descriptions for every child defined in the MXML file), but it's read-only, so I can't pass it to my innerCanvas.

If I'm not clear enough, do not hesitate to ask me precisions, english isn't my native tongue, so it's pretty hard to explain things well =/

Any help would be greatly appreciated, I'm totally stuck.


EDIT:
My SuperCanvas class (minus the imports and the zoom & pan logic that doesn't matter here) :

public class SuperCanvas extends Canvas
{
    public innerCanvas:Canvas = new Canvas();

    public function SuperCanvas()
    {
      super();
      addChild( innerCanvas );
    }
}

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

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

发布评论

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

评论(1

∝单色的世界 2024-08-26 05:35:31

博客条目详细介绍了将组件添加到 SuperCanvas,然后在创建后将它们全部移动到内部画布的方法。这是一种解决方法。

或者,您可以将 DefaultProperty 设置为 dataProvider 类型对象,然后从那里将内容添加到内部画布,而不是首先将它们设为 SuperCanvas 的子级。

另外:

我遇到了这个 博客文章,除其他内容外,还讨论了 Panel 组件及其如何处理此问题。您可以查看它和 Panel 源代码。

This blog entry details an approach where you add components to the SuperCanvas, but then move them all to the inner canvas after creation. So that's one workaround.

Alternatively, you could set the DefaultProperty to be a dataProvider-type object, and then add things to the inner canvas from there, rather than making them children of the SuperCanvas first.

Addition:

I ran across this blog entry which, among other things, talks about the Panel component and how it handles this problem. You might look at it and at the Panel source code.

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