<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    不用Cell Renderer如何在ComboBox里加入自定義ICO

     

          FLEX 2005-7-27 15:59
    //轉自:http://www.richinternetapps.com/index.html

    My first thought was to suggest the creation of a custom cell renderer, an example of which ships with Flex. However, I then remembered that the List control in Flex has an iconField property, which can be used to specify an image that will appear next to each item in the control. An example MXML file using the iconField property with the List control is as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >

    <mx:Script>
    [Embed(source="one.png")]
    var iconSymbol1:String;
    [Embed(source="two.png")]
    var iconSymbol2:String;
    [Embed(source="three.png")]
    var iconSymbol3:String;
    </mx:Script>

    <mx:List iconField="icon" >
    <mx:dataProvider>
    <mx:Array>
    <mx:Object label="One" icon="{ iconSymbol1 }" />
    <mx:Object label="Two" icon="{ iconSymbol2 }" />
    <mx:Object label="Three" icon="{ iconSymbol3 }" />
    </mx:Array>
    </mx:dataProvider>
    </mx:List>

    </mx:Application>

    The above MXML uses the iconField property of the List control to retrieve the icon property from each item in the control's data provider, and produces the following List control (image only):



    圖片如下:


    But (and isn't there always a but?), the poster to FlexCoders wanted the icons not in a List, but in a ComboBox and, such is fate, the Flex ComboBox does not have an iconField property.

    However, those who have looked into the Flex components in any detail will know that the ComboBox control uses the List control internally, to display its own drop down portion. So, I delved into the classes to see what I could find and the result of that find was as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >


    <mx:Script>
    [Embed(source="one.png")]
    var iconSymbol1:String;
    [Embed(source="two.png")]
    var iconSymbol2:String;
    [Embed(source="three.png")]
    var iconSymbol3:String;
    </mx:Script>

    <mx:ComboBox id="theCombo"
    creationComplete="theCombo.getDropdown().iconField='icon'" >
    <mx:dataProvider>
    <mx:Array>
    <mx:Object label="One" icon="{ iconSymbol1 }" />
    <mx:Object label="Two" icon="{ iconSymbol2 }" />
    <mx:Object label="Three" icon="{ iconSymbol3 }" />
    </mx:Array>
    </mx:dataProvider>
    </mx:ComboBox>

    </mx:Application>



    圖片如下:


    Simple! The highlighted code shows that we can get the List portion of the ComboBox control using the getDropdown() method of the ComboBox, and set its iconField property in the same manner as we did with the List control previously. For those that haven't yet investigated Flex in any detail, the creationComplete property allows us to define a handler that will run when the component instance has been created.

    There is one further point worth noting - the original poster wanted to be able to change the icon at runtime - the solution above does allow that. We can add the following to our MXML file so that when the user presses the button, the icons are rotated through the items in the dropdown.

    <mx:Button label="Rotate Icons" click="rotate();" />

    <mx:Script>

    <![CDATA[

    public function rotate() : Void
    {
    var firstIcon = theCombo.dataProvider[0].icon;
    for ( var i = 1; i < theCombo.dataProvider.length; i++ )
    {
    theCombo.dataProvider[i-1].icon = theCombo.dataProvider[i].icon;
    }

    theCombo.dataProvider[theCombo.dataProvider.length-1].icon = firstIcon;

    theCombo.bLabelFieldChanged = true;
    theCombo.invalidate();

    theCombo.dispatchEvent({type:"labelFieldChanged"});
    }
    ]]>

    </mx:Script>

    The for loop in the rotate() method is self-explanatory, but the last three lines in the method need further explanation. Because we are changing the underlying List component of the ComboBox, the ComboBox icons are not updated when we update the data provider. By including those three lines (which are what are called when the labelField property of the ComboBox is changed), the ComboBox is tricked into redrawing its drop down items. This is a quick and dirty way to get it working - I'm going to investigate a better solution.

    After the user has pressed the button (which is hidden under the drop down portion of the control), the ComboBox looks as follows, with the icons having moved:



    圖片如下:


    The obvious next step in the development of the above is to extract the code to a new component, which could then be used within any application. We'll show how that can be done in a future blog entry.

    This example does show the power of Flex,

    posted on 2007-04-11 10:20 leoli 閱讀(828) 評論(0)  編輯  收藏 所屬分類: Flex

    導航

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    統計

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案(17)

    文章分類(86)

    收藏夾(3)

    flex blog

    good site

    java blog

    my friend

    tools

    抓蝦

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 中文字幕免费在线播放| 久久国产乱子伦精品免费午夜| 日本免费人成黄页在线观看视频| 极品色天使在线婷婷天堂亚洲| ZZIJZZIJ亚洲日本少妇JIZJIZ| 99久在线国内在线播放免费观看 | 精品香蕉在线观看免费| 亚洲AV第一成肉网| 亚洲AV永久青草无码精品| 成人免费a级毛片| 亚洲五月午夜免费在线视频| 亚洲人成人77777在线播放| 亚洲精品第一国产综合境外资源 | 国外亚洲成AV人片在线观看| 大学生一级毛片免费看| 你懂的免费在线观看| 亚洲日韩一区二区一无码| 亚洲免费日韩无码系列| 黄色片在线免费观看| WWW免费视频在线观看播放| 国产成人精品日本亚洲网址 | 亚洲伊人精品综合在合线| 亚洲人成电影在线播放| 国拍在线精品视频免费观看 | 特级毛片A级毛片免费播放| 亚洲黄色在线观看网站| 亚洲无码日韩精品第一页| 亚洲三级在线免费观看| 国产中文字幕在线免费观看 | 一级毛片大全免费播放下载| 涩涩色中文综合亚洲| 久久久无码精品亚洲日韩蜜桃 | 亚洲AV午夜福利精品一区二区| 国产免费私拍一区二区三区| 四虎在线视频免费观看视频| 91视频精品全国免费观看| 老司机午夜免费视频| 亚洲美国产亚洲AV| 亚洲a视频在线观看| 久久久久亚洲AV成人片| 亚洲欧洲无码AV电影在线观看|