带自定义工具提示的 ItemRollOver

发布于 2024-09-28 18:16:27 字数 1235 浏览 4 评论 0原文

我有这个自定义工具提示:

   <?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx"
         implements="mx.core.IToolTip"
         creationPolicy="all"
         cornerRadius="4" borderStyle="solid" backgroundColor="#FFFFFF"
         creationComplete="init()" width="100" height="100">
  <fx:Script>
    <![CDATA[
      import mx.core.IToolTip;

  public var arrItemsKits:Array=[];
  public var _text:String;

  public function get text():String { 
    return _text; 
  } 
  public function set text(value:String):void {
  } 

  protected function init():void
  {
    grid.dataProvider=arrItemsKits;
  }

]]>
  </fx:Script>



  <mx:DataGrid id="grid" width="100%" height="100%">
    <mx:columns>
      <mx:DataGridColumn headerText="Code" dataField="itemPartNumber"/>
      <mx:DataGridColumn headerText="Description" dataField="kitItemsNotes"/>
    </mx:columns>
  </mx:DataGrid>


</mx:VBox>

并且我希望当我将鼠标滚动到数据网格中的一行上时它会触发它,因此我需要向该网格的行添加一个事件侦听器(toolTipCreate)。

有什么想法如何解决这个问题吗?

谢谢

I have this custom toolTip:

   <?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx"
         implements="mx.core.IToolTip"
         creationPolicy="all"
         cornerRadius="4" borderStyle="solid" backgroundColor="#FFFFFF"
         creationComplete="init()" width="100" height="100">
  <fx:Script>
    <![CDATA[
      import mx.core.IToolTip;

  public var arrItemsKits:Array=[];
  public var _text:String;

  public function get text():String { 
    return _text; 
  } 
  public function set text(value:String):void {
  } 

  protected function init():void
  {
    grid.dataProvider=arrItemsKits;
  }

]]>
  </fx:Script>



  <mx:DataGrid id="grid" width="100%" height="100%">
    <mx:columns>
      <mx:DataGridColumn headerText="Code" dataField="itemPartNumber"/>
      <mx:DataGridColumn headerText="Description" dataField="kitItemsNotes"/>
    </mx:columns>
  </mx:DataGrid>


</mx:VBox>

and i want it to fire it when i roll the mouse over a row from a datagrid, so i need to add an event listener(toolTipCreate) to the row of that grid.

Any ideas how can i solve this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔女人霸气范 2024-10-05 18:16:27

看看这个

<!-- myDataGridTest.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
        <![CDATA[
            import mx.events.ListEvent;
            import mx.core.IToolTip;
            import mx.events.ToolTipEvent;

            // holds the currently highlighted item
            private var highlightedItem:Object;

            // event listener to get our hands on the currently highlighted item.
            private function getHighlightedItem(e:ListEvent):void {
                highlightedItem = e.itemRenderer.data;
                // Quick n dirty way to force the ToolTipManager to refresh our tooltip.
                // We need to dispatch this by hand because the pointer never leaves myDataGrid
                // between successive highlights.
                myDataGrid.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OUT));
            }

            private function createTooltip(e:ToolTipEvent):void {
                var tt:MyCustomTooltip = new MyCustomTooltip();
                tt.firstName = highlightedItem.name;
                tt.lastName = highlightedItem.surname;
                // Contract with the tooltip manager: if it finds an IToolTip instance attached to
                // the event, it uses that instance instead of creating the standard one.
                e.toolTip = tt;
            }
        ]]>
    </mx:Script>

    <mx:DataGrid id="myDataGrid" toolTip=" " toolTipCreate="createTooltip(event)" itemRollOver="getHighlightedItem(event)">
        <mx:dataProvider>
            <mx:Object name="john" surname="doe"/>
            <mx:Object name="mike" surname="smith"/>
        </mx:dataProvider>
    </mx:DataGrid>

</mx:Application>

<!-- MyCustomTooltip.mxml -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.core.IToolTip" 
    backgroundColor="yellow" backgroundAlpha="0.6">

    <mx:Script>
        <![CDATA[
            private var _firstName:String;
            private var _lastName:String;

            // Dummy implementations to comply with mx.core.IToolTip
            public function get text():String {return null;}
            public function set text(value:String):void {}

            // properties and functions

            public function set firstName(value:String):void {
                _firstName = value;
                invalidateProperties();
            }

            public function set lastName(value:String):void {
                _lastName = value;
                invalidateProperties();
            }

            override protected function commitProperties():void {
                fName.text = _firstName;
                lName.text = _lastName;
            }
        ]]>
    </mx:Script>

    <mx:Label x="0" y="0" id="fName"/>
    <mx:Label x="0" y="20" id="lName"/>

</mx:Canvas>



或者尝试这样的事情

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="doInit();">
<mx:Script>
<!![CDATA[import mx.collections.ArrayCollection; // this holds the grid data
[Bindable]
private var myData:ArrayCollection = new ArrayCollection();private function doInit():void{
myData.addItem({fname:"Joe",lname:"Bloggs"});
myData.addItem({fname:"Joe1",lname:"Bloggs"});
}

private function buildToolTip(item:Object):String{
var myString:String = "";
if(item != null)
{
myString = myString + "Firstname : " + item.fname + "\n";
myString = myString + "Lastname : " + item.lname + "\n"
}
return myString;
}
]]>
</mx:Script>
<mx:DataGrid id="dGrid"  dataProvider="{myData}"  visible="true" dataTipFunction="buildToolTip">
<mx:columns>
<mx:DataGridColumn dataField="fname" headerText="FirstName" showDataTips="true" />
<mx:DataGridColumn dataField="lname" headerText="LastName" showDataTips="true" />
</mx:columns>
</mx:DataGrid>
</mx:Application>

Check out this

<!-- myDataGridTest.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
        <![CDATA[
            import mx.events.ListEvent;
            import mx.core.IToolTip;
            import mx.events.ToolTipEvent;

            // holds the currently highlighted item
            private var highlightedItem:Object;

            // event listener to get our hands on the currently highlighted item.
            private function getHighlightedItem(e:ListEvent):void {
                highlightedItem = e.itemRenderer.data;
                // Quick n dirty way to force the ToolTipManager to refresh our tooltip.
                // We need to dispatch this by hand because the pointer never leaves myDataGrid
                // between successive highlights.
                myDataGrid.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OUT));
            }

            private function createTooltip(e:ToolTipEvent):void {
                var tt:MyCustomTooltip = new MyCustomTooltip();
                tt.firstName = highlightedItem.name;
                tt.lastName = highlightedItem.surname;
                // Contract with the tooltip manager: if it finds an IToolTip instance attached to
                // the event, it uses that instance instead of creating the standard one.
                e.toolTip = tt;
            }
        ]]>
    </mx:Script>

    <mx:DataGrid id="myDataGrid" toolTip=" " toolTipCreate="createTooltip(event)" itemRollOver="getHighlightedItem(event)">
        <mx:dataProvider>
            <mx:Object name="john" surname="doe"/>
            <mx:Object name="mike" surname="smith"/>
        </mx:dataProvider>
    </mx:DataGrid>

</mx:Application>

<!-- MyCustomTooltip.mxml -->
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.core.IToolTip" 
    backgroundColor="yellow" backgroundAlpha="0.6">

    <mx:Script>
        <![CDATA[
            private var _firstName:String;
            private var _lastName:String;

            // Dummy implementations to comply with mx.core.IToolTip
            public function get text():String {return null;}
            public function set text(value:String):void {}

            // properties and functions

            public function set firstName(value:String):void {
                _firstName = value;
                invalidateProperties();
            }

            public function set lastName(value:String):void {
                _lastName = value;
                invalidateProperties();
            }

            override protected function commitProperties():void {
                fName.text = _firstName;
                lName.text = _lastName;
            }
        ]]>
    </mx:Script>

    <mx:Label x="0" y="0" id="fName"/>
    <mx:Label x="0" y="20" id="lName"/>

</mx:Canvas>

.
.
Or try something like this
.
.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="doInit();">
<mx:Script>
<!![CDATA[import mx.collections.ArrayCollection; // this holds the grid data
[Bindable]
private var myData:ArrayCollection = new ArrayCollection();private function doInit():void{
myData.addItem({fname:"Joe",lname:"Bloggs"});
myData.addItem({fname:"Joe1",lname:"Bloggs"});
}

private function buildToolTip(item:Object):String{
var myString:String = "";
if(item != null)
{
myString = myString + "Firstname : " + item.fname + "\n";
myString = myString + "Lastname : " + item.lname + "\n"
}
return myString;
}
]]>
</mx:Script>
<mx:DataGrid id="dGrid"  dataProvider="{myData}"  visible="true" dataTipFunction="buildToolTip">
<mx:columns>
<mx:DataGridColumn dataField="fname" headerText="FirstName" showDataTips="true" />
<mx:DataGridColumn dataField="lname" headerText="LastName" showDataTips="true" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
只想待在家 2024-10-05 18:16:27

我想通了:在 itemRollOver 处理程序上添加 event.itemRenderer.addEventListener(ToolTipEvent.TOOL_TIP_CREATE, createTT);

I figured it out: On itemRollOver handler you add event.itemRenderer.addEventListener(ToolTipEvent.TOOL_TIP_CREATE, createTT);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文