小小菜鸟的web菜园子

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

导航

改变ButtonBar组件中标签图标的位置:

getChildAt() 方法 and labelPlacement 属性.
示例:



代码:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/08/changing-the-label-placement-for-a-flex-buttonbar-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white">

    
<mx:Script>
        
<![CDATA[
            import mx.controls.Button;
            import mx.controls.ButtonLabelPlacement;

            [Bindable]
            [Embed("assets/arrow_down.png")]
            private var arrowDown:Class;

            [Bindable]
            [Embed("assets/arrow_left.png")]
            private var arrowLeft:Class;

            [Bindable]
            [Embed("assets/arrow_right.png")]
            private var arrowRight:Class;

            [Bindable]
            [Embed("assets/arrow_up.png")]
            private var arrowUp:Class;

            private function init():void {
                var idx:uint;
                var len:uint = buttonBar.numChildren;
                var btn:Button;
                /* Loop over each button. */
                for (idx = 0; idx < len; idx++) {
                    /* Get reference to current Button. */
                    btn = buttonBar.getChildAt(idx) as Button;
                    /* Set labelPlacement property to current item in
                       arr Array object. */
                    btn.labelPlacement = arr[idx].label;
                }
            }
        
]]>
    
</mx:Script>

    
<mx:Array id="arr">
        
<mx:Object label="left" img="{arrowLeft}" />
        
<mx:Object label="right" img="{arrowRight}" />
        
<mx:Object label="top" img="{arrowUp}" />
        
<mx:Object label="bottom" img="{arrowDown}" />
    
</mx:Array>

    
<mx:ButtonBar id="buttonBar"
            dataProvider
="{arr}"
            iconField
="img"
            buttonHeight
="64"
            width
="500"
            creationComplete
="init();" />

</mx:Application>

来自:
http://blog.flexexamples.com/2008/01/08/changing-the-label-placement-for-a-flex-buttonbar-control/

posted on 2008-04-25 19:28  『小小菜鸟』  阅读(1101)  评论(0编辑  收藏  举报