Accessing a TitleWindow container’s internal close button in Flex

The following example shows how you can access the close button in a Flex TitleWindow container by using the closeButton property in the mx_internal namespace.

Full code after the jump.

Since this example uses the mx_internal namespace, you can’t always depend on this behavior to work in future versions of the Flex SDK. Use at your own risk.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/24/accessing-a-titlewindow-containers-internal-close-button-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.events.CloseEvent;
            import mx.controls.Button;

            private function checkBox_change(evt:Event):void {
                var btn:Button = titleWindow.mx_internal::closeButton;
                btn.enabled = checkBox.selected;
            }

            private function titleWindow_close(evt:CloseEvent):void {
                arrColl.addItem({type:evt.type, time:getTimer()});
            }
        ]]>
    </mx:Script>

    <mx:ArrayCollection id="arrColl" />

    <mx:ApplicationControlBar dock="true">
        <mx:CheckBox id="checkBox"
                label="closeButton enabled:"
                selected="true"
                change="checkBox_change(event);" />
    </mx:ApplicationControlBar>

    <mx:TitleWindow id="titleWindow"
            showCloseButton="true"
            width="100%"
            close="titleWindow_close(event);">
        <mx:DataGrid id="dataGrid"
                dataProvider="{arrColl}"
                width="100%"
                rowCount="6">
            <mx:columns>
                <mx:DataGridColumn dataField="type" />
                <mx:DataGridColumn dataField="time" />
            </mx:columns>
        </mx:DataGrid>
    </mx:TitleWindow>

</mx:Application>

View source is enabled in the following example.

4 thoughts on “Accessing a TitleWindow container’s internal close button in Flex

  1. i’m a flex newbie -thank you so much for your generous sharing of knowledge through example – it’s incredibly helpful and informative. i’ve struggled mightily to apply your custom title window, popup and modal manager example code as a foundation for a video player but i can’t seem to do it. can you perhaps point me toward an example of the best method for setting up variables to load FLV files in a modal title window popup? i hope it isn’t asking too much, thanks in advance (either way) and best wishes,
    ;-)
    kg

  2. I don’t know if that was the point of this example, but there is a variable in TitleWindow class to hide/show the close button: “showCloseButton”

    1. lynxoid,

      True, but that only toggles the button’s visibility. What if you wanted to show a disabled close button? Or modify it in some other way?

      Not to imply the example is good or has an actual valid point.

      Peter

Comments are closed.