Creating an undraggable TitleWindow container in Flex
In a previous example, “Creating an undraggable Alert control in Flex”, we saw how you could create a Flex Alert control that isn’t draggable by listening for the mouseDown event and calling the stopImmediatePropagation() method in the event handler.
The following examples show how you can create an undraggable TitleWindow container by setting the isPopUp property to false on the TitleWindow instance.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/16/creating-an-undraggable-titlewindow-container-in-flex/ -->
<mx:Application name="PopUpManager_TitleWindow_isPopUp_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.containers.TitleWindow;
import mx.managers.PopUpManager;
private var titleWin:MyTitleWin;
private function launch():void {
titleWin = PopUpManager.createPopUp(this, MyTitleWin, true) as MyTitleWin;
PopUpManager.centerPopUp(titleWin);
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button id="btn"
label="Launch TitleWindow PopUp"
click="launch();" />
</mx:ApplicationControlBar>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/16/creating-an-undraggable-titlewindow-container-in-flex/ -->
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
showCloseButton="true"
title="TitleWindow"
width="300"
height="200"
close="titleWin_close(event);">
<mx:Script>
<![CDATA[
import mx.core.IFlexDisplayObject;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
private function titleWin_close(evt:CloseEvent):void {
PopUpManager.removePopUp(evt.target as IFlexDisplayObject);
}
private function checkBox_change(evt:Event):void {
this.isPopUp = checkBox.selected;
}
]]>
</mx:Script>
<mx:Label text="Drag this window"
horizontalCenter="0"
verticalCenter="0" />
<mx:ControlBar>
<mx:CheckBox id="checkBox"
label="isPopUp:"
labelPlacement="left"
selected="true"
change="checkBox_change(event);" />
</mx:ControlBar>
</mx:TitleWindow>
View source is enabled in the following example.
Due to popular demand, here is the “same” example in a more ActionScript friendly format:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/16/creating-an-undraggable-titlewindow-container-in-flex/ -->
<mx:Application name="PopUpManager_TitleWindow_isPopUp_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.containers.ControlBar;
import mx.controls.ButtonLabelPlacement;
import mx.controls.CheckBox;
import mx.containers.TitleWindow;
import mx.controls.Label;
import mx.core.ContainerLayout;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
private var checkBox:CheckBox;
private var titleWin:TitleWindow;
private function launch():void {
var lbl:Label = new Label();
lbl.text = "Drag this window";
lbl.setStyle("horizontalCenter", 0);
lbl.setStyle("verticalCenter", 0);
checkBox = new CheckBox();
checkBox.label = "isPopUp:";
checkBox.labelPlacement = ButtonLabelPlacement.LEFT;
checkBox.selected = true;
checkBox.addEventListener(Event.CHANGE, checkBox_change);
var controlBar:ControlBar = new ControlBar();
controlBar.addChild(checkBox);
titleWin = new TitleWindow();
titleWin.layout = ContainerLayout.ABSOLUTE;
titleWin.title = "TitleWindow";
titleWin.showCloseButton = true;
titleWin.width = 300;
titleWin.height = 200;
titleWin.addChild(lbl);
titleWin.addChild(controlBar);
titleWin.addEventListener(CloseEvent.CLOSE, titleWin_close);
PopUpManager.addPopUp(titleWin, this, true);
PopUpManager.centerPopUp(titleWin);
}
private function titleWin_close(evt:CloseEvent):void {
PopUpManager.removePopUp(titleWin);
}
private function checkBox_change(evt:Event):void {
titleWin.isPopUp = checkBox.selected;
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button id="btn"
label="Launch TitleWindow PopUp"
click="launch();" />
</mx:ApplicationControlBar>
</mx:Application>
The following example shows how you can create a custom TitleWindow based component (NonDraggableTitleWindow.mxml) which sets the isPopUp property to false in the TitleWindow instance’s initialize event handler:
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/16/creating-an-undraggable-titlewindow-container-in-flex/ -->
<mx:Application name="PopUpManager_TitleWindow_isPopUp_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
private var titleWin:NonDraggableTitleWindow;
private function launch():void {
titleWin = PopUpManager.createPopUp(this, NonDraggableTitleWindow, true) as NonDraggableTitleWindow;
PopUpManager.centerPopUp(titleWin);
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button id="btn"
label="Launch TitleWindow PopUp"
click="launch();" />
</mx:ApplicationControlBar>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/16/creating-an-undraggable-titlewindow-container-in-flex/ -->
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
showCloseButton="true"
title="TitleWindow"
width="300"
height="200"
initialize="titleWin_initialize(event);"
close="titleWin_close(event);">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.core.IFlexDisplayObject;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
private function titleWin_initialize(evt:FlexEvent):void {
evt.target.isPopUp = false;
}
private function titleWin_close(evt:CloseEvent):void {
PopUpManager.removePopUp(evt.target as IFlexDisplayObject);
}
]]>
</mx:Script>
<mx:Label text="Drag this window"
horizontalCenter="0"
verticalCenter="0" />
</mx:TitleWindow>
Finally, the following example shows how you can extend the TitleWindow class in ActionScript and set the isPopUp property to false in the TitleWindow instance’s initialize event handler.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/08/16/creating-an-undraggable-titlewindow-container-in-flex/ -->
<mx:Application name="PopUpManager_TitleWindow_isPopUp_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
private var titleWin:NonDraggableTitleWindow2;
private function launch():void {
titleWin = PopUpManager.createPopUp(this, NonDraggableTitleWindow2, true) as NonDraggableTitleWindow2;
PopUpManager.centerPopUp(titleWin);
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button id="btn"
label="Launch TitleWindow PopUp"
click="launch();" />
</mx:ApplicationControlBar>
</mx:Application>
/**
* http://blog.flexexamples.com/2008/08/16/creating-an-undraggable-titlewindow-container-in-flex/
*/
package {
import mx.containers.TitleWindow;
import mx.controls.Label;
import mx.core.ContainerLayout;
import mx.core.IFlexDisplayObject;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
public class NonDraggableTitleWindow2 extends TitleWindow {
public var lbl:Label;
public function NonDraggableTitleWindow2() {
super();
init();
}
private function init():void {
this.layout = ContainerLayout.ABSOLUTE;
this.title = "TitleWindow";
this.showCloseButton = true;
this.width = 300;
this.height = 200;
this.addEventListener(FlexEvent.INITIALIZE, titleWin_initialize);
this.addEventListener(CloseEvent.CLOSE, titleWin_close);
lbl = new Label();
lbl.text = "Drag this Window";
lbl.setStyle("horizontalCenter", 0);
lbl.setStyle("verticalCenter", 0);
addChild(lbl);
}
private function titleWin_initialize(evt:FlexEvent):void {
this.isPopUp = false;
}
private function titleWin_close(evt:CloseEvent):void {
PopUpManager.removePopUp(evt.target as IFlexDisplayObject);
}
}
}
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.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
8 Responses to Creating an undraggable TitleWindow container in Flex
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


wow!! so much head ache for such a simple thing!! what were they thinking when they developed the TitleWindow!!
Hey Peter,
Thanks for creating such a useful website for Flex examples. I have learned most of what I know through your examples and various tutorials. I am currently stuck trying to figure out how to create a popUpWindow that will load a SWF and then return information back to the main application. A summary of what I’m trying to accomplish is listed below.
1. A User clicks a “Search” button within the main application.
2. A PopUpWindow appears with the loaded SWF.
3. A User selects a username from a datagrid contained in the loaded SWF.
4. A text field within the main application is then populated with the selected username.
Do you have an example that touches on this sort of interaction. If not, could you give me some direction?
Thanks Peter!
Srr,
I want to create a popup(not based on tilewindow).
I don’t like the layout or styling of the titlewindow, and want to use a simple canvas/vbox etc. This works fine, and I can style the popup exactly how I want, but it is not draggable.
Are their properties to set? Do I need to write handlers for dragging?
Thanks in advance
Great lesson! Thank you! :)
Thanks for this example.
I know that it is a bit old, but I found it just seconds ago and it solve my problem.
Thanks again and keep up the good work :)
Muy buen blog, excelente tu trabajo! Soy estudiante y me han sido de gran utilidad tus ejemplos.
Muchas gracias!!!
Is there any example for the s:TitleWindow?
I’m having some strange issue with that one.
i having strange problem.
I have created new TitleWindow and placed just one simple button with label Submit. and when i run it i see button’s label is gettng truncated. And in browser it not always happens.
i tried
this.invalidateDisplayList();
this.validateNow();
on creattionComplete but .. no luck …
can any one please guide me..why it is happening..
SDK :- 3.2/ FLex3