Flex SkinnableContainer皮肤访问组内部组

时间:2011-12-01 19:31:08

标签: actionscript-3 flex flex4.5 skin

我有皮肤类,我在contentGroup中定义了一个Group:

<s:Group id="contentGroup" left="0" right="0" top="0" bottom="0" minWidth="475" minHeight="0">
        <s:layout>
            <s:HorizontalLayout paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom="0" gap="2" />
        </s:layout>


        <s:Group id="group_nav_custom_comp_hgroup_prevnext" left="0" right="0" top="0" bottom="0" minWidth="100" minHeight="0">
            <s:layout>
                <s:HorizontalLayout paddingLeft="0" paddingRight="0" paddingTop="0" paddingBottom="0" gap="5" />
            </s:layout>
            <s:Button label="Test Button"/>
        </s:Group>

    </s:Group>

现在,在我上面扩展skin类的CustomComponent中,我试图访问“group_nav_custom_comp_hgroup_prevnext”(这是contentGroup中的子组),所以我可以在运行时向它添加元素:

public class GroupNavCustomContainer extends SkinnableContainer
    {

        private var m_group_prev_next:Group = null;
        private var m_bAdded_btns:Boolean = true;
        private var _prevbtn:UIComponent = null;

        public function GroupNavCustomContainer()
        {
            super();


            setStyle("skinClass", GroupNavCustomSkin);

        }
        //----------------------------------
        public function set prevBtn(ui_comp_prev:UIComponent):void
        {

            if(m_group_prev_next)   
            {
                _prevbtn = ui_comp_prev;
                m_bAdded_btns = true;
                invalidateProperties();
            }

        }
        //-------------------------------------------------------------------------
        override protected function partAdded(partName:String, instance:Object):void 
        {
            trace("In partAdded");


            if(partName == "contentGroup")
            {
                var group:Group = instance as Group;
                var visualElem:IVisualElement = group.getElementAt(0);
                m_group_prev_next = visualElem as Group;
            }

            super.partAdded(partName, instance);

        }
        //------------------------------------------------------------------------
        override protected function commitProperties():void 
        {

            super.commitProperties();

            if (m_bAdded_btns) 
            {

                m_bAdded_btns = false;
                m_group_prev_next.addElement(_prevbtn);

            }

        }




    }

结果是我的:group_nav_custom_comp_hgroup_prevnext根本就没有显示出来,因为编译时出现的按钮不可见。有谁知道怎么让它出现? - 谢谢! -Mike

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

好的,我将我的子组添加为皮肤部分:

[SkinPart(所需= “真”)] public var group_nav_custom_comp_hgroup_prevnext:Group;

所以现在我可以从CustomComponent的任何地方访问它。但是'group_nav_custom_comp_hgroup_prevnext'中的按钮仍然没有显示出来。谁知道为什么?

package com.viiv.digi.views.navigation
{
          import mx.core.IVisualElement;
          import mx.core.UIComponent;

          import skins.GroupNavCustomSkin;

          import spark.components.Group;
          import spark.components.SkinnableContainer;

          public class GroupNavCustomContainer extends SkinnableContainer
          {

                    private var m_group_prev_next:Group = null;
                    private var m_bAdded_btns:Boolean = false;
                    private var _prevbtn:UIComponent = null;


                    [SkinPart(required="true")]
                    public var group_nav_custom_comp_hgroup_prevnext:Group;



                    public function GroupNavCustomContainer()
                    {
                              super();


                              setStyle("skinClass", GroupNavCustomSkin);

                    }
  //----------------------------------
                    public function set prevBtn(ui_comp_prev:UIComponent):void
                    {

                        _prevbtn = ui_comp_prev;
                              m_bAdded_btns = true;
                              invalidateProperties();
        }
  //------------------------------------
                    public function get prevBtn():UIComponent
                    {
                              return _prevbtn;
                    }
  //-------------------------------------------------------------------- -----
                    override protected function partAdded(partName:String, instance:Object):void
                    {
  trace("In partAdded");
                              super.partAdded(partName, instance);

                    }
  //-------------------------------------------------------------------- ----
                    override protected function commitProperties():void
                    {

                              super.commitProperties();

                              if (m_bAdded_btns)
                              {

                                        m_bAdded_btns = false;
                                        group_nav_custom_comp_hgroup_prevnext.addElement(_prevbtn);

                              }

                    }




          }
}

1 个答案:

答案 0 :(得分:0)

contentGroup应该包含添加到SkinnableContainer的元素,不包含任何其他内容。这是在父组件而不是外观中管理的。因此,您可以在contentGroup下面添加“group_nav_custom_comp_hgroup_prevnext”组组件定义,然后在GroupNavCustomContainer中引用它。