getObjectsUnderPoint по координатам фейкового указателя.
Проходитесь по массиву и диспетчите-баблите вручную нужный набор событий из подходящего InteractiveObject (верхний из тех, кто mouseEnabled)
Вот на коленке наваял пример:
Код AS3:
project fakeMouseTestContent
Код AS3:
package
{
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.events.Event;
[SWF(width="900", height="900")]
public class fakeMouseTestContent extends Sprite
{
private static const NUM_IN_LAYER : Number = 3;
private static const DEEP : Number = 3;
private var _circles : Vector.<Vector.<Sprite>> = new Vector.<Vector.<Sprite>>(DEEP);
public function fakeMouseTestContent()
{
//Security.allowDomain('*');
if(stage)
{
init();
}
else
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
}
//*** private ***//
private function init():void
{
drawBg();
createCircles(this);
}
private function drawBg():void
{
graphics.beginFill(0x0, 0);
graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
}
private function createCircles(host : DisplayObjectContainer):void
{
for(var deepCount : int = 0; deepCount < DEEP; deepCount++)
{
_circles[deepCount] = new Vector.<Sprite>(NUM_IN_LAYER);
for(var circleCount : int = 0; circleCount < NUM_IN_LAYER; circleCount++)
{
var circle : InteractiveCircle = new InteractiveCircle(InteractiveCircle.MAX_SIZE/(1 + deepCount));
_circles[deepCount][circleCount] = circle;
circle.name = 'deep : ' + deepCount + ' , num : ' + circleCount;
if(deepCount > 0)
{
var parentLayer : Vector.<Sprite> = _circles[deepCount-1];
var parentCircle : Sprite = parentLayer[int(Math.random() * parentLayer.length)];
parentCircle.addChild(circle);
}
else
{
host.addChild(circle);
}
var circleParent : DisplayObjectContainer = circle.parent;
circle.x = Math.random()*(circleParent.width - circle.width);
circle.y = Math.random()*(circleParent.height - circle.height);
}
}
}
//*** handlers ***///
private function onAddedToStage(event : Event):void
{
init();
}
}
}
import flash.display.Sprite;
import flash.events.MouseEvent;
internal class InteractiveCircle extends Sprite
{
public static const MAX_SIZE : Number = 400;
private static const COLOR : uint = 0x0;
private static const FILL_ALPHA : Number = 0.5;
private static const OUT_ALPHA : Number = 0.5;
private static const OVER_ALPHA : Number = 1;
public function InteractiveCircle(size : Number = MAX_SIZE)
{
initListeners();
draw(size);
toOutState();
}
//*** private ***//
private function draw(size : Number):void
{
graphics.clear();
graphics.beginFill(COLOR, FILL_ALPHA);
graphics.drawCircle(size/2, size/2, size/2);
}
private function initListeners():void
{
addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
}
private function toOverState():void
{
alpha = OVER_ALPHA;
}
private function toOutState():void
{
alpha = OUT_ALPHA;
}
//*** handlers ***//
private function onMouseOver(event : MouseEvent):void
{
trace('over. name : ' + event.currentTarget.name);
toOverState();
}
private function onMouseOut(event : MouseEvent):void
{
trace('out. name : ' + event.currentTarget.name);
toOutState();
}
}
Код AS3:
project fakeMouseTestContainer
Код AS3:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
[SWF(width="900", height="900")]
public class fakeMouseTestContainer extends Sprite
{
private static const URL : String = 'fakeMouseTestContent.swf';
private static const REQUEST : URLRequest = new URLRequest(URL);
private var _loader : Loader;
private var _fakeCursor : FakeCursor;
public function fakeMouseTestContainer()
{
init();
loadContent();
}
//*** private ***//
private function init():void
{
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
addChild(_loader);
_fakeCursor = new FakeCursor();
addChild(_fakeCursor);
_fakeCursor.x = stage.stageWidth/2;
_fakeCursor.y = stage.stageHeight/2;
KeyboardManager.init(stage);
}
private function loadContent():void
{
var context : LoaderContext = new LoaderContext(false);
_loader.load(REQUEST, context);
}
//*** handlers ***//
private function onLoadComplete(event : Event):void
{
_fakeCursor.reset();
}
}
}
Код AS3:
package
{
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.ui.Keyboard;
import flash.utils.Dictionary;
public class FakeCursor extends Sprite
{
private static const SIZE : Number = 10;
private static const COLOR : uint = 0xAA00AA;
private static const ALPHA : Number = 0.5;
private static const SPEED : Number = 10;
private static const DIRECTIONS : Object = initDirections();
//
private var _currObjectsUnderPoint : Dictionary;
private var _currentTopObject : InteractiveObject;
private var _currentPoint : Point;
public function FakeCursor()
{
draw();
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
}
//*** public ***//
public function reset():void
{
_currObjectsUnderPoint = new Dictionary(true);
_currentTopObject = null;
_currentPoint = null;
onEnterFrame(null);
}
//*** private ***//
private function draw():void
{
graphics.beginFill(COLOR, ALPHA);
graphics.drawCircle(0, 0, SIZE/2);
}
//*** handlers ***//
private function onEnterFrame(event : Event):void
{
move();
findInteractObject();
}
private function move():void
{
var pressedKeys : Array = KeyboardManager.getPressedKeys();
var direction : Point = new Point();
for each(var keyCode : int in pressedKeys)
{
var currDirection : Point = DIRECTIONS[keyCode] as Point;
if(currDirection)
{
direction = direction.add(currDirection);
}
}
x += direction.x * SPEED;
y += direction.y * SPEED;
}
private function findInteractObject():void
{
var globalPoint : Point = this.localToGlobal(new Point());
var objects : Array;
var numObjects : uint;
var objectsHash : Dictionary;
var topObject : InteractiveObject;
if(_currentPoint && _currentPoint.equals(globalPoint))
{
return;
}
_currentPoint = globalPoint;
objects = stage.getObjectsUnderPoint(globalPoint);
objectsHash = new Dictionary();
numObjects = objects.length;
for(var i : int = 0; i < numObjects; i++)
{
var object : InteractiveObject = objects[i] as InteractiveObject;
if(object)
{
if(!topObject)
{
topObject = object;
}
objectsHash[object] = object;
}
}
handleUnderObjects(objectsHash, topObject);
}
private function handleUnderObjects(newObjects : Dictionary, topObject : InteractiveObject):void
{
for each(var oldObject : InteractiveObject in _currObjectsUnderPoint)
{
if((oldObject in newObjects) == false)
{
disptatchMouseEvent(oldObject, MouseEvent.MOUSE_OUT, topObject);
}
}
for each(var newObject : InteractiveObject in newObjects)
{
if((newObject in _currObjectsUnderPoint) == false)
{
disptatchMouseEvent(newObject, MouseEvent.MOUSE_OVER, _currentTopObject);
}
}
_currObjectsUnderPoint = newObjects;
if(_currentTopObject != topObject)
{
if(_currentTopObject)
{
disptatchMouseEvent(_currentTopObject, MouseEvent.MOUSE_OUT, topObject);
}
if(topObject)
{
disptatchMouseEvent(topObject, MouseEvent.MOUSE_OVER, _currentTopObject);
}
_currentTopObject = topObject;
}
}
private function disptatchMouseEvent(object : InteractiveObject, type : String, relatedObject : InteractiveObject):void
{
var globalPoint : Point = new Point(this.x, this.y);
var localPoint : Point = object.globalToLocal(globalPoint);
var localX : Number = localPoint.x;
var localY : Number = localPoint.y;
var event : MouseEvent = new MouseEvent(type, true, false, localX, localY, relatedObject)
object.dispatchEvent(event);
}
//*** handles ***//
private function onAddedToStage(event : Event):void
{
reset();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onRemovedFromStage(event : Event):void
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
//*** private static ***//
private static function initDirections():Object
{
var directions : Object = {};
directions[Keyboard.UP] = new Point(0, -1);
directions[Keyboard.DOWN] = new Point(0, 1);
directions[Keyboard.LEFT] = new Point(-1, 0);
directions[Keyboard.RIGHT] = new Point(1, 0);
return directions;
}
}
}