views:

380

answers:

3

So I've noticed Windows 7 has a disturbing tendency to prevent you from dragging the title bar of windows off the top of the screen. If you try - in this case, using an air app with a draggable area at the bottom of the window, allowing you to push the top of the window up past the screen - it just kicks the window back down far enough that the title bar is at the top of what it considers the 'visible area.'

One solution would be to resize the app window as it moves, so that the title bar is always where windows wants it. How would you resize the window while you're dragging it, though? Would you do it like this?

dragHitArea.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void{
    stage.nativeWindow.height += 50;
    stage.nativeWindow.startMove();
    stage.nativeWindow.height -= 50;
});

see what's going on there? When I click, I'm doing startMove(), which is hooking into the OS' function for dragging a window around. I'm also increasing and decreasing the height of the window by 50 pixels - which should give me no net increase, right?

Wrong - the first '.height +=' gets executed, but the '.height -=' after the .startMove() never runs.

Why?

A: 

This seems like it would be a funny effect and not all standard window behavior. Why do you feel the need to do anything? Why not let the user resize the window themselves if they need to?

davr
I mean, it shouldn't matter why I want to do it, the question is *how* to do it... but because it probably does sound a little weird, I'll update the question to clarify.
matt lohkamp
A: 

have you tried looking into the NativeWindowBoundsEvent.MOVING event?

stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.MOVING, windowMove);
private function windowMove(e:NativeWindowBoundsEvent) : void {
    trace(e.beforeBounds);
    trace(e.afterBounds);
    // resize window as needed based on these
}

references: Google, which led me to http://lowpitch.com/blog/nativewindow-using-air-windows-with-actionscript-part-3-of-3/ which led me to http://livedocs.adobe.com/flex/3/langref/flash/events/NativeWindowBoundsEvent.html

NativeWindowBoundsEvent.MOVING is fired before the position actually changes, whereas NativeWindowBoundsEvent.MOVE is fired after the position has changed, if you were wondering. Thus you would need the MOVING event

(by the way, I was tempted to just say "you can't" without doing any research for the bounty... but felt that would be mean)

jonathanasdf
I'll give this a look when I get into the office tomorrow morning. I know, cutting it close. :)
matt lohkamp
Nope - add "e.curentTarget.height = 50;" in your event handler, and when this fires due to stage.nativeWindow.startMove(), the height never jumps to 50, regardless of what even you're listening for. I'm really thinking that this just can't be done - you can't resize the window while you're dragging it to reposition it, and you can't drag and drop the window in such a way that the title bar ends up above the desktop area.
matt lohkamp
I hope that you tried `e.currentTarget` instead of `e.curentTarget` heh. But anyways, if this doesn't work... well here is a possible workaround. Instead of using the built in thing, fake it. Attach the MOUSE_DOWN to what you would like to move the screen. Then, when MOUSE_DOWN is activated attach a MOUSE_MOVE and MOUSE_UP. In the MOUSE_MOVE you would manually move the window, resizing if necessary. In the MOUSE_UP you would remove the MOUSE_MOVE and MOUSE_UP. Note that MOUSE_MOVE should probably be attached to the stage.
jonathanasdf
yeah, that's still a possibility - the problem is, the OS's function for repositioning windows is so much smoother than AIR's, from what I saw... but I might have to end up doing it this way.
matt lohkamp
sorry I couldn't have been of much help. But at least you know that there's at least a possible way you could do it :)
jonathanasdf