<?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" viewSourceURL="srcview/index.html">

    <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>