Flex Datagrid - 如何获取鼠标 x/y 坐标的项目? [英] Flex Datagrid - how to obtain item for mouse x/y coordinates?

查看:26
本文介绍了Flex Datagrid - 如何获取鼠标 x/y 坐标的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是在 DataGrid 实例中选择一个只有屏幕坐标的项目.

my mission is to select an item in a DataGrid instance with nothing but the coordinates on screen.

我们正在 Flash 应用程序中实现右键单击功能,目的是能够右键单击 DG 行,这将选择该行并显示包含一些上下文命令的弹出窗口.

We are implementing right-click functionality in our Flash application, with the goal of being able to right-click a DG row, which would select that row plus show a popup window containing some context commands.

本网站.

到目前为止的进一步进展是通过

Further progress so far has been to obtain the DataGrid instance via

var objects : Array = this.getObjectsUnderPoint(new Point(this.mouseX, this.mouseY));

然后调查数组的每个项目,因为其中一个parent.parentList"是指 DataGrid 实例.

and then to investige each of the array's items, for one of those 'parent.parentList' refers to the DataGrid instance.

现在我被卡住了——我找不到任何点到项目转换器功能或任何东西.到目前为止,我们也非常欢迎对我的方法提出任何意见!

Now I am stuck -- I couldn't find any point-to-item converter function or anything. Any comments about my approach so far very welcome, too!

谢谢!

PS:不幸的是,使用标准的 Flash ContextMenu 不是一个选项.

PS: Using the standard Flash ContextMenu is, unfortunately, not an option.

推荐答案

/**
* Let mx and my be the mouse coordinates 
* (relative to the stage, not relative to the clicked object)
* */

var len:Number = dg.dataProvider.length;
var i:Number;
var p1:Point;
var p2:Point;
var renderer:DisplayObject;
for(i = 0; i < len; i++)
{
  renderer = DisplayObject(dg.indexToItemRenderer(i));
  if(!renderer)//item is not displayed (scroll to view it)
    continue;
  p1 = new Point(renderer.x, renderer.y);
  p2 = new Point(renderer.width, renderer.height);
  p1 = renderer.parent.localToGlobal(p1);
  p2 = renderer.localToGlobal(p2);
  if(mx >= p1.x && mx <= p2.x && my >= p1.y && my <= p2.y)
  {
    trace("You clicked on " + dg.dataProvider.getItemAt(i));
    break;
  }
}

<小时>

您可以将 ContextMenu 附加到DataGrid 的 itemRenderer 代替 - 这样您就可以从事件的 currentTarget 属性中获取右键单击的项目.尽可能简单.


You can attach the ContextMenu to the DataGrid's itemRenderer instead - that way you can get the right-clicked item from the event's currentTarget property. As simple as it can get.

这篇关于Flex Datagrid - 如何获取鼠标 x/y 坐标的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆