Home > Adobe Flex > Flex: Manually centering a popup based on browser width & height

Flex: Manually centering a popup based on browser width & height

Most Flex developers know that the default PopUpManager in Flex has a centerPopUp method that allows you to center the popup over the display object passed in through the method signature:

1
2
3
var _popup:MyPopup = new Popup();
PopUpManager.addPopUp( _popup, this );
PopUpManager.centerPopUp( this );

You may even switch out the “this” reference and replace with “parent” or “parent.parentApplication” to center the popup on the entire application.

This can be especially true if you’re opening a popup from a small component in your application and don’t necessary want the popup to get centered on that one single component.

Unfortunately, if the dimensions of your parent Application are larger than the dimensions of the viewable browser window, you will have to center the popup manually rather than use the built-in centerPopUp() function.

Here’s how I center popups manually in Flex:

First, in your HTML template, I create a JavaScript function to return the browser width and height. I found this handy function on the web somewhere and it seems to do the trick:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function getBrowserHeight()
{
	var winW = 630, winH = 460;
 
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	  winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	 }
	}
 
	return winH;
}

In this case, it’s only returning height (which I’m mostly interested in), however you can modify it to return both attributes if you’d like.

In Flex, I make a call to JavaScript using ExternalInterface during application startup and store that value somewhere (say on the Model) where I can access it later:

1
model.browserHeight = ExternalInterface.call( "getBrowserHeight" );

Now, whenever I open a popup, I use the browserHeight I’ve stored on the Model and manually compute a centered position on the screen:

1
2
3
4
5
6
7
8
9
10
/**
 * Opens this popup
 */
public static function open( parent:UIComponent, model:MyModel) : void
{
	var _popup:MyPopup= new MyPopup();				
	PopUpManager.addPopUp( _popup, parent.parentApplication as DisplayObject, true );
	_popup.y = ( model.browserHeight / 2 ) - ( _popup.height / 2 );
	_popup.x = ( ((parent.parentApplication.width) / 2) - (_popup.width / 2) ); 
}

In this example, I place a static function within the popup class itself, which nicely encapsulates that logic. I also pass in some UIComponent. This is used mostly to get access to the parentApplication object, which I can use to figure out the application’s total width.

As you can see, by dividing the application width and height, then subtracting the popup’s width and height, you can manually center the popup in the visible area of the browser regardless of the application’s full height (which could be thousands of pixels high in some scrollable instances).

Opening the popup from a view is as simple as calling the static function:

1
SubmitAdPopup.open( this, model );

I’ve run into this situation quite often in various Flex applications so I hope this may help others who finds themselves in the same boat.

Opinions? I’m curious in seeing how others solved this riddle. ;)

Categories: Adobe Flex Tags:
  1. May 31st, 2014 at 22:57 | #1

    What’s up, I read your blog like every week.

    Your story-telling style is witty, keep up
    the good work!

  2. December 15th, 2014 at 21:12 | #2

    Most major phone system manufacturers, attempt to sell theirr
    version of IP Tell hence the business will probably be
    looking at IP Tel irrespective of what. So one example is, should your business has 20 extensions,
    however, you only expect 6 simultaneous calls
    any time, you wiull only need 6 trunks. Though it can be expensive it
    adeded value on the money I have spent because of
    thgis excited device.

  3. December 23rd, 2014 at 23:05 | #3

    Whether movie industrial, chemical, food industry, water treatment or pharmaaceutical industry it is
    possible to count on their good quality products and services.
    At fg inox, you’re going to gett exclusive array of stainless steel pipe accessories especially suitable for you in reasonable prices.
    2 kg, allowing it to be compact and easy too use in various environments.

  4. December 26th, 2014 at 10:07 | #4

    Scent life (does it last four hours, or stay fresh all-around eight hours);.
    The nails, your hair, the footwear,she’s developed with these things
    and has now beewn paying focus on them since she was young.
    But aside froom these names, and many otfher recognizable brands, guys were stuck in no-man’s land concerning cologne.

  5. December 27th, 2014 at 08:35 | #5

    In 1984, following wave on the first production with the Air
    Maxx Tailwind 4 regarding Nike customers suddenly modified ther perception. The nails, your hair, these
    comfortable shoes, she’s matured with these things and it has ben paying awarreness of them
    since she was young. It has developed into huge
    success in the wintertime boots industgry as it is often launched.

  6. December 27th, 2014 at 09:35 | #6

    You will reall feel accustomed to the finest services in addition to
    their top class chef. Explore your neighborhood village with ‘Little Made,’
    as thhe host and guide. Manyy peoplle may even see journeys
    much like the one taken by Elizabeth Gilbert in Eat, Pray, Love as impossible of their lives.

  7. January 3rd, 2015 at 10:41 | #7

    First, the arrangement could be the order where the sections of
    music are positioned, for instance, intro-verse-chorus-verse-chorus so on. With
    genres between rock, pop, alternate, punk, electronica, hip-hop, place, folk,and blues, start searching for your
    favourite for no extra charge MP3 song by typing inside the name frrom the artist or band, song title,
    or perhaps the name with the album. As you receve the real dwelling on the Holy Spirit, you’ll realise until this
    is your fountain of perpetual life.

  8. January 7th, 2015 at 10:24 | #8

    Well here’s ann instant ist of a number of the things you receive with
    your nightly rate whenever you book this kind of accommodation:.
    The rooms are modern and comfy, with private bathrooms,
    24-hour domestic hot water, and electgricity plus accommodations are attractively
    appointed. An individual without knowledge or farming knowledge may not be expecting to obtain a farm and remain an immediate success.

  9. January 7th, 2015 at 10:59 | #9

    Pan-frying can also be considered a variety
    of dry heat approach tto cooking our meat. Master recipes to unlock culinary delights from through the globe.

    For pan-broiling, begin with placing the lamb in a heavy skillet.

  10. January 9th, 2015 at 11:10 | #10

    An easy way to tell whicdh side may be the front would
    be too look with the artist’s signature. As the king Of Yogyakarta, Java, Indonesia, batik iis becoming their daily outfits.

    Paired which has a T-shirt along with a denim jacket thdse skirts look great.

  11. February 2nd, 2015 at 02:08 | #11

    This may be called “The Feeder”mainly because itt feeds off everything
    around it, adapting in reply to its environment.
    It takes few hours so as to print the t-shirts so it
    might be quite tiring. Such that after servicemen returned following your war they brought with him or herr the concept, as well as the desire to put on them in civilian life.

  12. February 8th, 2015 at 20:47 | #12

    If that you are asking these questions, you might find this infrmation useful.
    Moreover, inside very first week only you will notice that
    that you arre having strong erections which enable it to stay in erected stage for a
    longer time time period. One major reason will be the natural formulation of ingredients which made with this product.

  13. February 8th, 2015 at 21:41 | #13

    Think of Hollywood’s ‘ice queen’ leading ladies to do this ‘look’.
    But virtually all sites let your childrten to learn online, with thanks to the flash technology.
    Even if you think youu are not considering
    fashion, you arre going to soon realize that
    you will discovver at least quite a ffew which you cannot
    but have preferences whenever it comes to dressing.

  14. February 8th, 2015 at 23:30 | #14

    Another benefit is the fact wooden clothes pegs are very cheap,using a
    packet of 36 pegs clsting around fifty pence.
    Following is really a list of Liberty Local Vendors for 2011
    with links with their websites (if available)
    to acquure more information about the artist and
    craft. These places provides you with an insight in to the local life and history
    on the island.

  15. February 11th, 2015 at 10:47 | #15

    Coloradoans have begun to recceive their blue book viter guides recently, using a large portion of the population getting
    theirs today. Selecting an online site that you will patronize is critical for you will be spendinhg a number of your money and period in it.

    Acquire the proper online sportsbook – A sportsbook caan be a sports gambling platform that allows punters
    to gamble.

  16. October 27th, 2019 at 09:29 | #16

    Other cash for typing jobs include text messaging for clients if
    identify to turn into tarot moto business. There is a green lifestyle .
    in the U.K. specifically that hires people to function from home
    chatting with clients yearn to notice the cards read for people today.
    You have to be professional though, and cause buy your own set of tarot cards in order to assist them.

    Some psychics however don’t use these psychic mediums. They can simply perceive
    or visualize the future with some help from
    the sixth sense they have been blessed with.

    The sixth sense is outright what we refer to as our “gut disposition.” It
    is more developed in the truth of mediums. Different psychics function in different procedures.
    Some psychics are able to dream or have an epiphany on a person consequently able to assist them.

    It’s not at all uncommon for psychics to visualize images
    or dreams along with the core of the day. Others use other
    means such as crystal balls and palmistry. For users who believe in reincarnation, psychic readings are an absolute must.

    To result from this life with a large amount of of having accomplished your jobs in this life is irreplaceable!
    Past life psychic readings furthermore an engaging peek in the person you are, and even even exactly what coming from then on. It’s
    no wonder people discover psychic readings comforting.

    A psychic reading can really alter the way you feel about life!
    Right now there isn’t any harm in trying psychic readings, wish you keep a good dose
    of disbelief that is very much.

    Creating magical ceremonies permit anyone offer that you a respite to acquire
    a few hrs .. Recharging yourself with love, gratitude, nicely course
    pleasure may be just thing you are looking for.
    Infuse your lifetime with some of sparkle, with elegant ceremony a
    person can and your lover can do with each similar.
    Set aside time to pamper some other and speak words of love and appreciation that will rekindle your desire and remind you both why
    you are still to each other.

  17. December 8th, 2019 at 09:22 | #17

    What’s Going down i am new to this, I stumbled upon this I’ve discovered It absolutely helpful and it
    has helped me out loads. I hope to contribute &
    help different customers like its aided me. Great job.

  18. March 2nd, 2021 at 11:31 | #18

    If tend to be playing low stakes B.O.R.S.E. poker, you will find that some players are fantastic at one format,
    but cannot handle other video clip games. Usually this will be seen for your Razz and Omaha hi-low rounds.
    Should you be good at these to games, you very well may easily
    win in these rounds of H.O.R.S.E. on line poker.

    A great poker quote by Doyle Brunson is “Texas Hold’em takes a few minutes to learn but an entire life to master” and Texas Dolly is perfect.

    Every time you play poker you should take away a lesson to increase game.

    Whether you were good day or an adverse day ought to be always be
    an instance that you remember in did something really well or produced a miscalculation. Playing poker takes practice each game should be considered so ,.
    Try to learn as much as you can from all the games you play around.

    The next thing is advertising your forums. You can do this by joining various running forums.
    Most forums or discussion boards provide you with a signature with a web site.
    Try to post interesting critical reviews. This will make people curios to visit your blogs.

    The worst thing you accomplish is to ask people to see your blogs via call.
    This is considered to be spam. All you have to do is to become involved in discussions.

    Share your opinions and ask questions.

    After the flop is dealt and the subsequent betting round is finished, players discard their extra hole card.
    Whenever of pineapple poker, throughout the simple and the crazy versions, the delicate process of the
    hand is played precisely like Texas Hold’em. This offshoot of Texas Hold em provides more action without changing the play.

    Players can develop a hand using several amount of hole cards, including it’s unlikely that
    any. The betting rules remain unchanged
    and anyone playing Texas Hold’em would have the measurements and strategy concerning Pineapple
    On-line poker.

    Participating within a poker game the old-fashioned way
    (around a table with other players) is not really precisely what different from joining an online
    poker game around the net. A poker player would not have such
    a tough transition specifically if he or she is definitely comfortable
    with technology and is able to easily handle himself or
    herself around computers. Ultimately, the game remains the same:
    the medium which it is played updates. But if you are still in process
    of learning the right way to play poker on the internet, there are a quantity of ways in which you are about everything.

    Just consider the professions like actors and footballers (soccer).
    At extremely first top, there are big rewards and subjected to testing mostly overpaid.
    But for the majority, it is a work!

    ‘High Roller: The Stu Ungar Story’ is heartbreaking biopic by the lifetime of the famous American poker player, Stu Ungar.
    This movie is created in 2003 and was produced by F.A Miller and directed by Per.W Vidmer.

    The entire movie takes the perspective of a flashback and follows the highs and lows of certainly one of pokers most prominent figures.

    The UIGEA was passed in September 2006 and signed right at that
    moment President George W. Bush. The law basically made it illegal for banks and
    a bank card to knowingly process transactions for Internet
    gaming needs.

    Become informed about poker hand variations – In poker, the player
    wins is the one with the best hand at the show-down. If two players
    have hands with n . y . value, for instance, two full houses, the person with the particular value card wins.

    Most companies offer some type of bonus or promotion to
    get your business and on-line poker rooms
    are no different. Regardless of how much you play, you’ve nothing
    to get. With most bonuses, exterior lights poker you play,
    today, the contemporary you win. Most online sites offer freerolls for beginners
    and by be an impressive way that build your bankroll.
    Now the final thing that you need to provide is the banking details; that could be either your bank account, online PayPal account
    or credit card details. Men and women are nervous about
    entering their banking details online, so when you are also really
    want them, perhaps you can set up an online pay account like PayPal, ClickandBuy, WebMoney, MoneyBookers and so forth ..
    Different poker rooms accept different online pay options.
    Which should first check the area online pay options that you have
    chosen is acceptable by the poker site or in no way.
    You can also use credit score card too. But remember that many credit card
    companies never allow to make use of your credit cards for online gambling, so
    don’t get upset as well as valid cost card is declined for the purpose.

    Let ‘Em Ride Poker plays out similarly to hold on to ‘Em Poker.
    The player is dealt five cards, two that are face-down. After seeing the
    first three cards, the player can better their bet.
    For the fourth and fifth cards are revealed, the player can also add to their ante.
    The cheapest paying hand is a number of tens, which offers the player a payout of 1:
    1.

    A statistics showing that out of ten hands playing, you’ll end up a bad beat can be quite possible on online online poker.
    This shows that online poker game players are more prone into bad
    betters. Compared to playing in an e-casino where one bad beat
    an hour is probably occur, having it online doubles or even triples the
    unwanted turn.

    Tiredness: You’ll constantly be exhausted in case you are playing
    right through the day. If you’re playing quite high limits, you don’t need to play throughout the day to earn an income.
    In fact, most of poker players are found it necessary to grind it all out all day to pay house rent and choose food.

    The flavor of home poker games can vary widely
    from loose and casual, to very aggressive. Be sure you choose a
    game match your personality and style and design. If you are a high-stakes player, you
    will not enjoy playing ‘dealer choice’ games for nickels and dimes.
    Likewise, if all you want a great social evening of playing cards, you avoid high stake games such as Pot Limit Omaha.
    Fitness center about poker is that there are a game for nearly everybody.

    There are yet websites that collect big bets, and then, you will discover a connection problem.
    You think that since niche markets . so fantastic trying
    gain access to the site at you shouldn’t time, a person are not being
    able help to make a stable connection. Can teach you happen possess have designed large bet or invested heavily.
    Ingestion that contributes to will stop trying to
    make a connection if we do time.

    ‘High Roller: The Stu Ungar Story’ is heartbreaking biopic by the lifetime of the famous American online poker player, Stu Ungar.
    This movie is made in 2003 and was produced by F.A
    Miller and directed by Per.W Vidmer. The entire movie takes
    the perspective of a flashback and follows the ups and downs of beans are known pokers most prominent personalities.

    There are a lot of answers to this question, any one of more help than others one would imagine.There is a place where you can play online poker with your friends, on a small climb!
    Why not host an event and invite your fellow uni mates round your own home?
    This is often a quick and easy way of experiencing a game and a lot of
    fun from my many personal experiences!

    These texas holdem sites work very hard to secure your players thought.
    They monitor the IP addresses which you have logged in from and compare for you to any new
    IP address that is logged directly into your account.
    This is a first-class way to forestall your account from getting hacked.

    Permanently they use is to assign a code that in order to offer be entered by your mouse and simply not your computer.
    This prevents an excellent deal of issues but especially stops the keylogger disease.
    This virus copies your keystrokes and sends them
    to be able to the hacker which the team to enter
    your trading account. Another affective method they use is security
    idea. These are questions that only you know and it will
    keep other out. Email list stops people from looking over
    your shoulder or logging into websites to your when a person away.

  1. No trackbacks yet.