2 Replies Latest reply on Nov 19, 2010 5:28 AM by MacUsher

    datagrid: tooltipcreate="<fn>" not called?

    ethrbunny Level 1

      Im hoping to create a custom tooltip function for a datagrid. Rather than taking the 'datatip' approach Im trying to set one function for the whole grid. Unfortunately the function I set isn't getting called.

       

      <mx:DataGrid id="studiesGrid" width="100%" height="100%" dataProvider="{participationArrayCollection}" editable="true"

      toolTipCreate="createToolTip( event )" toolTipStart="startToolTip(event)">

       

      Has anyone tackled this before? The docs make it sound straightforward.

        • 1. Re: datagrid: tooltipcreate="<fn>" not called?
          ethrbunny Level 1

          FWIW here's the answer:

           

          To set a custom tooltip on a datagrid you need to add event listeners for

           

          studiesGrid.addEventListener( ListEvent.ITEM_ROLL_OUT, onRollOut);

          studiesGrid.addEventListener( ListEvent.ITEM_ROLL_OVER, onRollOver);

          studiesGrid.addEventListener(ToolTipEvent.TOOL_TIP_CREATE, createToolTip );

          private function createToolTip(event:ToolTipEvent):void
          {
               var ptt:PanelToolTip = new PanelToolTip();
               ptt.title = "Subjects";
               ptt.bodyText = "event.target.toolTip";
               event.toolTip = ptt;
          }
          private function onRollOver(event:ListEvent):void
          {
               event.target.toolTip = null;
               var itemX:int = event.itemRenderer.x;
               var itemY:int = event.itemRenderer.y;
               var point:Point = event.currentTarget.contentToGlobal(new Point(itemX,itemY));                       
               event.target.toolTip = "tip text";                        
          }
          private function onRollOut(event:ListEvent):void
          {
               if (event.target.toolTip != null)
               {
                    event.target.toolTip = null;
               }
          }
          This is the PanelToolTip:
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.core.IToolTip"
          width="200" alpha="1.0" backgroundColor="#FFFFDD"
          borderColor="black" borderStyle="solid">
          <mx:Script>
          <![CDATA[
          [Bindable]
          public var bodyText:String = "";
          //  Implement required methods of the IToolTip interface
          /**
          * @private
          * @inheritDoc
          */
          public var _text:String;
          /**
          * @private
          * @inheritDoc
          */
          public function get text():String
          {
          return _text;
          }
          /**
          * @inheritDoc
          */
          public function set text(value:String):void
          {
          }
          ]]>
          </mx:Script>
          <mx:Text text="{bodyText}" percentWidth="100"/>
          </mx:Panel>

          • 2. Re: datagrid: tooltipcreate="<fn>" not called?
            MacUsher

            i wrote bs and can't delete this post, sorry...