5 Replies Latest reply on Feb 1, 2007 7:51 AM by Roman Protsiuk

    IFocusManagerComponent and removePopUp

    Roman Protsiuk
      Hi, everyone.

      As I understand in order to properly handle focusOut event for my
      component it should implement IFocusManagerComponent. The component I
      develop is a pop-up window. Then strange and very unpleasant bug
      appear. After I set focus to one of my components child and after I
      click a button on it to close it browser crashes (firefox, ie).
      I don't know what to say more. Here's example. Simply clicking "close
      me" crashes browser. Totally confused.

      PopUpWindow.mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute"
      width="400"
      height="300"
      implements="mx.managers.IFocusManagerComponent"
      defaultButton="{mainButton}">

      <mx:Button id="mainButton"
      horizontalCenter="0"
      verticalCenter="0"
      label="close me"
      click="onMainButtonClick()" />

      <mx:Button label="fake" />

      <mx:Script>
      <![CDATA[
      import mx.core.UIComponent;
      import mx.managers.PopUpManager;

      public function showPopUp(parent : UIComponent) : void {
      PopUpManager.addPopUp(this, parent);
      PopUpManager.centerPopUp(this);
      setFocus();
      }

      public function hidePopUp() : void {
      PopUpManager.removePopUp(this);
      }

      public override function setFocus() : void {
      super.setFocus();
      mainButton.setFocus();
      }

      protected override function focusOutHandler(event : FocusEvent) : void {
      if (event.relatedObject == null || !contains(event.relatedObject)) {
      hidePopUp();
      }
      super.focusOutHandler(event);
      }

      private function onMainButtonClick() : void {
      hidePopUp();
      dispatchEvent(new Event(Event.CLOSE));
      }
      ]]>
      </mx:Script>

      </mx:TitleWindow>


      popUpSample.mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute"
      creationComplete="onCreationComplete()">

      <mx:Button id="clickButton"
      horizontalCenter="0"
      verticalCenter="0"
      label="click me"
      click="onButtonClick()" />

      <mx:Button label="fake" />

      <mx:Script>
      <![CDATA[
      public override function setFocus() : void {
      super.setFocus();
      clickButton.setFocus();
      }

      private function onCreationComplete() : void {
      _popUp = new PopUpWindow();
      _popUp.addEventListener(Event.CLOSE, onPopUpClose);
      }

      private function onButtonClick() : void {
      _popUp.showPopUp(this);
      }

      private function onPopUpClose(event : Event) : void {
      //clickButton.setFocus();
      }

      private var _popUp : PopUpWindow;
      ]]>
      </mx:Script>

      </mx:Application>

      The only thought i have: it's because focus is lost (it stays in
      pop-up) when pop-up is removed and the lost focus is unacceptable for
      flash player. So I added clickButton.setFocus() on close. But if i do
      it before removePopUp then PopUpWindws focusOutHandler removes it. Why
      do i need to call it manually anyway? :/ And if i do it after calling
      removePopUp then situation remains the same, browser crashes, not
      surprisingly.

      Any help highly appreciated.
      R.