小小菜鸟的web菜园子

web开发学习。好记性不如烂笔头。每天进步一点点!

导航

使Accordion控件的头部不可单击.

Accordion控件的mouseEnabled属性.
示例1:

示例2:

代码:
示例1代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/30/preventing-users-from-clicking-on-an-accordion-containers-header-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white">

    
<mx:Script>
        
<![CDATA[
            private function prevChild():void {
                accordion.selectedIndex--;
            }

            private function nextChild():void {
                accordion.selectedIndex++;
            }
        
]]>
    
</mx:Script>

    
<mx:Accordion id="accordion"
            headerRenderer
="comps.MyAccHeader"
            width
="100%" height="100%">
        
<mx:VBox id="v1" label="One" width="100%" height="100%">
            
<mx:VBox width="100%" height="100%">
                
<mx:Label text="One" />
            
</mx:VBox>
            
<mx:ControlBar horizontalAlign="right" width="100%">
                
<mx:Spacer width="100%" />
                
<mx:Button label="next" click="nextChild();" />
            
</mx:ControlBar>
        
</mx:VBox>
        
<mx:VBox id="v2" label="Two" width="100%" height="100%">
            
<mx:VBox width="100%" height="100%">
                
<mx:Label text="Two" />
            
</mx:VBox>
            
<mx:ControlBar width="100%">
                
<mx:Button label="prev" click="prevChild();" />
                
<mx:Spacer width="100%" />
                
<mx:Button label="next" click="nextChild();" />
            
</mx:ControlBar>
        
</mx:VBox>
        
<mx:VBox id="v3" label="Three" width="100%" height="100%">
            
<mx:VBox width="100%" height="100%">
                
<mx:Label text="Three" />
            
</mx:VBox>
            
<mx:ControlBar width="100%">
                
<mx:Button label="prev" click="prevChild();" />
                
<mx:Spacer width="100%" />
                
<mx:Button label="next" click="nextChild();" />
            
</mx:ControlBar>
        
</mx:VBox>
        
<mx:VBox id="v4" label="Four" width="100%" height="100%">
            
<mx:VBox width="100%" height="100%">
                
<mx:Label text="Four" />
            
</mx:VBox>
            
<mx:ControlBar width="100%">
                
<mx:Button label="prev" click="prevChild();" />
                
<mx:Spacer width="100%" />
                
<mx:Button label="next" click="nextChild();" />
            
</mx:ControlBar>
        
</mx:VBox>
        
<mx:VBox id="v5" label="Five" width="100%" height="100%">
            
<mx:VBox width="100%" height="100%">
                
<mx:Label text="Five" />
            
</mx:VBox>
            
<mx:ControlBar width="100%">
                
<mx:Button label="prev" click="prevChild();" />
                
<mx:Spacer width="100%" />
            
</mx:ControlBar>
        
</mx:VBox>
    
</mx:Accordion>

</mx:Application>

comps/MyAccHeader.as:
/**
 * http://blog.flexexamples.com/2008/05/30/preventing-users-from-clicking-on-an-accordion-containers-header-in-flex/
 */
package comps {
    import mx.containers.accordionClasses.AccordionHeader;

    public class MyAccHeader extends AccordionHeader {
        public function MyAccHeader() {
            super();
            mouseEnabled = false;
        }
    }
}

示例2代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/05/30/preventing-users-from-clicking-on-an-accordion-containers-header-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white">

    
<mx:Script>
        
<![CDATA[
            private function prevChild():void {
                accordion.selectedIndex--;
            }

            private function nextChild():void {
                accordion.selectedIndex++;
            }
        
]]>
    
</mx:Script>

    
<mx:Accordion id="accordion"
            headerRenderer
="comps.MyAccHeader"
            width
="100%"
            height
="100%">
        
<mx:VBox id="v1"
                label
="One"
                width
="100%"
                height
="100%">
            
<mx:Label text="One" />
        
</mx:VBox>
        
<mx:VBox id="v2"
                label
="Two"
                width
="100%"
                height
="100%">
            
<mx:Label text="Two" />
        
</mx:VBox>
        
<mx:VBox id="v3"
                label
="Three"
                enabled
="false"
                width
="100%"
                height
="100%">
            
<mx:Label text="Three" />
        
</mx:VBox>
        
<mx:VBox id="v4"
                label
="Four"
                enabled
="false"
                width
="100%"
                height
="100%">
            
<mx:Label text="Four" />
        
</mx:VBox>
        
<mx:VBox id="v5"
                label
="Five"
                width
="100%"
                height
="100%">
               
<mx:Label text="Five" />
        
</mx:VBox>
    
</mx:Accordion>

</mx:Application>
comps/MyAccHeader.as :
/**
 * http://blog.flexexamples.com/2008/05/30/preventing-users-from-clicking-on-an-accordion-containers-header-in-flex/
 */
package comps {
    import mx.containers.accordionClasses.AccordionHeader;
    import mx.events.FlexEvent;

    public class MyAccHeader extends AccordionHeader {
        public function MyAccHeader() {
            super();
            addEventListener(FlexEvent.INITIALIZE, accordionHeader_initialize);
        }

        private function accordionHeader_initialize(evt:FlexEvent):void {
            enabled = data.enabled;
        }
    }
}

posted on 2008-06-02 13:04  『小小菜鸟』  阅读(613)  评论(0编辑  收藏  举报