View Single Post
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator 17 Creative Assets 2005-09-17 #23 Old  
Originally posted by fr3d
to further probe nutrox's knowledge: is there a simple way to call a function *after* the user has finished resizing the browser window? i.e. instead of calling it repeatedly while the window is being dragged...

thanks - this thread has been invaluable.
The only way I can think of doing that at the moment is like this...

ActionScript Code:
  1. stop();
  2.  
  3. Stage.scaleMode = "noscale";
  4. Stage.align = "tl";
  5. Stage.addListener({onResize:startReposition});
  6.  
  7. function startReposition() {
  8.     clearInterval(_root.repos_int);
  9.   _root.repos_int = setInterval(_root, "reposition", 250);
  10. };
  11.  
  12. function reposition() {
  13.         var mc = _root.mainContent_mc;
  14.         var newX = Math.floor((Stage.width - mc._width) / 2);
  15.         var newY = Math.floor((Stage.height - mc._height) / 2);
  16.         mc._x = newX;
  17.         mc._y = newY;
  18.     clearInterval(_root.repos_int);
  19. };
  20.  
  21. reposition();
What that does is start a "timeout" when the browser window is resized, and will reposition everything if the browser size doesn't change for 1/4 of a second (250ms). That should prevent anything being repositioned until the user has stopped resizing the browser.

Hope that helps.

On a side note: If the size of your main content ever changes then you can simply call _root.reposition(); to force everything to the center of the screen.
Reply With Quote