<?xml version="1.0" encoding="utf-8"?>
<!--Flex中如何使用addChild()和removeChild()函数动态添加或删除Accordion容器中项目的例子 -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    
    <fx:Script>
        <![CDATA[
            import mx.containers.VBox;
            private const MAX_CHILDREN:uint = 5;
            protected function accordion_addChild(event:MouseEvent):void
            {
                if (accordion.numChildren < MAX_CHILDREN) {
                    var vbox:VBox = new VBox();
                    vbox.label = "child " + accordion.numChildren;
                    vbox.percentWidth = 100;
                    vbox.percentHeight = 100;
                    var randColor:uint = Math.random() * 0xFFFFFF;
                    vbox.setStyle("backgroundColor", randColor);
                    accordion.addChild(vbox);
                }

            }
            
            protected function accordion_removeChild(event:MouseEvent):void
            {
                if (accordion.selectedChild) {
                    accordion.removeChild(accordion.selectedChild as DisplayObject);
                }
            }
            
        ]]>
    </fx:Script>
    
    <fx:Declarations>
        <!-- 将非可视元素(例如服务、值对象)放在此处 -->
    </fx:Declarations>
    <s:controlBarContent>
        <s:Button label="Add child" click="accordion_addChild(event)"/>
        <s:Button label="Remove child" click="accordion_removeChild(event)"/>
    </s:controlBarContent>
    <mx:Accordion id="accordion" width="240" height="160"/>
</s:Application>

 

相关文章:

  • 2021-07-04
  • 2022-02-14
  • 2021-09-25
  • 2021-05-19
  • 2022-12-23
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2022-02-01
  • 2022-02-23
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
相关资源
相似解决方案