views:

1421

answers:

3

I'm developing a Flex 2 application, and I noticed that part of the library which is responsible for moving GUI windows (TitleWindows) around when you drag them with the mouse gets confused if there is a clickable (buttonMode = true) sprite beneath them. When I say confused, I mean that the window is moved around normally for a while, but then at some point "jumps" into the upper left corner of the flash app, and makes very minor movement there. Then at some other point it jumps back. It is more difficult to explain than to experience, so please go and see for yourself. Here's how to reproduce the problem:

  1. Go to http://www.panocast.com
  2. In the left sidebar, choose "Real Estate"
  3. Just below the bottom right corner of the flash window, choose "high res" by clicking on the rightmost icon.
  4. When (part of) the video loads, click on the staircase. A TitleWindow will pop up.
  5. Try dragging it around the screen. When the mouse cursor is moved above one of the clickable areas (like the staircase), the window is misplaced.

(Sorry, but can't give you a direct link, part of the page is generated dynamically.)

(What's makes the problem even more interesting is that for me, in "low res" mode, the problem does not occur! There is very little difference between the various modes.) I would really appreciate if someone told me what was going on here and how it can be fixed.

I'm not sure if it matters, but the underlying sprite is actually not just plain sprite, rather it is a Papervision3D renderer object with some 3D elements in it. I'm telling this because it is possible that the incorrect mouse coordinates somehow come from the texture UV mapped on the clickable objects.

+1  A: 

I've managed to replicate this on the low res mode as well, so I don't think it's related to the resolution.

This looks to be because the MouseEvent is being handled by the TitleWindow AND the Papervision3D window. Perhaps you need to force stopImmediatePropagation() on one or the other? Or maybe switch off the MouseEvent handling for the Pv3D window when the TitleWindow pops up?

inferis
Yes, I was thinking along the same lines, but how Papervision3D handling the mouse event can possibly effect how Flex windows are positioned?
David Hanak
Your mouseclick handler on the pv3d window presumably pops up the title window in the first place? It looks as though it's re-opening the titlewindow each time, positioning it according to where you clicked. Without seeing the code it's difficult to be any more specific though.
inferis
Hmm. I don't think that's it (mouseMove does not open the dialog, AND opening the dialog also recenters it), but I will double check.
David Hanak
+1  A: 

That's a tough one to debug without some source; something's apparently calling either move() or setting x and y properties on that TitleWindow and scheduling it be moved.

When I first read the post, it "smelled" like maybe a rotation miscalculation somewhere (using Math.atan vs. Math.atan2 can sometimes have that kind of effect), so you're right, it could have something to do with PaperVision, assuming you're not using Math.atan or setting rotation properties yourself anywhere. Just thought I'd mention it, though it's probably not happening in your case. You never know, though. ;)

More likely the LayoutManager is moving the component in response to a property change on the component. The Flex docs explain that in addition to setting its x and y properties, and explicit calls to move(), a UIComponent's move event can also be triggered when any of the following other properties change:

  • minWidth
  • minHeight
  • maxWidth
  • maxHeight
  • explicitWidth
  • explicitHeight

PaperVision or no, maybe that info might help you isolate the source of the move. Good luck.

Christian Nunciato
Thanks, that should be enough to get me going. I'll report back when I have more.
David Hanak
Cool, yeah -- good luck. That seems like a tricky one. :)
Christian Nunciato
+1  A: 

I got this figured out. Apparently, this is a Papervision3D problem. There is a class deep inside Papervision3D called VirtualMouse, which is supposed to generate MouseEvents programmatically. This happens, for example, when the user interacts with any of the interactive objects on stage, e.g., a Plane with an interactive material on it (as in my case).

The problem is that the x and y coordinates of the generated event represent texture UV coordinates (just as I suspected) and not real world screen coordinates. When a TitleWindow (or any Panel object) is dragged, a "mouseMove" handler (among others) is added to the SystemManager, which then uses the stageX and stageY properties of the event object to determine the new position of the window. Unfortunately for VirtualMouse's mouse events, these are invalid, since the original x,y coordinates, which are probably used to determine the global stage coordinates are, as I said, not screen coordinates.

Honestly, I'm still unsure whether the events dispatched by VirtualMouse are used anywhere within Papervision3D itself, or they are just offered for convenience, but they sure make it difficult to integrate a viewport into a Flex program. Assuming that such events aren't necessary for PV3D itself, there is a one-liner fix for my problem, which must be added right after the creation of the viewport:

viewport.interactiveSceneManager.virtualMouse.
    disableEvent(MouseEvent.MOUSE_MOVE);

BTW., there was a very similar (or rather, as it turns out, the same) bug with dragging sliders, also fixed by this line.

David Hanak