Flex的Datagrid中 - 如何获得项目鼠标x / y坐标?鼠标、坐标、如何获得、项目

2023-09-08 12:44:59 作者:小熊探险日记

我的任务是在一个DataGrid实例什么也没有,但是坐标在屏幕上选择一个项目。

我们正在实现右键功能在我们的Flash应用程序,用能的目标右键单击DG行,这将选择该行加上显示包含一些背景的弹出窗口的命令。

我设法得到正确的单击事件到我的Flex应用程序具有的这个网站。

进一步的进展,到目前为止已经取得的DataGrid实例,通过

  VAR对象:阵列= this.getObjectsUnderPoint(新点(this.mouseX,this.mouseY));
 

,然后investige每个阵列的项目,对于那些parent.parentList一指DataGrid实例。

既小又轻还很好的电竞鼠标,骨伽空气鼠AirBlader一个特立独行的答案

现在我坚持 - 我无法找到任何一点对项转换器功能或任何东西。我的做法有任何意见,到目前为止非常欢迎呢!

谢谢!

PS:使用标准Flash文本菜单,不幸的是,不可以选项。

解决方案

  / **
*让MX和我是鼠标坐标
*(相对于舞台,而不是相对于点击的对象)
* * /

VAR LEN:数= dg.dataProvider.length;
变种我:数字;
VAR P1:点;
VAR P2:点;
VAR渲染器:的DisplayObject;
对于(i = 0; I< LEN;我++)
{
  渲染器=的DisplayObject(dg.indexToItemRenderer(一));
  如果(!渲染器)//不显示项目(滚动查看)
    继续;
  P1 =新的点(renderer.x,renderer.y);
  P2 =新的点(renderer.width,renderer.height);
  P1 = renderer.parent.localToGlobal(P1);
  P2 = renderer.localToGlobal(P2);
  如果(MX> = p1.x和放大器;&功放; MX< = p2.x和放大器;&安培;我> = p1.y和放大器;&安培;我< = p2.y)
  {
    跟踪(你点击+ dg.dataProvider.getItemAt(一));
    打破;
  }
}
 

您可以将文本菜单到DataGrid的的itemRenderer 代替 - 这样你可以从事件的 currentTarget当前属性右单击项目。由于简单,因为它可以得到的。

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

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.

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));

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!

Thanks!

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;
  }
}

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.

 
精彩推荐