Creating custom pop-up windows with the PopUpManager class (redux)
In a previous example, “Creating custom pop-up windows with the PopUpManager class”, we saw how you could use ActionScript to create pop up windows using the PopUpManager class in Flex.
In the following example we see how you can create a custom MXML component and pass the class name to the static PopUpManager.createPopUp() method to display the pop up.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/20/creating-custom-pop-up-windows-with-the-popupmanager-class-redux/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
private function launchMoreInfo():void {
var win:Dialog = PopUpManager.createPopUp(this, Dialog, true) as Dialog;
PopUpManager.centerPopUp(win);
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<mx:Button id="button"
label="Click for more information"
click="launchMoreInfo();" />
</mx:ApplicationControlBar>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<!-- Dialog.mxml -->
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
title="More information"
showCloseButton="true"
width="400"
height="300"
close="titleWindow_close(event);">
<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
private function titleWindow_close(evt:CloseEvent):void {
PopUpManager.removePopUp(this);
}
]]>
</mx:Script>
<mx:String id="info" source="info.txt" />
<mx:TextArea id="txt"
htmlText="{info}"
focusAlpha="0.0"
width="100%"
height="100%" />
</mx:TitleWindow>
info.txt
<font size="+2"><i>More Information...</i></font> <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec at arcu in lacus iaculis ultricies. Vivamus consectetuer. Donec vulputate aliquam leo. Nam metus. Aliquam nulla odio, ultrices vitae, nonummy eget, viverra accumsan, tellus. Curabitur neque ante, nonummy ut, fermentum eu, elementum a, ligula. Fusce hendrerit lectus ac velit. Suspendisse lorem pede, sagittis ac, fermentum non, auctor quis, nulla. Integer eu lacus sit amet justo vestibulum sodales. In euismod tellus eget magna. Vestibulum sed ante. Suspendisse eros libero, gravida ac, cursus et, porta vitae, lectus.</p>
View source is enabled in the following example.
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.
43 Responses to Creating custom pop-up windows with the PopUpManager class (redux)
-
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


Bah, I forgot to set the TextArea control’s
editableproperty tofalse, but you get the idea.Peter
Can you explain why spacing between paragraphs so big? (It is often the big problem)
s’ergo,
Try setting the
condenseWhiteproperty totrueon the TextArea control.Peter
Thank you!
All works fine.
You the great!
谢谢
…createPopUp(this, Dialog, true)…
how to make relation between dialog in .as and our dialog.mxml?
and thks ;)
yes u forgot to import it in as like :
import src.Dialog;northwebs.net,
You shouldnt need the import. the Dialog.mxml, info.txt, and main.mxml should all be in the same directory. Sorry, I think the filenames above the code are a bit confusing. You can check out the source code to see the exact folder structure.
Peter
u’re right Peter, thks a lot ;)
Hi,
If i want to put the Dialog.mxml file in an other folder (ie : src/myComponents/Dialog.mxml). How can I then reference it into the code “PopUpManager.createPopUp(this, Dialog, true) as Dialog”. I tried to put myComponents.Dialog but it doest’n work.
Any help please
Thanks
Gael,
How about this:
<mx:Script> <![CDATA[ import mx.managers.PopUpManager; import myComponents.Dialog; private function launchMoreInfo():void { var win:Dialog = PopUpManager.createPopUp(this, Dialog, true) as Dialog; PopUpManager.centerPopUp(win); } ]]> </mx:Script>Peter
Hi,
I’m trying to apply the style of the titleWindow you used in your “Creating a pop up TitleWindow using the PopUpButton control” example. However, when I use the PopUpManager class, the style isn’t applied, it uses the default one like the one in this example, is there anything I can do?
Thanx in advance
I want to do instead of info.txt in static I want dynamic that comes from database in text field.How????Anyone help me???
Could you make the popup re-sizable using the cursor?
Thanks
‘All works fine.’
Thats not true, the example didnt works.What about this?
var win:Dialog = PopUpManager.createPopUp(this, Dialog, true) as Dialog;
here is error: undefined property dialog
I had d same problem the solution is u av to av to import the managers.Popupmanager class into ur script block using the import statement.
Excellent tutorial as usual!
Just one question. If I change the width/height of the popup to percentwidth/percentheight, it doesn’t work. How do I set the size of the popup to, say, 80% of the parent?
Thank you,
You are doing a great job!
Eric,
This is a little crude, and you probably want to ask this question on the FlexCoders list, but you may be able to do what you want if you create a custom TitleWindow component and calculate the width/height yourself based on the Application’s width/height multiplied by the desired percent width/height. Something like the following:
<?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" showCloseButton="true" width="80%" percentHeight="80" creationComplete="titleWin_creationComplete(event);" close="titleWin_close(event);"> <mx:Script> <![CDATA[ import mx.events.ResizeEvent; import mx.events.FlexEvent; import mx.core.IFlexDisplayObject; import mx.events.CloseEvent; import mx.managers.PopUpManager; import mx.core.Application; private function titleWin_creationComplete(evt:FlexEvent):void { var titleWin:TitleWindow = evt.target as TitleWindow; var widthPct:uint = Application.application.width * titleWin.percentWidth / 100; var heightPct:uint = Application.application.height * titleWin.percentWidth / 100; titleWin.width = widthPct; titleWin.height = heightPct; PopUpManager.centerPopUp(titleWin); } private function titleWin_close(evt:CloseEvent):void { PopUpManager.removePopUp(evt.target as IFlexDisplayObject); } ]]> </mx:Script> <mx:Label text="Lorem Ipsum" /> </mx:TitleWindow>Peter
Hi,
Indeed you were right peterd, I followed your idea and rebuilt this function (in my popup class for Flex 4 :
public function resizePercentage(widthPercentage:Number, heightPercentage:Number):void {
var appWidth:Number = FlexGlobals.topLevelApplication.width;
var appHeight:Number = FlexGlobals.topLevelApplication.height;
this.width = Number(appWidth*(widthPercentage/100));
this.height = Number(appHeight*(heightPercentage/100));
this.maxWidth = this.width;
this.maxHeight = this.height;
}
I am sorry Peter, I didn’t mean to offend anyone. I am very new to flex and I am not familiar with flexcoder list. Thanks a lot for your help anyway. Great blog.
Eric,
No problem. Sorry, after re-reading my reply, I worded it very poorly. I meant my solution was a little crude and I’m sure somebody on the FlexCoders list would have a more elegant solution.
Peter
Peter,
Thanks for the solution, I have a question. New height and width is received on CreationComplete, now is it possible to set height and width of child components based on this new height and width. Could you please give an example for this.
Thank You
–
Chetan
I have a form designed using Flex. The form does not fit the screen area and hence I am having scroll bars in it. When we click on some of the controls in the form, we open popups. But when the popup is opened, if we scroll the form using the form scroll bar then the popup is not getting scrolled. I want the popup to be scrolled along with the form elements. Please let me know how this can be done.
Thanks
Abhilash
Hi Peter,
Ive been looking at your example and also the examples in the livedocs. Ive been doing flex for about 2 months now and previously i was developing in AS 2.0, C#, Java and VB. Im just trying to get my head around this class and it has been annoying. I have an application that uses a socket connection to raise events. When these events are raised, i am using a custom Alert component that is displayed using the PopUpManager class. Now it all works great, the problem is i am using the same PopUpManager class to display another custom Alert component. After adding one, it seems as though i cannot add the second one, even after removing it. Is there anything that i am missing to be getting the this error?? should i possible have 1 component with the two others nested within it? and the parent of these two be the panel that i use to display in PopupManager?
the error i am getting is as follows:
Hi Peter
Thank you for the good examples. I wonder if you have an answer for this. I want to popup a custom window like this example, and be able to dispatch an event back to the opener. Basically when the custom window closes I want run a function from the opener.
Are there any problems with this approach? Thanks!
Hi AC, this is the problem I also face just now. It can be easily solved with Cairgnorm framework but w/o it, you can do this way.
1. You create custom event in your custom popup window. Then dispatch event as usual.
2. In your opener, you have a reference to popup window, register it with custom event listener above. i.e.
(in your opener’s code)
var popup:CustomPopup = new CustomPopUP();
popup.addEventListener(yourEvent, functionHandler);
private var fucntion functionHandler(yourEvent):void{ }
Regards,
Anh
P.S. This is a great flex blog :D Thank you, Peter
Do you know how to make modal dialog only cover specific section of the swf application (say some panel) and not the full swf application ?
I’m also wondering the same as Shailendra (previous poster). Is there a way to make the modal window cover only a component, not the entire stage? I debugged and found where the modal window is created. I guess we could just inherit from the proper classes and resize/relocate the modal window.
Hello Sir
I am having a problem now !!I tried to use pop up window
private function launchMoreInfo():void { var win:Dialog = PopUpManager.createPopUp(this, ManageMedia, true) as ManageMedia; PopUpManager.centerPopUp(win); }I am not able to compile this code . Can any one Explain me the Exact Syntaz
Var win : XXXX –>should it be the name of the other class we are going to call or Dialog class ?
Can you please explain me the line
isaac,
Try this:
Peter
Hi Peter,
Your tutorial helped me a lot.
Can you please help me. I want to pass data from my parent window in the Dialog window. How can I do so?
I am new to flex.
Thanks in advance
Hi Peter,
Your tutorial more helped for me
But one thing, already some people asked this question..
“Can you please help me. I want to pass data from my parent window in the Dialog window. How can I do so?”…
Thanks,
Anderson.
Hello
Thank you for your site and support !
I would like to develop a dynamic popup window :
If i select (single click) an item in a advanceddatagrid, and click on a button elsewhere, a popup appear with information about the selected item.
I know how to create the popup but i don’t know how to send information to this popup
thanks !!
Thanks for the information, this help a lot!
Cheers!
Hey Peter,
Thanks for the great post! This has been really useful in helping me understand creating popups better.
I’ve read both: Creating custom pop-up windows with the PopUpManager class (redux) & Creating custom pop-up windows with the PopUpManager class & their corresponding comments.
I was wondering if you could help me understand the examples a little better (I’m only a few flex days old)
I really like this example where you separated Dialog.mxml from main.mxml.
As compared to the original post of , I find this example a neater and more organized way of handling codes. However, I find it a shame that this (redux) post was created for the purpose of just displaying information.
I’m wondering if you can advice me on how to modify Dialog.mxml into a form submission Popup. I’ve looked through your original post, and although the user is able to enter his/her name, that inputted value is not submitted by a form & does not go anyway.
I’m pretty familiar with the HTTPservice, but I’m not quite sure how to go about writing the structure of the application for me to turn Dialog.mxml into a form. Can you help me out here?
Thanks so much in advance,
Jord
@Jord,
The best way to display a Form in Flex is to probably use the <mx:Form/> and <mx:FormItem/> tags (should be lots of examples on this site as well). Then create a Submit type button which validates the form. If the data is valid then send the form values to the server using HTTPService and then close the dialog. If the data is not valid, then display an error dialog using the Alert component and don’t close the popup.
Peter
Thanks Peter,
I’ve actually figured it out!
I’ve replaced the codes in Dialog.mxml to:
Can you please look though for me if i applied these concepts wrongly?
Hi Peter,
I really got stuck with one problem. I am creating a desktop applicaiton using air. In that applicaiton left side contains a list and right side contains a HTML component. Double clicking on a list item will load the currosponding html id that in right side.
Click on List item opens a popup which will be on top of the HTML component. The problem is in Windows (I tried XP) this popup goes beind the HTML/SWF . I tried adding modal = true while adding popup which brought made popup visible on top of HTML component but the SWF in HTML became disappear..
I want to make this popup NOT as Modal so that background is enabled, but want to show on top of HTML component when swf is there.
How can solve this issue?
Instead of loading info.text (html tags) i want to add an mxml file(with mxml components inside). To load the text u used the TextArea
htmlText=”{info}” property but what kind of component can i use to insert mxml components that are in an external mxml file. Please help me.
Hi Peter,
I’ve got a problem:
when I try and create a popup in the way you describe I get this error
i want to know is there any way to open popupwindow except popupmanager.createpopup(this,child,false)
becouse i want to set child dynamically but in this case i am facing problem please help me ASAP
Hi,
s thr any way to create a pop up window in action scrtip file, without calling the mxml file in createpopup()