Flex列出项目作为组合框项目的工具提示

时间:2009-12-01 06:57:31

标签: flex

如何将列表项作为组合框项目的工具提示?

2 个答案:

答案 0 :(得分:0)

import mx.events.ListEvent; import mx.managers.ToolTipManager;                 import mx.controls.ToolTip;

        public var myTip:ToolTip;

        private function fnInit():void
        {
            cmb.addEventListener(ListEvent.ITEM_ROLL_OVER,fnCreToolTip);
            cmb.addEventListener(ListEvent.ITEM_ROLL_OUT,fnCreToolTip);
            cmb.addEventListener(ListEvent.CHANGE,fnCreToolTip);
        }
        private function fnCreToolTip(e:ListEvent):void
        {
            switch(e.type)
            {
                case ListEvent.ITEM_ROLL_OVER:
                {
                    //creates a tooltip.
                    myTip = ToolTipManager.createToolTip(array2[e.rowIndex].tooltip,stage.mouseX+10,stage.mouseY) as ToolTip; // array2 is id of arraylist  
                    break;
                }
                case ListEvent.ITEM_ROLL_OUT:
                {
                    //destroy the created tooltip, so that we can create a new one for others.
                    ToolTipManager.destroyToolTip(myTip);
                    break;
                }
                case ListEvent.CHANGE:
                {
                    //destroy the created tooltip, so that we can create a new one for others.
                    ToolTipManager.destroyToolTip(myTip);
                    break;
                }
            }

        }

答案 1 :(得分:0)

在flex 4中创建自己的项目渲染器:

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" 
                autoDrawBackground = "true"
                toolTip="{data.description}">
<...>

</s:ItemRenderer>

其中description是您通过addItem()传递给Combobox的对象的属性。 (例如,我传递XML以便我执行数据。@ description)