1

Is there any way that you can detect the resizeHandlers moment of completion? something like this:

this.addEventListener(Event.RESIZE_COMPLETE, resizeHandler);

I hope somebody has a way to make this possible, so I can remove my enterframehandler :)

3 Answers 3

3

Basically what you need to do is set up a timer that will count time after last Event.RESIZE. Once enough time has passed (like, 50ms or so), you can assume, that the user has stopped continuous resizing of the stage. This code can simulate what you need:

private var timer:Timer;
private var resizeInterval:Number = 50; //amount of time you believe is enough to say that continuous resizing is ended after last discrete Event.RESIZE

private function init():void
{
  timer = new Timer(resizeInterval);
  timer.addEventListener(TimerEvent.TIMER, timerHandler);
  stage.addEventListener(Event.RESIZE, resizeHandler);
}

private function resizeHandler(e:Event):void
{
  if (timer.running) {
    timer.reset();
  }
  timer.start();
}
private function timerHandler(e:Event):void
{
  timer.stop();
  resizeCompletehandler();
}
1

Event.RESIZE is dispatched depending on the browser/OS.

In some circumstances it will be fired every time user changes the browser window size, some times it will be dispatched in intervals, sometimes it will be dispatched when user releases the mouse button.

There is no way of knowing it the resizing has completed...

0
0

In Adobe AIR for Desktop, this Timer pattern won't work with the example timerInterval because the resize events fire between 100ms and 150ms. The timerInterval has to be larger than the largest typical resize event interval to reliably detect the end of the resize process.

Here is trace output while the user resizes the stage:

[trace] 15:02:27:128 onResize() - nativeWindows.width: 911
[trace] 15:02:27:239 onResize() - nativeWindows.width: 884
[trace] 15:02:27:358 onResize() - nativeWindows.width: 866
[trace] 15:02:27:475 onResize() - nativeWindows.width: 844
[trace] 15:02:27:593 onResize() - nativeWindows.width: 820
[trace] 15:02:27:677 onResize() - nativeWindows.width: 805
[trace] 15:02:27:762 onResize() - nativeWindows.width: 799
[trace] 15:02:27:842 onResize() - nativeWindows.width: 788
[trace] 15:02:27:935 onResize() - nativeWindows.width: 778
... 

However, the trace output process process itself may pollute the measurement a little.

I suppose the RESIZE event intervals could vary between Flash Player and the AIR runtime, so just be sure you test before you choose a resizeInterval. I settled on 250ms in our AIR desktop app and it works pretty well.

But we wouldn't have to do this at all if AIR would just fire a MOUSE_UP event when the user releases the mouse after dragging the window. One could then add an event listener for MOUSE_UP in the first RESIZE event, and wait for the user to release the mouse capture, but the Adobe AIR runtime does not fire a stage MOUSE_UP event after a user resizes the window. I expect the same behavior in Flash Player.

Thanks, Package for your answer. It does work. I just wish there was a better way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.