【问题标题】:(flex mobile)how to add element in the my custom layout(flex mobile)如何在我的自定义布局中添加元素
【发布时间】:2012-05-06 09:48:58
【问题描述】:

这是我的代码:

public class my_Layout extends LayoutBase
{
    public function my_Layout(){
        super();
        var b:Button = new Button;
        b.label="my button"
        addChild(b)
    }
}

但它显示错误,我的方法 addChild 未定义,

那我能做什么,谢谢

【问题讨论】:

  • 您不应该在 Layout 类中添加元素。您将元素添加到组件(自定义或非自定义),并通过 Layout 类定位和调整这些元素的大小。
  • 我认为@RIAstar 做到了。布局实际上只是 measure() 方法的“外包”,以及用于调整子级大小和位置的 updateDisplayList() 部分。您不会直接在布局中添加子元素,而是在使用该布局的组件中添加子元素。我忘记了如何从布局类中访问该组件。
  • @www.Flextras.com 这是LayoutBase 类的target 属性(它是一个GroupBase)。
  • 如果您使用的是 spark 组件,请使用 addElement 而不是 addChild。

标签: apache-flex layout mobile


【解决方案1】:
private function get_list():List{
        var list:List = target.parent.parent.parent.parent as List;
        return list;
    }
    private function get_document():View{
        var list:List = get_list();
        return list.document as View;
    }

var list:List = get_list();
        var document:View = get_document();
        var b:Button = new Button;
        b.label = 'wwwwwwwwwwwwwwwwwwwwww';
        document.addElement(b);

【讨论】:

    猜你喜欢
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-08
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 2021-08-16
    相关资源
    最近更新 更多