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

查看:294
本文介绍了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.

我已经设法获得正确的借助这个点击事件进入我的Flex应用程序网站

I have managed to get the right click event into my Flex app with the help of this site.

迄今为止,进一步的进展是通过

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天全站免登陆