【问题标题】:ActionScript 3 accordion component child container overlay each otherActionScript 3 手风琴组件子容器相互叠加
【发布时间】:2009-11-16 03:29:08
【问题描述】:

我在 as3 中使用手风琴列表在谷歌地图上显示标记集群信息。由于某种原因,当前选定的子容器(一个 vbox)被下一个容器的标签部分覆盖。而且似乎手风琴列表越长,容器的面积就会越大。我尝试将 resizeToContent 属性设置为 true/false,但似乎都不起作用。这是自定义手风琴类(list 是一个标记信息窗口对象数组,它也扩展了UIComponent):

package{
         import mx.containers.Accordion;
          ...
public class AccordionWindow extends UIComponent{ 

public function AccordionWindow(list:Array){

        var panel:Box = new Box();
        panel.width = 300;
        panel.height = 200;
        addChild(panel);

        var acc:Accordion = new Accordion();
        acc.percentWidth = 100;
        acc.percentHeight = 100;

        for (var i:int = 0; i < list.length; i++)
        {
            var vbox:VBox = new VBox();
            vbox.label = "Item" + String(i);
            vbox.addChild(list[i]);
            acc.addChild(vbox);
        }

        panel.addChild(acc);
   }
}

有什么想法吗?

【问题讨论】:

    标签: actionscript-3 flexbuilder accordion


    【解决方案1】:

    我不确定您的问题的确切原因是什么,但这里有一些想法应该会有所帮助。

    1. 您需要使用 super() 语句来启动您的构造函数。

      公共函数 AccordionWindow(list:Array) { 极好的();
          // any other code you might have in your constructor.  
          // generally, you'll want to store arguments in instance properties.  
          // maybe something like this:
      
             this.list = list;
      
      }

    抱歉 - 不知道为什么我在代码格式方面遇到这么多麻烦...

    1. 根据您发布的代码,AccordionWindow 类似乎旨在创建 Accordion 并将其放入 Box 中。也许您有特定的需要以您尝试做的方式做事,但根据我的经验,扩展 Box 比 UIComponent 更有意义。

    2. 在创建子节点并将它们添加到构造函数的阶段时,您往往会遇到问题。相反,请覆盖受保护的 createChildren 方法,并将您当前在构造函数中的所有代码移至该方法。

    createChildren 会自动调用,因此您只需覆盖它并将代码移入其中即可。

    override protected function createChildren():void
    {
        super.createChildren();  // very important.  do not leave this out.
    
        // paste the code that is currently in the constructor here
    }
    

    http://danorlando.com/?p=122 上有一篇关于 UIComponent 生命周期的非常有用的帖子。

    【讨论】:

    • 非常感谢您回答这个问题。这是非常有帮助的。我最近自己发现我只需要为手风琴中的每个孩子设置一个明确的MinHeight。再次感谢!
    • 没问题。是的,你可以这样做,但你基本上是在反对 UIComponents 的工作方式。如果您发现您开始遇到类似的问题,或者没有任何意义的布局问题,我绝对建议您返回并使用 createChildren 方法。祝你好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 2012-11-21
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    相关资源
    最近更新 更多