【问题标题】:Flex 3: Adding a sprite to a Container's "rawChildren" sometimes adds it to the content children insteadFlex 3:将精灵添加到容器的“rawChildren”有时会将其添加到内容子项中
【发布时间】:2012-02-12 21:10:30
【问题描述】:

我要解决的基本问题是,我混合了 Flex 和 Flash 组件,并且我有一个通用函数,用于向组件添加进度微调器。所以如果组件是Container,我就添加到rawChildren,否则正常添加。

但是,我遇到了从 VBox 继承的组件的问题。我打电话

cont.rawChildren.addChildAt(spinner, cont.rawChildren.numChildren);

但是当我追踪孩子们时,我的微调器出现在cont.getChildren() 中,comp.numChildren 显然也增加了 1。并且其他容器似乎工作正常,甚至其他 VBox 控件。

我浏览了 Flex 框架代码,但找不到任何东西来解释为什么会发生这种情况,无论是通过继承还是计时。

有没有人看到过类似的情况或可以解释为什么rawChildren 在这种情况下可能无法预测?

谢谢。


功能:

var bcu:Number = u.numChildren;
var bce:Number = el.numChildren;

el.addChildAt(s, ((pos > -1)?pos : el.numChildren));
trace("ADD NEW SPINNER", u, el, el.numChildren, u.numChildren, bce, bcu);

el 是容器的 DisplayObject 或 rawChildren 对象,u 是微调器附加到的原始对象。

输出:

ADD NEW SPINNER BlockMovePopup1734 [object ContainerRawChildrenList] 6 5 5 4

然后:

[Fault] exception, information=TypeError: Error #1034: Type Coercion 
failed: cannot convert com.misc::SbSpinner@57970a1 to mx.core.IUIComponent.

输出显示el 正确设置为ContainerRawChildrenListVBoxrawChildren 对象)并且numChildren 在调用之前是[6,5][5,4]。这意味着 Sprite 被添加到内容子项而不是 rawChildren。

【问题讨论】:

  • 您说的是哪个“内容儿童”?您说“但是,我遇到了从 VBox 继承的组件的问题”,但您没有准确解释从 VBox 扩展的类会发生什么。
  • “内容子项”是容器的正常子项,不包括添加到 rawChildren 的皮肤之类的东西。我的扩展 VBox 本质上只是一个弹出/工具提示类型的东西,但对孩子没有什么特别的。它最多包含 4 个链接按钮。

标签: actionscript-3 apache-flex flex3


【解决方案1】:

那很有趣。发现了怪癖。我认为rawChildren.addChildAt 函数可能有点错误。在 Container 类中找到了这个文本块:

    Container assumes that content children are contiguous, and that
    non-content children come before or after the content children.
    In order words, Container partitions DisplayObjectContainer's
    index range into three parts:

    A B C D E F G H I
    0 1 2 3 4 5 6 7 8    <- index for all children
          0 1 2 3        <- index for content children

    The content partition contains the content children D E F G.
    The pre-content partition contains the non-content children
    A B C that always stay before the content children.
    The post-content partition contains the non-content children
    H I that always stay after the content children.

如果我使用rawChildren.addChild,它现在可以正常工作。在这两种情况下,微调器都被添加为最后一个孩子,但 addChild 正确地做到了。

【讨论】:

  • 哇,很高兴知道。这对于一个平台来说太可怕了……难怪这些天 Flex 正在为 HTML5 倒下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-19
相关资源
最近更新 更多