Posted By

Winkyboy on 08/01/10


Tagged

names as3 naming


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

adrianparr
thastyle
tspitzr


AS3 Get Object Names from GetObjectsUnderPoint


 / Published in: ActionScript 3
 

Calling this will conditionally trace the list of object names underneath your mouse point. It will only trace when the list of objects beneath the mouse actually changes.

  1. var previousOUM:String = "";
  2. private function listObjectsUnderMouse():void {
  3. var point:Point = new Point(mouseX, mouseY);
  4. var objects:Array = stage.getObjectsUnderPoint(point);
  5. var currentOUM:String = ""; // Objects Under Mouse
  6. var results:String = "";
  7. for (var i:int = 0; i < objects.length; i++)
  8. {
  9. currentOUM += DisplayObject(objects[i].parent).name
  10. if (i != objects.length-1) currentOUM += ", ";
  11. }
  12. if (currentOUM != previousOUM) {
  13. trace(currentOUM);
  14. previousOUM = currentOUM;
  15. }
  16. }
  17.  
  18. // modified/improved version below for pure AS/Flex:
  19.  
  20.  
  21. // Syntax
  22. Application.application.stage.addEventListener(MouseEvent.CLICK, listObjectsUnderMouse);
  23.  
  24. // Variable(s)
  25. var previousOUM:String = "";
  26.  
  27. // Function
  28. private function listObjectsUnderMouse(e:MouseEvent):void {
  29. var point:Point = new Point(e.stageX,e.stageY);
  30. var objects:Array = Application.application.stage.getObjectsUnderPoint(point);
  31. var currentOUM:String = ""; // Objects Under Mouse
  32. var currentTypes:String = "";
  33. var results:String = "";
  34. for (var i:int = 0; i < objects.length; i++) {
  35. currentOUM += DisplayObject(objects[i].parent).name;
  36. currentTypes += DisplayObject(objects[i].parent);
  37. if (i != objects.length-1) {
  38. currentOUM += ", ";
  39. currentTypes += ", ";
  40. }
  41. }
  42. if (currentOUM != previousOUM) {
  43. trace("\n\n><> " + objects.length + " object(s) under mouse position (" + point.x + "/" + point.y + ").\n><> " + currentOUM + "\n><>" + currentTypes);
  44. previousOUM = currentOUM;
  45. }
  46. }

Report this snippet  

You need to login to post a comment.