5 Replies Latest reply on Jun 25, 2007 5:48 PM by DC_Hall

    TitleWindow Close

    DC_Hall
      I have searched up and down for this and probably just overlooking something simple. I have set showcloseButton="true" in the TitleWindow but for the life of me can't get it to actually function and close the app. Hover works and so do my styles for it but the actual function I am now bald over.

      Any help would be really appreciated. Thanks
        • 1. Re: TitleWindow Close
          rvollmar Level 1
          Hello,
          You have to set up a handler for the close event. First get the sample app. for TitleWindow in the language reference:

          http://livedocs.adobe.com/flex/201/langref

          Next, I've pasted a modification, below, to the SimpleTitleWindow.mxml file, which will turn on the Close button and use it:

          <?xml version="1.0" encoding="utf-8"?>
          <!-- Simple custom MXML TitleWindow component.
          The TitleWindowApp application displays this component.
          You cannot run it independently. -->

          <mx:TitleWindow xmlns:mx=" http://www.adobe.com/2006/mxml"
          title="Title Window" x="168" y="86" close="doClose()" showCloseButton="true">

          <mx:Script>
          <![CDATA[
          import mx.managers.PopUpManager;
          import mx.controls.Text;

          // A reference to the TextInput control in which to put the result.
          public var loginName:Text;

          // Event handler for the OK button.
          private function returnName():void {
          loginName.text="Name entered: " + userName.text;
          PopUpManager.removePopUp(this);
          }

          // Event handler for the Close and Cancel buttons.
          private function doClose():void{
          PopUpManager.removePopUp(this);
          }
          ]]>
          </mx:Script>

          <mx:HBox>
          <mx:Label text="Enter Name: "/>
          <mx:TextInput id="userName" width="100%"/>
          </mx:HBox>

          <mx:HBox>
          <mx:Button label="OK" click="returnName();"/>
          <mx:Button label="Cancel" click="doClose();"/>
          </mx:HBox>

          </mx:TitleWindow>
          - Rob
          • 2. Re: TitleWindow Close
            DC_Hall Level 1
            thanks rvollmar,

            I got the follow error after compiling and trying to close the app with the close button.

            TypeError: Error #1009: Cannot access a property or method of a null object reference.
            at mx.managers::PopUpManagerImpl/::findPopupInfoByOwner()
            at mx.managers::PopUpManagerImpl/removePopUp()
            at mx.managers::PopUpManager$/removePopUp()
            at TickerV1/::doClose()
            at TickerV1/__ticker_close()
            at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
            at flash.events::EventDispatcher/dispatchEvent()[C:\Documents and Settings\acrorel\Local Settings\Temp\aslibc-28157\EventDispatcher.as:209]
            at mx.core::UIComponent/dispatchEvent()
            at mx.containers::Panel/::closeButton_clickHandler()


            Here is how my code looks so you know. I am pretty sure I followed your example.

            <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" applicationComplete="appCompleteHandler()"
            layout="absolute" showFlexChrome="false" width="1280" height="1024" borderColor="#FFFFFF">
            <mx:Style source="/bin/style/style.css" />

            <mx:Script>
            <![CDATA[
            import flash.filesystem.*
            import mx.controls.Alert;
            import mx.events.*;
            import mx.managers.PopUpManager;
            import mx.containers.panel
            private var defaultFile:File;

            private function appCompleteHandler():void
            {
            defaultFile = File.documentsDirectory.resolve("test.txt");
            stage.window.width = 1280;
            stage.window.height = 1024;
            stage.window.x = 10;
            stage.window.y = 10;
            stage.window.visible = true;
            this.ticker.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            }


            private function onMouseDown(evt:MouseEvent):void
            {
            stage.window.startMove();
            }

            private function doClose():void{
            PopUpManager.removePopUp(this);
            }

            ]]>
            </mx:Script>

            <mx:TitleWindow id="ticker" close="doClose()" showCloseButton="true" mouseEnabled="true" width="1024" height="100" layout="absolute" title="Ticker" horizontalCenter="-97" verticalCenter="-205" fontFamily="Georgia" fontWeight="bold" fontSize="10" borderColor="#FFFFFF" themeColor="#C80000">


            </mx:TitleWindow>


            </mx:WindowedApplication>
            • 3. TitleWindow Close
              rvollmar Level 1
              I see the difference in how we were approaching this. In the TitleWindow example, notice that the main application, which I did not paste and probably should have, called TitleWindowApp, uses PopUpManager to create a PopUpWindow which uses sample TitleWindow. This child TitleWindow component is what I pasted above. Since the PopUpManager is used to create the PopUp, I am able to use PopUpManager.removePopUp() to remove it.

              The sample app. you provided does not use PopUpManager to launch a popup to show the TitleWindow. Instead, you have added the TitleWindow as an mxml component.

              Here is a sample app. which shows a couple of options you can use:

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

              <mx:Script>
              <![CDATA[

              import mx.managers.PopUpManager;

              private function doClose():void{

              // This will cause an RTE because the TitleWindow is not a popup.
              //PopUpManager.removePopUp(tw);

              // These are options you can use to make a component in the UI disappear,
              // depending on what you plan to do later.

              // 1) This will remove the item from the display list:
              removeChild(tw);

              // 2) This will just make it invisible:
              //tw.visible=false;
              }

              ]]>
              </mx:Script>

              <mx:TitleWindow id="tw" showCloseButton="true" close="doClose()" />

              </mx:Application>


              • 4. Re: TitleWindow Close
                DC_Hall Level 1
                thanks rvollmar.

                Those worked. Not really what was i was after as it leaves the program open in the task bar as it only makes it invisible but this may work for the demonstration I am doing. Ideally it would need to close the entire app down and stop the exe from running for the final product.

                • 5. Re: TitleWindow Close
                  DC_Hall Level 1
                  I got it.....just changed it to

                  //private function doClose():void{
                  //stage.window.close();
                  }

                  Thanks again for getting me on the right path.