My WP8 game isn't receiving Drag gestures when using MonoGame - windows-phone-8

I've got a WP8 project that is using the MonoGame framework. I have some code that should recognize Horizontal and Vertical drag events and perform an action but I never seem to get these events. I do get a FreeDrag gesture but the Deltas are always NaN.
I initialize the TouchPanel.EnabledGestures in the Initialize method of the game as follows:
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
TouchPanel.EnabledGestures = GestureType.HorizontalDrag | GestureType.FreeDrag;
}
I have a method that checks the gesture type as follows:
private void CheckUserGesture()
{
while (TouchPanel.IsGestureAvailable)
{
var gesture = TouchPanel.ReadGesture();
switch(gesture.GestureType)
{
case GestureType.DragComplete:
System.Diagnostics.Debug.WriteLine("Drag Complete");
break;
case GestureType.FreeDrag:
System.Diagnostics.Debug.WriteLine("Drag Complete");
break;
case GestureType.HorizontalDrag:
if (gesture.Delta.X < 0)
gameVm.MoveLeft(Math.Abs((int)gesture.Delta.X));
if (gesture.Delta.X > 0)
gameVm.MoveRight((int)gesture.Delta.X);
break;
case GestureType.VerticalDrag:
if (gesture.Delta.Y > 0)
gameVm.MoveDown(Math.Abs((int)gesture.Delta.Y));
break;
case GestureType.Tap:
System.Diagnostics.Debug.WriteLine("Rotating Shape Due To Tap Command");
gameVm.RotateClockwise();
break;
}
}
}
And this is called in the Update method:
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
// TODO: Add your update logic here
//CheckTouchGesture();
CheckUserGesture();
gameVm.UpdateGame((int)gameTime.ElapsedGameTime.TotalMilliseconds);
}
I've also tried using TouchState:
private void CheckTouchGesture()
{
var touchCol = TouchPanel.GetState();
foreach (var touch in touchCol)
{
// You're looking for when they finish a drag, so only check
// released touches.
if (touch.State != TouchLocationState.Released)
continue;
TouchLocation prevLoc;
// Sometimes TryGetPreviousLocation can fail. Bail out early if this happened
// or if the last state didn't move
if (!touch.TryGetPreviousLocation(out prevLoc) || prevLoc.State != TouchLocationState.Moved)
continue;
// get your delta
var delta = touch.Position - prevLoc.Position;
// Usually you don't want to do something if the user drags 1 pixel.
if (delta.LengthSquared() < DragTolerence)
continue;
if (delta.X < 0)
gameVm.MoveLeft(Math.Abs((int)delta.X));
else if (delta.X > 0)
gameVm.MoveRight((int)delta.X);
else if (delta.Y > 0)
gameVm.MoveDown((int)delta.Y);
}
}
But again the deltas are always NaN.
Is there something I'm missing that I might need to initialize?
I've tried various combinations of the EnabledGestures types but still can't get the dragging events to work. Flick doesn't work either.
Things like Tap are fine though.
Thanks

I think this is broken on the current release of MonoGame ( Version 3.0.1, Release date: Mar 3 2013 ).
Building the latest from the GitHub developer branch:
https://github.com/mono/MonoGame.git
(NOTE: I also built SharpDX too from here: https://github.com/sharpdx/SharpDX)
Seems to fix a lot of my problems
I'm not 100% convinced it is fully working though.
Using the touch.TryGetPreviousLocation() as shown in the code above always returns the same position as the current position so doing var delta = loc.Position - preLoc.Postion always results in 0.
At least I'm receiving the drag gestures now.

Related

AS3 Objects Issue with Switches

I am having some issues with AS3 Object Arrays. I am trying to make an inventory system, which the user can navigate left and right (which is working). When the user presses ENTER the item should then equip.
I was going to use switch and case to equip the items, as there will only be around 8 items to the game. I get the result [object purpleSword] when using trace, but my switch isn't getting any results or firing anything. I need the equipItem function to find the purpleSword that's ben found in the arrayItems. Items are added to the arrayItems when picked up off the floor.
Does anyone have any tips for using Objects for an RPG inventory system? Many thanks in advance.
public var arrayItems: Array = new Array();
if (keyEvent.keyCode == Keyboard.ENTER) {
if (currentScreen == "inventory") {
if(inventoryCurrent >= 0) {
var actualCurrentItem = inventoryCurrent - 1;
equipItem(arrayItems[actualCurrentItem]);
}
}
}
public function equipItem(itemNumber) {
switch(itemNumber) {
case "purpleSword":
trace("equip purple sword");
break;
}
}
AS3 has a type system, you should use it to help you understand your own errors, and help others understand your code (like us).
Given the fact that you say your output gives you [object purpleSword] I can assume you have a class purpleSword. My guess is that this is an exported symbol, not a .as class file, but it could be either.
But those are all guesses because you haven't provided any type information. For example:
arrayItems:Array could contain anything, and you haven't told us what. You could use a items:Vector.<Object> to store objects, or Vector.<Sprite> to store symbols exported from your Flash library, or better yet create an InventoryItem class and use a Vector.<InventoryItem> to store them.
var actualCurrentItem should be var actualCurrentItem:int
equipItem(itemNumber) should be equipItem(itemNumber:int):void?
If you do this, you will realize (either through your own observation or the compiler telling you) that your equipItem() function is wrong: it expects an itemNumber but it will receive an object.
If my prior assumptions were correct, you could do this:
public var items:Vector.<Object> = new <Object>[];
if (keyEvent.keyCode == Keyboard.ENTER) {
if (currentScreen == "inventory") {
if(inventoryCurrent >= 0) {
var actualCurrentItem:int = inventoryCurrent - 1;
equipItem(items[actualCurrentItem]);
}
}
}
public function equipItem(item:Object):void {
switch(item.constructor) {
case purpleSword:
trace("equip purple sword");
break;
}
}
This works because Object/constructor is a reference to the class of any object, ie purpleSword class, etc. However, you really should use something more concrete than Object, which could be any kind of object and tells you nothing about what kind of properties it might have.

AS3: pass Keyboard control to child movieclip and back to main timeline

EDIT: I don't know if this is the norm, but I preferred to leave the original question in and add updates. Please, feel free to let me know if I should eliminate the original code snippets and somesuch.
I am trying to create a slideshow-like presentation in flash CS6, using a main timeline with one symbol in each frame and the different animations (some quite complex) in those symbols. Since I'm going to use a presenter remote, I've captured the keystrokes and coded pg_up and pg_down to go to the next and previous frame respectively:
stage.addEventListener(KeyboardEvent.KEY_DOWN, pagerFunction);
var symb:movieClip;
function pagerFunction(e:KeyboardEvent):void
{
var myKey = e.keyCode;
if (myKey == Keyboard.PAGE_DOWN){
if (symb != null){
//some code that allows to control the symbols timeline forward
} else {
nextFrame();
}
}
if (myKey == Keyboard.PAGE_UP){
if (symb != null){
//some code that allows to control the symbols timeline backward
} else {
prevFrame();
}
}
The problem I'm having is the following. I've added framelabels and stop(); code inside the symbol animations where I needed to control the step from one animation to the next one. However, after having tried numerous solutions on the web, I haven't been able to succeed having the symbols react to pg_up and pg_down as if they were part of the main timeline.
To sum up, what I need to solve is this:
Enter Main timeline Frame
Identify symbol instance (labeled as _mc)
Inside symbol timeline, play from first frame (labeled '0') until next labeled frame ('1' and so on)
stop and wait for next pg_down to start playing from next labeled frame to the following (i.e. '1'-'2'), or pg_up to start playing from the previous labeled frame (i.e. '0' to '1') (for this, I would use a variable to keep track.
on last frame (labeled 'final') exit symbol focus and return keyboard control to main timeline to allow pg_down and pg_up to move to the next / previous frame. on pg_up on symbol.currentFrame == 0, do same.
BTW, if there's a better way to achieve this, I'm open (and quite desperate) for better suggestions / solutions.
Thank you so much to anyone who can help!
Edit: Ok, I guess I wasn't too clear on the issue, so I'll try to add a bit to this:
addEventListener(KeyboardEvent.KEY_DOWN, mc_pagerFunction);
var lbl:String;
var counter:Number = 0;
function mc_pagerFunction(e:KeyboardEvent):void {
var myKey = e.keyCode;
if (myKey == Keyboard.PAGE_DOWN){
lbl = this.currentFrameLabel;
if (this.currentFrameLabel == 'final'){
stop();
stage.focus = this.parent; //which would be the main timeline
} else if (Number(lbl) == counter){
this.gotoAndStop(lbl);
counter++;
} else {
this.gotoAndPlay(lbl);
}
}
if (myKey == Keyboard.PAGE_UP){
lbl = this.currentFrameLabel;
if (this.currentFrameLabel == '0'){
stop();
stage.focus = this.parent; //which would be the main timeline
} else if (Number(lbl) == counter){
this.gotoAndStop(lbl);
counter--;
} else {
this.gotoAndPlay(lbl);
}
}
}
Now, this bit is the behaviour I'd like to see inside the symbol when the main timeline goes into the next frame, thus being able to use the main timeline as sort of slideholder and the real thing happening inside the symbol.
Btw, I'd like to try and keep all code within the main action layer, not in the symbols. I tried that, shifting focus to the symbol and it didn't work either, and having code all over the place grates against my nerves ;).
I hope this throws some light on what I'm stuck at.
Again, any help is appreciated. Thanks all in advance
UPDATE:
Please someone help me out here!
This is what I'm trying. Logically, it makes all the sense in the world, except that it doesn't work.
var symb:MovieClip;
symb = MovieClip(root); //assign symbol I want to be controlled by pg_up/pg_down
symb.focusRect = false;
stage.focus = symb; //focus on current symbol
symb.addEventListener(KeyboardEvent.KEY_DOWN, mc_pager); //add keyboard event listener
function mc_pager(e:KeyboardEvent):void{
var myKey = e.keyCode;
if (myKey == Keyboard.PAGE_DOWN){
do{
symb.play(); // it plays, then checks if the lbl is null or final, then quits
} while (symb.currentFrameLabel == null && symb.currentFrameLabel != 'final');
symb.stop();
symb.removeEventListener(KeyboardEvent.KEY_DOWN, mc_pager);
stage.focus=MovieClip(root); //return focus to main timeline (in the next keyframes, the focus is on the nested _mc
}
if (myKey == Keyboard.PAGE_UP){
do{
symb.prevFrame();
} while (symb.currentFrameLabel == null && symb.currentFrameLabel != '0');
symb.stop();
symb.removeEventListener(KeyboardEvent.KEY_DOWN, mc_pager);
stage.focus=MovieClip(root);
}
}
Where am I being to moronic to get it right? Please, guys, you're the experts, I need your advice here. Thanks!
UPDATE:
Doing a trace on symb, it seems like as soon as it enters the function, it forgets the initial assignment (symb = MovieClip(root)) and shows null. Why?
In this sample, I created a basic proof of concept where I have a circle MC with an instance name of "c" on the main timeline. Within this mc, I created with 2 keyframes inside with stop actions on both. I colored the circle a different color on frame 2 and labeled it as "two".
In the Main timeline I have the following code:
import flash.events.KeyboardEvent;
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyEvt);
function keyEvt(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.PAGE_DOWN){
trace("down");
c.gotoAndPlay("two");
}
}
This should help form a foundation for your code as long as you stick with targeting the symbol through direct reference and ensure your keyboard event is attached to the stage.
Also, always stick with getting a basic working version down first. I.E. Check to see if your keyboard listeners are working for your target object and then build additional functionality off of that.

Does anyone know why my object pool won't work after i dispose of an object?

After trying to optimize my game i started off with the obvious object pool. I followed the more complicated one using max_growth etc then went on to a simple one but i keep hitting the same problems. Now after over 40hrs of searching online and asking help from a friend who knows a lot more than me about flash i've given up and decided to come here. The code below includes some # just for reference and i've left in my commented stuff which i've tried and also hasn't worked.
My Cpool class
package {
import flash.display.DisplayObject;
public class CPool
{
public var counter:int;
private var pool:Array;
//public function CPool(type:class, len:int)
public function CPool()
{
pool = new Array();
counter = 10;
//counter=len;
//var i:int=len;
var i:int = 10;
while (--i > -1)
//pool[i] = new type();
pool[i] = new Condor();
};
public function getCondor():Condor
{
trace(counter);
//trace (pool.length);
if (counter > 0)
{
return pool[--counter];
}
else
{
var cde = new Condor();
return cde;
}
};
public function disposeCondor(disposedCondor:Condor):void {
pool[counter++] = disposedCondor;
//pool.unshift(disposedCondor); #10
};
}
}
You can see it's a simple one that just uses get and dispose. My code on my logic class below that refers to the pool.
public var cpool:CPool;
cpool = new CPool(); //(in the constructor)
else if (whichBird ==12)
{
bird = cpool.getCondor() as Condor;
} // (in the addBird section)
private function checkBirdsOnScreen():void
{
for (var i:int = 0; i < birdArray.length; i++)
{
var dg = birdArray[i];
if (birdArray[i].x < -100 )
{
dg.parent.removeChild(dg);
birdArray.splice(i, 1);
//hc.destroyCondor(); #9
//tr cpool.disposeCondor(dg); #1
//birdArray[i].destroyCondor(); #2
}
}
}
and finally my destroy bird function in the condor class
public function destroyCondor():void
{
//removeChild(oldCondor); #5
//ConPool.disposeCondor(oldCondor); #4
//this.x=390 #3
//ConPool.disposeCondor(this);
parent.removeChild(this); //remove object from stage
removeEventListener(Event.ENTER_FRAME, CondorLoop);
}
As you can see i've tried every way i can think of to get this to work. The code as it stands starts off with 10 condors in the pool, when they go off screen they leave and the trace counter in the pool shows the pool going down, when it gets to 0 it creates new condors. Now this works this way or when i use destroyCondor unless i take some comments out. When i remove //tr in the dispose condor then it works for the first 2 condors, the counter goes to 9, then 9 again then 10 and stays at 10, the problem is it stops putting any more on screen, no errors but it stops working. Btw, i've also tried trace (pool.length) but i keep getting 10s all the way down.
I've also tried #1 and 2 with no effect. The closest i've come is #10, the unshift statement in the pool. This actually looks like it works, counter goes down to 9, back up to 10 when they go off screen like it's putting them back into the pool but when 10 have gone past they just stop coming altogether, even bypassing the new condor statement. I really have tried everything that i can think off as you can see from the comments, even going form the more advanced pooling to this simplified version and still getting nowhere. Over 40 hrs now, staying up till 4am as i'm so frustrated at not being able to solve this problem and i haven't even done the bitmaps caches yet. Can anyone please help?
If you need to alter the array while traversing it, do a backwards traverse.
for (var i:int=birdArray.length-1;i>=0;i--) {...}
This eliminates both null pointers trouble, missed elements (if you encounter this as well) and the need of a temporary array.

Overriding WP8 Navigation - crash in PhoneApplicationPage

I'm trying to do something that's arguably a bad idea, but I think it's still possible. I'm trying to override how WP8 handles the Back Button and implement it myself. I theorize that if I:
The Plan
Only ever create one "Frame" and "Page" in the entire application
Always handle PhoneApplicationPage.BackKeyPress myself unless they were about to back out of the application.
The Repro
Here's a sample project that has the crash
The code
..then it should work. However, my attempts are being thwarted by Windows Phone. Here's the code:
// This basically happens on PhoneApplicationService.OnLaunched
_viewModelChanged.StartWith(ViewModel).Where(x => x != null).Subscribe(vm => {
var page = default(IViewFor);
var frame = RootVisual as PhoneApplicationFrame;
// Find the initial PhoneApplicationPage for the app
page = RxApp.GetService<IViewFor>("InitialPage");
// Depending on how we're being signalled (i.e. if this is cold start
// vs. resume), we need to create the PhoneApplicationFrame ourselves
if (frame == null) {
frame = new PhoneApplicationFrame() {
Content = page,
};
}
page.ViewModel = vm;
var pg = page as PhoneApplicationPage;
if (pg != null) {
pg.BackKeyPress += (o, e) => {
if (ViewModel.Router.NavigationStack.Count <= 1 ||
ViewModel.Router.NavigateBack.CanExecute(null)) {
return;
}
e.Cancel = true;
ViewModel.Router.NavigateBack.Execute(null);
};
}
// Finally, set Application.RootVisual
RootVisual = frame;
});
Sadness
This works great, until right after this code executes, where a DispatcherItem queued by the framework crashes the app:
System.NullReferenceException occurred
Message: A first chance exception of type 'System.NullReferenceException' occurred in Microsoft.Phone.ni.dll
Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) Unknown
Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.PhoneApplicationPage.Microsoft.Phone.Controls.IPhoneApplicationPage.InternalOnNavigatedFromX(System.Windows.Navigation.NavigationEventArgs e) Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.NavigationService.RaiseNavigated(object content, System.Uri uri, System.Windows.Navigation.NavigationMode mode, bool isNavigationInitiator, Microsoft.Phone.Controls.IPhoneApplicationPage existingContentPage, Microsoft.Phone.Controls.IPhoneApplicationPage newContentPage) Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.NavigationService.CompleteNavigation(System.Windows.DependencyObject content, System.Windows.Navigation.NavigationMode mode) Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(System.IAsyncResult result) Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(System.AsyncCallback userCallback, System.Windows.Navigation.PageResourceContentLoader.PageResourceContentLoaderAsyncResult result) Unknown
Microsoft.Phone.ni.dll!System.Windows.Navigation.PageResourceContentLoader.BeginLoad.AnonymousMethod__0(object args) Unknown
[Native to Managed Transition]
mscorlib.ni.dll!System.Delegate.DynamicInvokeImpl(object[] args) Unknown
System.Windows.ni.dll!System.Windows.Threading.DispatcherOperation.Invoke() Unknown
System.Windows.ni.dll!System.Windows.Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority priority) Unknown
System.Windows.ni.dll!System.Windows.Threading.Dispatcher.OnInvoke(object context) Unknown
System.Windows.ni.dll!System.Windows.Hosting.CallbackCookie.Invoke(object[] args) Unknown
System.Windows.RuntimeHost.ni.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam* pParams, System.Windows.Hosting.NativeMethods.ScriptParam* pResult) Unknown
So, I've solved this - my code was problematic because I didn't grok how WP8 works :) Here's what I understand now, which may also be wrong but I'll write it anyways
How your WP8 app is initialized:
The OS creates your App class via rehydrating App.xaml.cs
This means, your constructor gets run, and as part of that, you create a PhoneApplicationFrame
Creating a PhoneApplicationFrame seems to also set a global static variable (same thing happens with creating PhoneApplicationService in the App.xaml, it sets PhoneApplicationService.Current).
NavigationService then attempts to recreate a XAML View via a resource string (i.e. '/MainPage.xaml'). Either it will recreate the one that was previously tombstoned, or if not, it defaults to the one in your WMAppManifest (this is the part I didn't understand).
PhoneApplicationFrame.Navigated gets called by NavigationService - this is where you can actually start doing stuff, including most importantly, setting Application.RootVisual, which will send the Loading... screen away
PhoneApplicationService.Launched or PhoneApplicationService.Activated finally fires, once basically everything is set up, depending how your app was woken up.
Found the issue. Well, the tip of the iceberg.
The code of the InternalOnNavigatedFrom method is:
internal override void InternalOnNavigatedFrom(NavigationEventArgs e)
{
PhoneApplicationPage content = e.Content as PhoneApplicationPage;
string str = ((content == null) || (content.Title == null)) ? string.Empty : content.Title;
PerfUtil.BeginLogMarker(MarkerEvents.TH_ONNAVIGATEDFROM_PAGE, string.Format("{0},{1},{2}", (base.Title == null) ? "" : base.Title, e.NavigationMode, str));
this.OnNavigatedFrom(e);
PerfUtil.EndLogMarker(MarkerEvents.TH_ONNAVIGATEDFROM_PAGE, string.Format("{0},{1},{2}", (base.Title == null) ? "" : base.Title, e.NavigationMode, str));
DeviceStatus.KeyboardDeployedChanged -= new EventHandler(this.OnKeyboardDeployedChanged);
Task rootTask = ApplicationHost.Current.RootTask;
rootTask.OnVisibleRegionChange = (ITask.VisibleRegionChanged) Delegate.Remove(rootTask.OnVisibleRegionChange, new ITask.VisibleRegionChanged(this.OnVisibleRegionChange));
Task task2 = ApplicationHost.Current.RootTask;
task2.OnSipVisibilityChange = (ITask.SipVisibilityChange) Delegate.Remove(task2.OnSipVisibilityChange, new ITask.SipVisibilityChange(this.OnSipVisibilityChange));
this._lastSipHeight = 0.0;
this._dictionary = null;
}
After a bit of debugging, I concluded that neither e or Application.Current.RootTask were null. After scratching my head, I looked at the code of the KeyboardDeployedChanged event handler:
public static event EventHandler KeyboardDeployedChanged
{
[SecuritySafeCritical] add
{
if (KeyboardDeployedSubscription == null)
{
KeyboardDeployedSubscription = new SubscriptionHandler(DeviceTypes.KeyBoard);
}
KeyboardDeployedSubscription.Changed += value;
}
[SecuritySafeCritical] remove
{
KeyboardDeployedSubscription.Changed -= value;
}
}
This code is poorly written. If the remove part of the handler is called before the add, KeyboardDeployedSubscription will be null and an exception will be raised. To test my theory, I subscribed to the event in App's constructor:
public App()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
DeviceStatus.KeyboardDeployedChanged += (sender, e) => { };
And sure enough, the exception was gone. Now, to understand why your code is triggering this issue, I backtraced to which part of the framework is supposed to subscribe to the event. The only candidate is the InternalOnNavigatedTo method.
Therefore, your issue is that OnNavigatedFrom is called even though OnNavigatedTo was never called.
Since you are strungling with the built-in auto navigation of Windows Phone to the page defined in WMAppManifest.xml, I tried to remove the auto navigation and it basically worked (no exception).
I just replaced
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
with
<DefaultTask Name="_default" />
Not sure if this solves your problem but it at least doesn't crash anymore.

Emulating Mouse Event AS3

I have a project that involves polling a hardware switch each update and converting its states to a custom events:
ToggleSwitchEvent.BackWardButtonDown
ToggleSwitchEvent.BackWardButtonUp
ToggleSwitchEvent.Click
etc ....
The hardware switch acts similar to a two button mouse. So I would like to be able to "inject" the custom ToggleSwitchEvent events into the Display List and have it act just as a MouseEvent does, bubbling up from the InteractionObject that the click intersects with. This would allow me to addEventListener to the display list just as I do with MouseEvents.
The trouble, as far as I understand it, is that I would need a reference to the leaf nodes of the DisplayList to insert my ToggleSwitchEvent manually. I would like to say that the switch was clicked at a certain position on screen, and have the DisplayList figure out what InteractionObject the click intersects and dispatch my ToggleSwitchEvent instead of a MouseEvent.
Is there a method to emulate the MouseEvent in AS3 but using a custom event?
i do not quite understand ... do you want a custom event to bubble, or to fire MouseEvents on your own?
any event will bubble as expected, if its bubbles property is set to true ...
if you dispatch mouse events manually, they will also bubble, and even their stageX and stageY is calculated appropriately ...
so good luck then ... ;)
edit:
ok, well the display list will not really take care of this for you ... actually, you have two options ... start at the stage, and make your way through it, always keeping under the mouse ... or, start at the object under the mouse, get its path in the tree, and find the right InteractiveObject in its parent chain ... the latter can be done using DisplayObjectContainer::getObjectsUnderPoint ... here's the code ...
public static function dispatchEventUnderMouse(event:Event, stage:Stage, point:Point):Boolean {
//return if stage is disabled
if (!stage.mouseEnabled) return false;
//find the topmost object
var cur:DisplayObject = stage.getObjectsUnderPoint(point).pop();
if (cur == null) cur = stage;
//build the path
var path:Array = [];
while (cur != null) {
path.push(cur);
cur = cur.parent;
}
//traverse the path from the root to find the right InteractiveObject
while (path.length > 0) {
cur = path.pop();
if (cur is InteractiveObject) {
if (!(cur as InteractiveObject).mouseEnabled) {
cur = cur.parent;
break;
}
if (cur is DisplayObjectContainer) {
if (!(cur as DisplayObjectContainer).mouseChildren) break;
}
}
else {
cur = cur.parent;
break;
}
}
return cur.dispatchEvent(event);
}
you might actually want to inject the right coordinates into the event, but i guess you'll figure that out ... ;)