/ 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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; } }