使用占位符制作Flex组件的好方法是什么?

时间:2009-08-19 12:16:33

标签: flex actionscript-3 actionscript flex3 mxml

我想创建一个具有几个“漏洞”的组件,每次使用时都要以不同方式填充。目前,我这样做(在这个例子中使用Flex 4框架---对于Flex 3看起来几乎相同):

public var fooComponent : IVisualElement;
public var barComponent : IVisualElement;

override protected function createChildren() : void
{
  super.createChildren();

  fooContainer.addElement(fooComponent);
  barContainer.addElement(barComponent);
}

<Group id="fooContainer"/>
<!-- ... other components ... -->
<Group id="barContainer"/>

这很好用,但是为了这么简单的事情而编写的代码很多。

我想要的是这样的:

[Bindable] public var fooComponent : IVisualElement;
[Bindable] public var barComponent : IVisualElement;

<Placeholder content="{fooComponent}"/>
<!-- ... other components ... -->
<Placeholder content="{barComponent}"/>

现在,我可以自己实现Placeholder组件,但我不禁想知道使用Flex框架中的现有工具是否有更好的方法来实现这一点。

理论上,通过适当的编译器支持,它甚至可以归结为类似的东西:

<Placeholder id="fooComponent"/>
<!-- ... other components ... -->
<Placeholder id="barComponent"/>

4 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

我们只需要使用任何标准容器作为占位符。我们可以使用addChild()和removeChild()方法添加,删除该容器中的控件。

答案 2 :(得分:0)

您是否尝试使用一些SkinPart创建一个SkinnableComponent,并为它准备一个合适的皮肤?我想这可能有所帮助。

答案 3 :(得分:0)

<UIComponent id="fooComponent"/>
<!-- ... other components ... -->
<UIComponent id="barComponent"/>