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.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

4 Responses to Accessing a TitleWindow container’s internal close button in Flex

  1. kg says:

    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. KLadofoRA says:

    nice example
    i was play around with windows-1256 encoding and I was how wonderful it works

    thanks

  3. lynxoid says:

    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”

    • Peter deHaan says:

      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

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree