ActionScript 3 AS3从GetObjectsUnderPoint获取对象名称

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3从GetObjectsUnderPoint获取对象名称相关的知识,希望对你有一定的参考价值。

var previousOUM:String = "";
private function listObjectsUnderMouse():void {
	var point:Point = new Point(mouseX, mouseY);
	var objects:Array = stage.getObjectsUnderPoint(point);
	var currentOUM:String = ""; // Objects Under Mouse
	var results:String = "";
	for (var i:int = 0; i < objects.length; i++) 
	{
		currentOUM += DisplayObject(objects[i].parent).name
		if (i != objects.length-1) currentOUM += ", ";
	}
	if (currentOUM != previousOUM) {
		trace(currentOUM);
		previousOUM = currentOUM;
	}
}

// modified/improved version below for pure AS/Flex:


// Syntax
Application.application.stage.addEventListener(MouseEvent.CLICK, listObjectsUnderMouse);

// Variable(s)
var previousOUM:String = "";

// Function
private function listObjectsUnderMouse(e:MouseEvent):void {
  var point:Point = new Point(e.stageX,e.stageY);
  var objects:Array = Application.application.stage.getObjectsUnderPoint(point);
  var currentOUM:String = ""; // Objects Under Mouse
  var currentTypes:String = "";
  var results:String = "";
  for (var i:int = 0; i < objects.length; i++) {
    currentOUM += DisplayObject(objects[i].parent).name;
    currentTypes += DisplayObject(objects[i].parent);
    if (i != objects.length-1) {
      currentOUM += ", ";
      currentTypes += ", ";
    }
  }
  if (currentOUM != previousOUM) {
    trace("\n\n><> " + objects.length + " object(s) under mouse position (" + point.x + "/" + point.y + ").\n><> " + currentOUM + "\n><>" + currentTypes);
    previousOUM = currentOUM;
  }
}

以上是关于ActionScript 3 AS3从GetObjectsUnderPoint获取对象名称的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3从坐标中找到角度

ActionScript 3 AS3从外部文本文件加载变量

ActionScript 3 AS3从GetObjectsUnderPoint获取对象名称

ActionScript 3 AS3从文本中删除HTML标记

ActionScript 3 AS3从字符串中剥离空格

ActionScript 3 使用AS3从Flash触发Javascript