1 Reply Latest reply on Sep 25, 2008 12:29 PM by Newsgroup_User

    Handling resize event ...

    AJC5327
      I have a class that extends Panel. I add some buttons (Min/Restore/Max/Close ... top right corner,etc) to the chrome using rawChildren.addChild. I'd like to restrict the window to never be allowed to get to a height less than the height of the buttons or a width less than the combined width of the buttons (this is a generalization, I've included logic to account for borders, etc). Nevertheless, I've tried countless approaches ... then I tried listening for a resize event ...

      //in constructor
      this.addEventListener("resize", myResizeHandler);

      //handler
      private function myResizeHandler(event:ResizeEvent):void{
      width = Math.max(someMinimumCalculatedWidth(), width);
      height = Math.max(someMinimumCalculatedHeight(), height);
      }

      As shown ... within the event handler, I set width/height properties of the panel. In the case where they are different than current width/height, it expected it would trigger yet another resize event .... and I expected to get into some kind of nutty event loop (as you can see ... I'm in that ** I'll try anything ...** mode). Surprisingly ... it worked properly. There doesn't seem to be a resize event triggered when I set the width/height to values different than they were before entering the handler? I've perused the Panel/UIComponent source and everything I see leads me to believe another resize event would be triggered.

      So ... as strange as it sounds, I'd like to understand why this works :-) I can't bring myself to just move on without knowing why another resize event isn't dispatched and why I don't end right back up in myResizeHandler ...
        • 1. Re: Handling resize event ...
          Level 7

          "AJC5327" <webforumsuser@macromedia.com> wrote in message
          news:gbgnn1$n58$1@forums.macromedia.com...
          >I have a class that extends Panel. I add some buttons
          >(Min/Restore/Max/Close
          > ... top right corner,etc) to the chrome using rawChildren.addChild. I'd
          > like to
          > restrict the window to never be allowed to get to a height less than the
          > height
          > of the buttons or a width less than the combined width of the buttons
          > (this is
          > a generalization, I've included logic to account for borders, etc).
          > Nevertheless, I've tried countless approaches ... then I tried listening
          > for a
          > resize event ...
          >
          > //in constructor
          > this.addEventListener("resize", myResizeHandler);
          >
          > //handler
          > private function myResizeHandler(event:ResizeEvent):void{
          > width = Math.max(someMinimumCalculatedWidth(), width);
          > height = Math.max(someMinimumCalculatedHeight(), height);
          > }
          >
          > As shown ... within the event handler, I set width/height properties of
          > the
          > panel. In the case where they are different than current width/height, it
          > expected it would trigger yet another resize event .... and I expected to
          > get
          > into some kind of nutty event loop (as you can see ... I'm in that ** I'll
          > try
          > anything ...** mode). Surprisingly ... it worked properly. There doesn't
          > seem
          > to be a resize event triggered when I set the width/height to values
          > different
          > than they were before entering the handler? I've perused the
          > Panel/UIComponent
          > source and everything I see leads me to believe another resize event would
          > be
          > triggered.
          >
          > So ... as strange as it sounds, I'd like to understand why this works :-)
          > I
          > can't bring myself to just move on without knowing why another resize
          > event
          > isn't dispatched and why I don't end right back up in myResizeHandler ...

          A lot of times I find I have to go several classes up the inheritence chain
          to find where something lives. A shortcut to this is to find the public
          class extends statement and click whatever it extends. Press F3.

          HTH;

          Amy