We love choice

Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://fxr.groups.adobe.com.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
«
»

ActionScript, Components, How to, MXML

How To Modify TitleWindow’s Close Button Position

Andrei Ionescu | 10.04.09 | 7 Comments

Google Buzz

Last week we received an email from someone having problems changing the position of the close button of a TitleWindow or Panel component. After a short brainstorming we found a solution and created a new component.

If you wonder how we did it the answer is simple: we extended the TitleWindow component and got into the mx_internal namespace of it.

Here is the code of the component with some comments:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" creationComplete="init()">
    <mx:Script>
        <![CDATA[
 
            // flag to see if the component is visually created
            private var _isCreated:Boolean = false;
 
            // initialization
            private function init():void
            {
                _isCreated = true;
            }
 
            // setter for setting the x position of close button
            public function set closeButtonX(pos:int):void
            {
                // checking if the component is visually created
                // setting the mx_internal close button x position
                if(_isCreated)
                    this.mx_internal::closeButton.x = pos;
            }
 
            public function set closeButtonY(pos:int):void
            {
                // checking if the component is visually created
                // setting the mx_internal close button y position
                if(_isCreated)
                    this.mx_internal::closeButton.y = pos;
            } 
 
        ]]>
    </mx:Script>
</mx:TitleWindow>

The main application that makes use of the new component is also simple:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" xmlns:flexer="com.flexer.*">
    <mx:Script>
        <![CDATA[
            // setting the x and y position of close button
            private function moveButton():void
            {
                if ( xPos.text != "" )
                    myWin.closeButtonX = int(xPos.text);
                if ( yPos.text != "" )
                    myWin.closeButtonY = int(yPos.text);	
            }
        ]]>
    </mx:Script>
 
    <flexer:TitleWindowCloseButton id="myWin" 
        title="Move the close button"
        width="400" height="300" 
        showCloseButton="true" 
        verticalCenter="0" horizontalCenter="0">
 
        <mx:VBox width="160" verticalCenter="0" horizontalCenter="0">
            <mx:HBox>
                <mx:Label text="button X pos:" width="100%" />
                <mx:TextInput id="xPos" width="50" /> 
            </mx:HBox>
            <mx:HBox>
                <mx:Label text="button Y pos:" width="100%" />
                <mx:TextInput id="yPos" width="50" /> 
            </mx:HBox>
            <mx:Button label="move it!" width="100%" click="moveButton()" /> 
        </mx:VBox>
 
    </flexer:TitleWindowCloseButton>
</mx:Application>

To see it in action play a bit with the coords in the following application.

This is the whole thing. The component can be improved to be able to set not only the coordinates of the close button but to set a padding and aligning it by using “top“, “bottom“, “left“, “right” or any combination of them. The mx_internal namespace lets us modify parts of components but is not advised to get too deep into it and modifying inside mx_internal without knowing what you’re doing. As the name of the namespace says, what is inside it is intenal! So… take care.

Share and Enjoy:
  • Twitter
  • Google Buzz
  • LinkedIn
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Sphinn
  • blogmarks
  • Reddit
  • StumbleUpon
  • Facebook
  • DZone
  • FriendFeed
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • Slashdot
  • MySpace
  • Add to favorites
TitleWindowCloseButton_sources
TitleWindowApp




Tags: , , ,

This post was written by Andrei Ionescu

Views: 16593

related

7 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

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

:

:


«
»