用什么作为自定义MXML组件的基础?

时间:2011-08-26 11:32:30

标签: flex flex4 mxml flex4.5 custom-component

我在Flex 4.5应用程序中使用了几个自定义MXML组件。

他们都使用绝对坐标放置图像,标签,线等组件,目前基于spark.components.BorderContainer

<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    width="160" height="140" borderWeight="0" 
    creationComplete="init(event)">

    <s:layout>
        <s:BasicLayout />
    </s:layout>

    <s:Image id="_avatar" x="0" y="0" width="160" height="120" />
    <s:Label id="_username" x="1" y="122" width="80" /> 
    <s:Label id="_bid" x="80" y="122" width="40" textAlign="center" /> 
    <s:Label id="_trix" x="120" y="122" width="36" textAlign="right" />
        .... and so on: Images, Labels, Paths, Lines, Rects .... 
</s:BorderContainer>

然后我意识到,我可能不必使用BorderContainer,因为我不会在我的自定义组件周围绘制/需要任何边框。

但我不知道,该怎么做而不是它。

我尝试过&lt; mx:UIComponent&gt; (并删除上面的&lt; s:Layout&gt;标记),但后来我收到错误:

'Image' declaration must be contained within the <Declarations> tag since it does not implement 'mx.core.IUIComponent'.
'Label' declaration must be contained within the <Declarations> tag since it does not implement 'mx.core.IUIComponent'.

有什么建议吗?是否有一些最简单的火花“容器”?如果我使用(并且想要使用)绝对坐标,我是否需要一个“容器”?

1 个答案:

答案 0 :(得分:4)

我建议您使用s:Group。并且您可以省略layout声明,因为BasicLayout是默认布局。

UIComponent不是容器,因此没有默认占位符供孩子使用MXML添加它们。

相关问题